Search in sources :

Example 31 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class OppositeProject method getChild2Descriptor.

private XMLDescriptor getChild2Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child2.class);
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child2");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:opposite");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    XMLObjectReferenceMapping child1Mapping = new XMLObjectReferenceMapping();
    child1Mapping.setReferenceClass(Child1.class);
    child1Mapping.setAttributeName("child1");
    child1Mapping.addSourceToTargetKeyFieldAssociation("tns:child1/text()", "@id");
    xmlDescriptor.addMapping(child1Mapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 32 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class CopyHelperProject method getChild1Descriptor.

private XMLDescriptor getChild1Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child1.class);
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:copy");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child1");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    XMLObjectReferenceMapping child2Mapping = new XMLObjectReferenceMapping();
    child2Mapping.setReferenceClass(Child2.class);
    child2Mapping.setAttributeName("child2");
    child2Mapping.addSourceToTargetKeyFieldAssociation("tns:child2/text()", "@id");
    xmlDescriptor.addMapping(child2Mapping);
    XMLCollectionReferenceMapping child2CollectionMapping = new XMLCollectionReferenceMapping();
    child2CollectionMapping.setReferenceClass(Child2.class);
    child2CollectionMapping.setAttributeName("child2Collection");
    child2CollectionMapping.addSourceToTargetKeyFieldAssociation("tns:child2collection/text()", "@id");
    xmlDescriptor.addMapping(child2CollectionMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 33 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class CopyHelperProject method getChild2Descriptor.

private XMLDescriptor getChild2Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child2.class);
    xmlDescriptor.setDefaultRootElement("tns:child2");
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child2");
    schemaReference.setType(XMLSchemaReference.ELEMENT);
    xmlDescriptor.setSchemaReference(schemaReference);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:copy");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    XMLObjectReferenceMapping child1Mapping = new XMLObjectReferenceMapping();
    child1Mapping.setReferenceClass(Child1.class);
    child1Mapping.setAttributeName("child1");
    child1Mapping.addSourceToTargetKeyFieldAssociation("tns:child1/text()", "@id");
    xmlDescriptor.addMapping(child1Mapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 34 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class JAXBValueStore method getJAXBMappingForProperty.

/**
 * Return the JAXB mapping for the SDO property.  They are matched
 * on their XML schema representation.
 */
Mapping getJAXBMappingForProperty(SDOProperty sdoProperty) {
    DatabaseMapping sdoMapping = sdoProperty.getXmlMapping();
    XMLField field;
    if (sdoMapping instanceof XMLObjectReferenceMapping) {
        XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping;
        field = (XMLField) referenceMapping.getFields().get(0);
    } else {
        field = (XMLField) sdoMapping.getField();
    }
    TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
    XPathNode xPathNode = treeObjectBuilder.getRootXPathNode();
    XPathFragment xPathFragment = field.getXPathFragment();
    while (xPathNode != null && xPathFragment != null) {
        if (xPathFragment.isAttribute()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) {
                xPathFragment = null;
                break;
            }
            Map<XPathFragment, XPathNode> attributeChildrenMap = xPathNode.getAttributeChildrenMap();
            if (null == attributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = attributeChildrenMap.get(xPathFragment);
            }
        } else if (xPathFragment.nameIsText()) {
            xPathNode = xPathNode.getTextNode();
        } else {
            Map<XPathFragment, XPathNode> nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
            if (null == nonAttributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = nonAttributeChildrenMap.get(xPathFragment);
            }
        }
        xPathFragment = xPathFragment.getNextFragment();
        if (xPathFragment != null && xPathFragment.nameIsText()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment()) {
                xPathFragment = null;
                break;
            }
        }
    }
    if (null == xPathFragment && xPathNode != null) {
        if (xPathNode.getNodeValue().isMappingNodeValue()) {
            MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue();
            return mappingNodeValue.getMapping();
        }
    }
    throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath());
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) TreeObjectBuilder(org.eclipse.persistence.internal.oxm.TreeObjectBuilder) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode)

Example 35 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class TestModelProject method addRootDescriptor.

public void addRootDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.Root");
    descriptor.setNamespaceResolver(nsResolver);
    XMLCompositeObjectMapping compObj = new XMLCompositeObjectMapping();
    compObj.setAttributeName("compObj");
    compObj.setXPath("comp-obj");
    compObj.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeObjectTarget");
    descriptor.addMapping(compObj);
    XMLCompositeCollectionMapping compColl = new XMLCompositeCollectionMapping();
    compColl.setAttributeName("compColl");
    compColl.setXPath("comp-coll/item");
    compColl.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeCollectionTarget");
    compColl.useCollectionClass(ArrayList.class);
    compColl.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
    descriptor.addMapping(compColl);
    XMLCompositeDirectCollectionMapping compDirColl = new XMLCompositeDirectCollectionMapping();
    compDirColl.setAttributeName("compDirColl");
    compDirColl.setXPath("comp-dir-coll");
    descriptor.addMapping(compDirColl);
    XMLBinaryDataMapping binData = new XMLBinaryDataMapping();
    binData.setAttributeName("binData");
    XMLField binDataField = new XMLField("bin-data");
    binDataField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binData.setField(binDataField);
    binData.setShouldInlineBinaryData(true);
    descriptor.addMapping(binData);
    XMLBinaryDataCollectionMapping binDataColl = new XMLBinaryDataCollectionMapping();
    binDataColl.setAttributeName("binDataColl");
    XMLField binDataCollField = new XMLField("bin-data-coll");
    binDataCollField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binDataColl.setField(binDataCollField);
    binDataColl.setShouldInlineBinaryData(true);
    descriptor.addMapping(binDataColl);
    XMLAnyObjectMapping anyObj = new XMLAnyObjectMapping();
    anyObj.setAttributeName("anyObj");
    anyObj.setField(new XMLField("any-obj"));
    descriptor.addMapping(anyObj);
    XMLCompositeObjectMapping anyAtt = new XMLCompositeObjectMapping();
    anyAtt.setAttributeName("anyAtt");
    anyAtt.setXPath("any-att");
    anyAtt.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.AnyAttributeTarget");
    descriptor.addMapping(anyAtt);
    XMLTransformationMapping transform = new XMLTransformationMapping();
    transform.setAttributeName("transform");
    transform.setAttributeTransformer(new AttributeTransformer());
    transform.addFieldTransformer("transform/first-val/text()", new FirstFieldTransformer());
    transform.addFieldTransformer("transform/second-val/text()", new SecondFieldTransformer());
    descriptor.addMapping(transform);
    XMLFragmentMapping frag = new XMLFragmentMapping();
    frag.setAttributeName("frag");
    frag.setXPath("frag");
    descriptor.addMapping(frag);
    XMLFragmentCollectionMapping fragColl = new XMLFragmentCollectionMapping();
    fragColl.setAttributeName("fragColl");
    fragColl.setXPath("frag-coll");
    fragColl.useCollectionClass(ArrayList.class);
    descriptor.addMapping(fragColl);
    XMLObjectReferenceMapping objRef = new XMLObjectReferenceMapping();
    objRef.setAttributeName("objRef");
    objRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.ObjectReferenceTarget");
    objRef.addSourceToTargetKeyFieldAssociation("obj-ref-id/text()", "@id");
    descriptor.addMapping(objRef);
    XMLCollectionReferenceMapping collRef = new XMLCollectionReferenceMapping();
    collRef.setAttributeName("collRef");
    collRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CollectionReferenceTarget");
    collRef.addSourceToTargetKeyFieldAssociation("coll-ref-id/text()", "@id");
    descriptor.addMapping(collRef);
    XMLChoiceObjectMapping choice = new XMLChoiceObjectMapping();
    choice.setAttributeName("choice");
    choice.addChoiceElement("choice-int/text()", Integer.class);
    choice.addChoiceElement("choice-float/text()", Float.class);
    descriptor.addMapping(choice);
    XMLChoiceCollectionMapping choiceColl = new XMLChoiceCollectionMapping();
    choiceColl.setAttributeName("choiceColl");
    choiceColl.addChoiceElement("choice-coll-double/text()", Double.class);
    choiceColl.addChoiceElement("choice-coll-string/text()", String.class);
    choiceColl.addChoiceElement("choice-coll-boolean/text()", Boolean.class);
    descriptor.addMapping(choiceColl);
    this.addDescriptor(descriptor);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) ArrayList(java.util.ArrayList) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) SecondFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.SecondFieldTransformer) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLFragmentCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentCollectionMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) FirstFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.FirstFieldTransformer) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AttributeTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.AttributeTransformer) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Aggregations

XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)35 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)32 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)20 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)14 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)12 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)8 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)6 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)2 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)2 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)2 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1