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