import org.eclipse.persistence.config.DescriptorCustomizer; import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping; public class PhoneNumberCustomizer implements DescriptorCustomizer { @Override public void customize(ClassDescriptor descriptor) throws Exception { descriptor.removeMappingForAttributeName("contact"); XMLObjectReferenceMapping contactMapping = new XMLObjectReferenceMapping(); contactMapping.setAttributeName("contact"); contactMapping.setReferenceClass(Employee.class); contactMapping.addSourceToTargetKeyFieldAssociation("contact/@eID", "eId/text()"); contactMapping.addSourceToTargetKeyFieldAssociation("contact/@country", "country/text()"); descriptor.addMapping(contactMapping); } }
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; }
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; }