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:mil.navy.med.dzreg.dao.RegistriesManagerDAO.java
/** * * @param pt//from www .j a v a2 s. co m * @return */ private PersonRegistryProfileType map(DzPatients pt) throws Exception { PersonRegistryProfileType profile = new PersonRegistryProfileType(); profile.setDataSource(pt.getDataSource()); //-------------------------------------------------------------------------- // map person info //-------------------------------------------------------------------------- PersonType person = new PersonType(); if (pt != null) { person.setDataSource(pt.getDataSource()); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(pt.getPatientDob()); person.setDateOfBirth(DatatypeFactory.newInstance().newXMLGregorianCalendar(gc)); person.setId(pt.getPatid()); person.setEligibilityIdentifier(pt.getPatientDeersIdentifier()); person.setFmpssn(pt.getFmpssn()); person.setName(pt.getName()); person.setOfficePhone(pt.getOfficePhone()); person.setHomePhone(pt.getPhone()); AddressType address = new AddressType(); address.setStreetAddress(pt.getAddress()); address.setStreetAddress2(pt.getStreet2()); address.setCity(pt.getCity()); address.setPostalCode(pt.getZip()); address.setState(pt.getState()); JAXBElement<AddressType> jAddr = new JAXBElement<AddressType>( new QName("urn:mil:navy:med:dzreg:service", "AddressType"), AddressType.class, null, address); person.setAddress(jAddr); profile.setPerson(person); } //-------------------------------------------------------------------------- // map registry info //-------------------------------------------------------------------------- Collection<DzReg> dzregColl = pt.getDzRegCollection(); if (!dzregColl.isEmpty()) { for (DzReg d : dzregColl) { RegistryProfileType registry = map(d); if (registry != null) { registry.setRegisteredDate(d.getRegisteredDt()); } profile.getRegistry().add(registry); } } return profile; }
From source file:org.betaconceptframework.astroboa.model.jaxb.adapter.ContentObjectAdapter.java
@Override public ContentObjectType marshal(ContentObject contentObject) throws Exception { String contentObjectTypeName = retrieveContentObjectType(contentObject); ContentObjectTypeDefinition contentObjectTypeDefinition = contentObject.getTypeDefinition(); if (contentObjectTypeDefinition == null) { throw new CmsException("Unable to locate definition for content object " + contentObject.getId() + " with type " + contentObjectTypeName); }//from www. ja v a2 s . c o m JAXBElement<ContentObjectType> contentObjectTypeJaxb = new JAXBElement<ContentObjectType>( contentObjectTypeDefinition.getQualifiedName(), ContentObjectType.class, null, new ContentObjectType()); ContentObjectType contentObjectType = contentObjectTypeJaxb.getValue(); if (marshallerVisitor == null) { marshallerVisitor = new ContentObjectMarshalVisitor(); } marshallerVisitor.initialize(contentObject, contentObjectType, marshaller, serializeBinaryContent, exportAllProperties); //Marshal object properties defined by its content type contentObjectTypeDefinition.accept(marshallerVisitor); //Marshal object's aspects if (CollectionUtils.isNotEmpty(contentObject.getComplexCmsRootProperty().getAspects())) { marshallerVisitor.enableAspectDefinitionVisit(); Collection<ComplexCmsPropertyDefinition> aspectDefinitions = contentObject.getComplexCmsRootProperty() .getAspectDefinitions().values(); for (ComplexCmsPropertyDefinition aspectDefinition : aspectDefinitions) { aspectDefinition.accept(marshallerVisitor); } } // Check if one or more aspects have been removed. // If this is the case then a null value for them must be marshalled List<String> pathsOfPropertiesMarkedForRemoval = ((ComplexCmsPropertyImpl) contentObject .getComplexCmsRootProperty()).getPathsOfPropertiesMarkedForRemoval(); if (pathsOfPropertiesMarkedForRemoval != null && !pathsOfPropertiesMarkedForRemoval.isEmpty()) { LazyLoader lazyLoader = AstroboaClientContextHolder.getLazyLoaderForActiveClient(); for (String pathOfPropertyMarkedForRemoval : pathsOfPropertiesMarkedForRemoval) { //We are interested only for aspects, therefore we are looking only for simple property paths if (pathOfPropertyMarkedForRemoval.contains(".")) { continue; } //If this property is not defined in the object's type definition, then it is an aspect if (!contentObjectTypeDefinition.hasCmsPropertyDefinition(pathOfPropertyMarkedForRemoval)) { ComplexCmsPropertyDefinition aspectDefinition = null; if (lazyLoader != null) { aspectDefinition = (ComplexCmsPropertyDefinition) lazyLoader.getDefinitionService() .getCmsDefinition(pathOfPropertyMarkedForRemoval, ResourceRepresentationType.DEFINITION_INSTANCE, false); } if (aspectDefinition == null) { logger.warn("Definition for aspect " + pathOfPropertyMarkedForRemoval + " was not found. Unable to marshal NULL value for this property which has been marked for removal."); continue; } marshallerVisitor.enableAspectDefinitionVisit(); aspectDefinition.accept(marshallerVisitor); } } } appendSchemaLocationToMarshaller(); return contentObjectTypeJaxb.getValue(); }
From source file:org.betaconceptframework.astroboa.model.jaxb.CmsEntitySerialization.java
private String marshalEntity(CmsRepositoryEntity cmsRepositoryEntity, ResourceRepresentationType<?> resourceRepresentationType, boolean exportBinaryContent, boolean prettyPrint, String... propertyPathsToBeMarshalled) { if (cmsRepositoryEntity != null) { if (cmsRepositoryEntity instanceof ContentObject || cmsRepositoryEntity instanceof Topic || cmsRepositoryEntity instanceof Space || cmsRepositoryEntity instanceof RepositoryUser || cmsRepositoryEntity instanceof Taxonomy) { StringWriter writer = new StringWriter(); Marshaller marshaller = null; try { marshaller = createMarshaller(resourceRepresentationType, prettyPrint); if (cmsRepositoryEntity instanceof ContentObject) { if (!ArrayUtils.isEmpty(propertyPathsToBeMarshalled)) { marshaller.setProperty(AstroboaMarshaller.CMS_PROPERTIES_TO_BE_MARSHALLED, Arrays.asList(propertyPathsToBeMarshalled)); }//from w w w . ja v a 2s . co m //ContentObject needs special marshaling as JAXB does not have //enough information in order to initialize appropriate adapter for //ContentObject ContentObjectAdapter adapter = new ContentObjectAdapter(); adapter.setMarshaller(marshaller, exportBinaryContent, ArrayUtils.isEmpty(propertyPathsToBeMarshalled)); marshaller.setAdapter(adapter); ContentObjectType contentObjectType = marshaller.getAdapter(ContentObjectAdapter.class) .marshal((ContentObject) cmsRepositoryEntity); JAXBElement<ContentObjectType> contentObjectTypeJaxb = new JAXBElement<ContentObjectType>( ((ContentObject) cmsRepositoryEntity).getTypeDefinition().getQualifiedName(), ContentObjectType.class, null, contentObjectType); marshaller.marshal(contentObjectTypeJaxb, writer); } else { //Provide schema location marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, " " + BetaConceptNamespaceConstants.ASTROBOA_MODEL_DEFINITION_URI + " " + SchemaUtils.buildSchemaLocationForAstroboaModelSchemaAccordingToActiveClient()); marshaller.marshal(cmsRepositoryEntity, writer); } } catch (Exception e) { throw new CmsException(e); } finally { marshaller = null; } return writer.toString(); } else { throw new CmsException("Creating XML for entity type " + cmsRepositoryEntity.getClass().getName() + " is not supported"); } } throw new CmsException("No entity is provided. Unable to create xml"); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java
private JAXBElement<AbstractGeometryType> createPolygon() { PolygonType localPolygon = new PolygonType(); LinearRingType ring = new LinearRingType(); for (Coordinate coordinate : polygon.getCoordinates()) { CoordType coord = new CoordType(); coord.setX(BigDecimal.valueOf(coordinate.x)); coord.setY(BigDecimal.valueOf(coordinate.y)); if (!Double.isNaN(coordinate.z)) { coord.setZ(BigDecimal.valueOf(coordinate.z)); }// w ww .ja v a2 s.co m ring.getCoord().add(coord); } AbstractRingPropertyType abstractRing = new AbstractRingPropertyType(); abstractRing.setRing(gmlObjectFactory.createLinearRing(ring)); localPolygon.setExterior(gmlObjectFactory.createExterior(abstractRing)); JAXBElement<AbstractGeometryType> agt = new JAXBElement<AbstractGeometryType>( new QName("http://www.opengis.net/gml", "Polygon"), AbstractGeometryType.class, null, localPolygon); return agt; }
From source file:org.plasma.xml.schema.SchemaModelAssembler.java
private JAXBElement<Facet> createNumberFacet(String name, int value) { NumFacet facet = new NumFacet(); facet.setValue(String.valueOf(value)); QName qname = new QName(SchemaConstants.XMLSCHEMA_NAMESPACE_URI, name); return new JAXBElement<Facet>(qname, Facet.class, null, facet); }
From source file:org.plasma.xml.schema.SchemaModelAssembler.java
private JAXBElement<Facet> createNumberFacet(String name, String value) { NumFacet facet = new NumFacet(); facet.setValue(String.valueOf(value)); QName qname = new QName(SchemaConstants.XMLSCHEMA_NAMESPACE_URI, name); return new JAXBElement<Facet>(qname, Facet.class, null, facet); }