Search in sources :

Example 1 with XMLDirectMapping

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"));
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) HashMap(java.util.HashMap) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) LinkAdapterString(org.eclipse.persistence.testing.jaxb.dynamic.util.LinkAdapterString)

Example 2 with XMLDirectMapping

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);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 3 with XMLDirectMapping

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);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)

Example 4 with XMLDirectMapping

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);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 5 with XMLDirectMapping

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()");
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Aggregations

XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)802 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)630 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)103 XMLField (org.eclipse.persistence.oxm.XMLField)100 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)78 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)74 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)53 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)41 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)35 QName (javax.xml.namespace.QName)33 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)28 XMLSchemaURLReference (org.eclipse.persistence.oxm.schema.XMLSchemaURLReference)26 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)25 ArrayList (java.util.ArrayList)24 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)22 URL (java.net.URL)21 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)21 List (java.util.List)15 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)14 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)14