Search in sources :

Example 26 with XMLObjectReferenceMapping

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

the class MultipleSourceProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    // create id mapping
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    // create name mapping
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    // create address mapping
    XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("@address-id", "@aid");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)

Example 27 with XMLObjectReferenceMapping

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

the class EmployeeProject method getDependentDescriptor.

public XMLDescriptor getDependentDescriptor() {
    if (null == dependentDescriptor) {
        dependentDescriptor = new XMLDescriptor();
        dependentDescriptor.setJavaClass(Dependent.class);
        dependentDescriptor.setSequencedObject(true);
        dependentDescriptor.setDefaultRootElement("BAR");
        XMLDirectMapping fnMapping = new XMLDirectMapping();
        fnMapping.setAttributeName("firstName");
        fnMapping.setXPath("first-name/text()");
        dependentDescriptor.addMapping(fnMapping);
        XMLDirectMapping lnMapping = new XMLDirectMapping();
        lnMapping.setAttributeName("lastName");
        lnMapping.setXPath("last-name/text()");
        dependentDescriptor.addMapping(lnMapping);
        XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
        addressMapping.setAttributeName("address");
        addressMapping.setReferenceClass(Address.class);
        addressMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", "@aid");
        dependentDescriptor.addMapping(addressMapping);
    }
    return dependentDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)

Example 28 with XMLObjectReferenceMapping

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

the class NestedAttributeKeyProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    // create id mapping
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    // create name mapping
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    // create address mapping
    XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("address-ref/@address-id", "@aid");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)

Example 29 with XMLObjectReferenceMapping

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

the class MappingsGenerator method generateXMLObjectReferenceMapping.

/**
 * Create an XMLObjectReferenceMapping and add it to the descriptor.
 */
public ObjectReferenceMapping generateXMLObjectReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass referenceClass) {
    ObjectReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, UnmarshalRecord, XMLField, XMLRecord> mapping = new XMLObjectReferenceMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    mapping.setReferenceClassName(referenceClass.getQualifiedName());
    // here we need to setup source/target key field associations
    if (property.isSetXmlJoinNodes()) {
        for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
            validateJoinNode(descriptor.getJavaClassName(), property, xmlJoinNode.getReferencedXmlPath(), referenceClass);
            mapping.addSourceToTargetKeyFieldAssociation(xmlJoinNode.getXmlPath(), xmlJoinNode.getReferencedXmlPath());
        }
    } else {
        String tgtXPath = null;
        TypeInfo referenceType = typeInfo.get(referenceClass.getQualifiedName());
        if (null != referenceType && referenceType.isIDSet()) {
            Property prop = referenceType.getIDProperty();
            tgtXPath = getXPathForField(prop, namespaceInfo, !prop.isAttribute(), false).getXPath();
        }
        // if the XPath is set (via xml-path) use it, otherwise figure it out
        Field srcXPath;
        if (property.getXmlPath() != null) {
            srcXPath = new XMLField(property.getXmlPath());
        } else {
            srcXPath = getXPathForField(property, namespaceInfo, true, false);
        }
        mapping.addSourceToTargetKeyFieldAssociation(srcXPath.getXPath(), tgtXPath);
    }
    if (property.getInverseReferencePropertyName() != null) {
        mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
        JavaClass backPointerPropertyType = null;
        if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
            mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
            mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
            JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[] {});
            if (getMethod != null) {
                backPointerPropertyType = getMethod.getReturnType();
            }
        } else {
            JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
            if (backpointerField != null) {
                backPointerPropertyType = backpointerField.getResolvedType();
            }
        }
        if (helper.isCollectionType(backPointerPropertyType)) {
            mapping.getInverseReferenceMapping().setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
        }
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 30 with XMLObjectReferenceMapping

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

the class OppositeProject method getChild1Descriptor.

private XMLDescriptor getChild1Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child1.class);
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:opposite");
    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)

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