Search in sources :

Example 1 with XMLObjectReferenceMapping

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

the class SDOProperty method buildXMLObjectReferenceMapping.

private DatabaseMapping buildXMLObjectReferenceMapping(String mappingUri) {
    XMLObjectReferenceMapping mapping = new XMLObjectReferenceMapping();
    mapping.setAttributeName(getName());
    if (getType().isDataObjectType()) {
        getType().setImplClassName(SDOConstants.SDO_DATA_OBJECT_IMPL_CLASS_NAME);
    }
    mapping.setReferenceClassName(getType().getImplClassName());
    mapping.setReferenceClass(getType().getImplClass());
    String sourcexpath = getQualifiedXPath(getContainingType().getURI(), true);
    // Get reference ID property if it exists
    SDOProperty targetIDProp = getIDProp(getType());
    if (targetIDProp != null) {
        String targetxpath = targetIDProp.getQualifiedXPath(getType().getURI(), true);
        mapping.addSourceToTargetKeyFieldAssociation(sourcexpath, targetxpath);
    } else {
        throw SDOException.noTargetIdSpecified(getType().getURI(), getType().getName());
    }
    return mapping;
}
Also used : XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)

Example 2 with XMLObjectReferenceMapping

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(DatabaseMapping mapping, Object value) {
    XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor();
    NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
    Setting rootSetting = new Setting();
    XMLField xmlField = (XMLField) mapping.getField();
    if (xmlField == null) {
        if (mapping instanceof XMLObjectReferenceMapping) {
            xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0);
        } else if (mapping instanceof XMLCollectionReferenceMapping) {
            xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0);
        }
    }
    Setting setting = rootSetting;
    if (xmlField != null) {
        XPathFragment xPathFragment = xmlField.getXPathFragment();
        rootSetting = convertToSetting(xPathFragment, nsResolver);
        setting = rootSetting;
        while (xPathFragment.getNextFragment() != null) {
            xPathFragment = xPathFragment.getNextFragment();
            Setting childSetting = convertToSetting(xPathFragment, nsResolver);
            setting.addChild(childSetting);
            setting = childSetting;
        }
    }
    setting.setObject(dataObject);
    setting.setMapping(mapping);
    setting.setValue(value, false);
    return rootSetting;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) Setting(org.eclipse.persistence.oxm.sequenced.Setting) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 3 with XMLObjectReferenceMapping

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

the class ChangeSummaryProject 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:changesummary");
    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);
    XMLObjectReferenceMapping child1AttributeMapping = new XMLObjectReferenceMapping();
    child1AttributeMapping.setReferenceClass(Child1.class);
    child1AttributeMapping.setAttributeName("child1Attribute");
    child1AttributeMapping.addSourceToTargetKeyFieldAssociation("@child1", "@id");
    xmlDescriptor.addMapping(child1AttributeMapping);
    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 4 with XMLObjectReferenceMapping

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

the class MappingsProject 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:mappings");
    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);
    XMLObjectReferenceMapping child1AttributeMapping = new XMLObjectReferenceMapping();
    child1AttributeMapping.setReferenceClass(Child1.class);
    child1AttributeMapping.setAttributeName("child1Attribute");
    child1AttributeMapping.addSourceToTargetKeyFieldAssociation("@child1", "@id");
    xmlDescriptor.addMapping(child1AttributeMapping);
    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 5 with XMLObjectReferenceMapping

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

the class SingleAttributeKeyProject 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)

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