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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations