use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class DynamicJAXBFromOXMTestCases method testXmlProperties.
public void testXmlProperties() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream iStream = classLoader.getResourceAsStream(XMLPROPERTIES);
if (iStream == null) {
fail("Couldn't load metadata file [" + XMLPROPERTIES + "]");
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream);
jaxbContext = DynamicJAXBContextFactory.createContextFromOXM(classLoader, properties);
DynamicEntity person = jaxbContext.newDynamicEntity(PACKAGE + "." + PERSON);
assertNotNull("Could not create Dynamic Entity.", person);
// Ensure that properties were set on the Descriptor and Mapping
XMLDescriptor d = jaxbContext.getXMLContext().getDescriptor(new QName("mynamespace", "person"));
assertEquals("Descriptor property not present.", 101, d.getProperty("identifier"));
assertEquals("Descriptor property not present.", Boolean.FALSE, d.getProperty("active"));
XMLDirectMapping m = (XMLDirectMapping) d.getMappingForAttributeName("name");
assertEquals("Mapping property not present.", "ENGLISH", m.getProperty("language"));
assertEquals("Mapping property not present.", "first and last name", m.getProperty("comment"));
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class TestModelProject method addCollectionReferenceTargetDescriptor.
public void addCollectionReferenceTargetDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.CollectionReferenceTarget");
descriptor.addPrimaryKeyFieldName("@id");
descriptor.setNamespaceResolver(nsResolver);
XMLDirectMapping id = new XMLDirectMapping();
id.setAttributeName("id");
id.setXPath("@id");
descriptor.addMapping(id);
XMLDirectMapping value = new XMLDirectMapping();
value.setAttributeName("value");
value.setXPath("value/text()");
descriptor.addMapping(value);
this.addDescriptor(descriptor);
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class TestModelProject method addCompositeCollectionTargetDescriptor.
public void addCompositeCollectionTargetDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeCollectionTarget");
descriptor.setNamespaceResolver(nsResolver);
XMLDirectMapping value = new XMLDirectMapping();
value.setAttributeName("value");
value.setXPath("value/text()");
descriptor.addMapping(value);
XMLInverseReferenceMapping invRef = new XMLInverseReferenceMapping();
invRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.Root");
invRef.setMappedBy("compColl");
invRef.setAttributeName("invRef");
descriptor.addMapping(invRef);
this.addDescriptor(descriptor);
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class TestModelProject method addAnyCollectionTargetDescriptor.
public void addAnyCollectionTargetDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.AnyCollectionTarget");
descriptor.setDefaultRootElement("any-coll-value");
descriptor.setNamespaceResolver(nsResolver);
XMLDirectMapping value = new XMLDirectMapping();
value.setAttributeName("value");
value.setXPath("text()");
descriptor.addMapping(value);
this.addDescriptor(descriptor);
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class PersonCustomizer method customize.
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
XMLDirectMapping nameMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("name");
XMLField nameField = (XMLField) nameMapping.getField();
nameField.setXPath("contact-info/personal-info/name/text()");
}
Aggregations