List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, Class scope, T value)
Construct an xml element instance.
From source file:Main.java
public static <ValueType, BoundType> JAXBElement<BoundType> marshallJAXBElement( Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, Class<BoundType> declaredType, QName name, Class scope, ValueType v) { try {//from ww w .j a v a2 s .c o m if (v == null) { return null; } else { final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass); return new JAXBElement<BoundType>(name, declaredType, scope, xmlAdapter.marshal(v)); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static <BoundType> JAXBElement<BoundType> marshallJAXBElement(Class<BoundType> declaredType, QName name, Class scope, BoundType v) { if (v == null) { return null; } else {//from w w w. ja va 2 s. c o m return new JAXBElement<BoundType>(name, declaredType, scope, v); } }
From source file:io.mapzone.arena.csw.InsertRecordRequest.java
@Override protected void prepare(IProgressMonitor monitor) throws Exception { writeElement(CSW, "Insert", () -> { QName name = new QName(Namespaces.CSW, "Record"); writeObject(new JAXBElement(name, RecordXML.class, null, record)); });//from ww w .j a v a 2s.c o m }
From source file:io.mapzone.arena.csw.UpdateRecordRequest.java
@Override protected void prepare(IProgressMonitor monitor) throws Exception { writeElement(CSW, "Update", () -> { // record QName name = new QName(Namespaces.CSW, "Record"); writeObject(new JAXBElement(name, RecordXML.class, null, record)); // constraint writeElement(CSW, "Constraint", () -> { writeAttributes(constraintLangVersion); out().writeNamespace("ogc", OGC); writeElement(OGC, "Filter", () -> { writeElement(OGC, "PropertyIsEqualTo", () -> { writeElement(OGC, "PropertyName", () -> { out().writeCharacters("Identifier"); });// w w w . j ava 2s . c o m writeElement(OGC, "Literal", () -> { out().writeCharacters(identifier); }); }); }); }); }); }
From source file:eu.europa.ec.markt.tlmanager.model.TSPInformationExtensionAdapter.java
private List<ExtensionType> getExtensions() { List<ExtensionType> extensions = new ArrayList<ExtensionType>(); for (TSPInformationExtensionModel value : values.values()) { if (StringUtils.isNotBlank(value.getExtension())) { ExtensionType extensionType = new ExtensionType(); extensionType.setCritical(value.isCritical()); ObjectIdentifierType oid = new ObjectIdentifierType(); IdentifierType identifier = new IdentifierType(); identifier.setValue(value.getExtension()); oid.setIdentifier(identifier); JAXBElement<ObjectIdentifierType> element = new JAXBElement<ObjectIdentifierType>( QNames._ObjectIdentifier_QNAME, ObjectIdentifierType.class, null, oid); extensionType.getContent().add(element); extensions.add(extensionType); }//from ww w .j av a 2 s .c om } return extensions; }
From source file:gov.nih.nci.integration.caaers.invoker.CaAERSUpdateRegistrationServiceInvocationStrategy.java
private String marshalParticipantType(ParticipantType participantType) throws IntegrationException { final StringWriter sw = new StringWriter(); try {/*from w ww.j a v a 2 s .c o m*/ final JAXBElement<ParticipantType> jaxbEle = new JAXBElement<ParticipantType>(qname, ParticipantType.class, null, participantType); final PrintWriter pw = new PrintWriter(sw); getMarshaller().marshal(jaxbEle, pw); } catch (JAXBException e) { final IntegrationException ie = new IntegrationException(IntegrationError._1053, e, "Unable to serialize retrieved Participant"); throw ie; } return sw.toString(); }
From source file:com.prowidesoftware.swift.model.mx.BusinessHeader.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private JAXBElement _element(final Object header) { if (header instanceof BusinessApplicationHeaderV01) { return (JAXBElement<BusinessApplicationHeaderV01>) new JAXBElement(new QName(NAMESPACE_BAH, "AppHdr"), header.getClass(), null, header); } else if (header instanceof ApplicationHeader) { return (JAXBElement<ApplicationHeader>) new JAXBElement(new QName(NAMESPACE_AH, "AppHdr"), header.getClass(), null, header); } else {//from w w w . j av a 2 s .co m return null; } }
From source file:org.socialhistoryservices.pid.database.dao.HandleDaoImpl.java
/** * add locations without namespace as Handle System describes it. * The namespace will have to be removed to make sure future implementations of the Handle System * process the XML correctly://from www . j av a 2 s . co m * <locations><location></location></locations> * * @param handle The persistent identifier * @param locations The 10320/loc value */ private void setLocations(Handle handle, LocAttType locations) { final JAXBElement element = new JAXBElement(qname, PidType.class, LocAttType.class, locations); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamResult result = new StreamResult(baos); marshaller.marshal(element, result); ByteArrayOutputStream os = new ByteArrayOutputStream(); Result result2 = new StreamResult(os); final StreamSource xmlSource = new StreamSource(new ByteArrayInputStream(baos.toByteArray())); try { templates.newTransformer().transform(xmlSource, result2); } catch (TransformerException e) { e.printStackTrace(); } handle.setData(os.toByteArray()); }
From source file:at.gv.egovernment.moa.id.protocols.stork2.MandateRetrievalRequest.java
private PersonalAttribute marshallComplexAttribute(PersonalAttribute currentAttribute, Object obj) { // TODO refactor StringWriter stringWriter = new StringWriter(); try {// w w w . ja va 2s . co m if (obj instanceof MandateContentType) { final Marshaller marshaller = JAXBContext.newInstance(MandateContentType.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(new JAXBElement<MandateContentType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateContentType.class, null, (MandateContentType) obj), stringWriter); } else if (obj instanceof MandateType) { final Marshaller marshaller = JAXBContext.newInstance(MandateType.class).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(new JAXBElement<MandateType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateType.class, null, (MandateType) obj), stringWriter); } else if (obj instanceof RepresentationPersonType) { final Marshaller marshaller = JAXBContext.newInstance(RepresentationPersonType.class) .createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal( new JAXBElement<RepresentationPersonType>( new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), RepresentationPersonType.class, null, (RepresentationPersonType) obj), stringWriter); } } catch (Exception ex) { Logger.error("Could not marshall atrribute: " + currentAttribute.getName() + ", " + ex.getMessage()); return new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), new ArrayList<String>(), AttributeStatusType.NOT_AVAILABLE.value()); } ArrayList<String> value = new ArrayList<String>(); value.add(stringWriter.toString()); PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, AttributeStatusType.AVAILABLE.value()); return personalAttribute; }
From source file:org.soitoolkit.commons.studio.components.logger.impl.DefaultLogEventCreator.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private String getJaxbContentAsString(Object jaxbObject, String outputEncoding) { String content;/*from w ww .ja v a2s . c om*/ if (jaxbContext == null) { content = "Missing jaxbContext injection, can't marshal JAXB object of type: " + jaxbObject.getClass().getName(); } else { if (!jaxbObject.getClass().isAnnotationPresent(XmlRootElement.class)) { // We are missing element end namespace info, let's create a // wrapper xml-root-element QName wrapperQName = new QName("class:" + jaxbObject.getClass().getName(), getJaxbWrapperElementName(jaxbObject)); jaxbObject = new JAXBElement(wrapperQName, jaxbObject.getClass(), null, jaxbObject); } try { content = marshalJaxbObject(jaxbObject); } catch (Throwable e) { e.printStackTrace(); content = "JAXB object marshalling failed: " + e.getMessage(); } } return content; }