use of org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class XmlJoinNodeTestCases method testContainerType.
public void testContainerType() {
JAXBContext jCtx = null;
try {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(OXM_DOC_V2);
HashMap<String, Source> metadataSourceMap = new HashMap<>();
metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmljoinnode", new StreamSource(inputStream));
Map<String, Object> invalidProperties = new HashMap<>();
invalidProperties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
jCtx = (JAXBContext) JAXBContextFactory.createContext(new Class<?>[] { Company.class }, invalidProperties);
} catch (JAXBException e) {
e.printStackTrace();
fail("An exception occurred while creating the JAXBContext.");
}
XMLDescriptor xDesc = jCtx.getXMLContext().getDescriptor(new QName("company"));
assertNotNull("No descriptor was generated for Company.", xDesc);
DatabaseMapping mapping = xDesc.getMappingForAttributeName("employees");
assertNotNull("No mapping exists on Customer for attribute [employees].", mapping);
assertTrue("Expected an XMLCollectionReferenceMapping for attribute [employees], but was [" + mapping.toString() + "].", mapping instanceof XMLCollectionReferenceMapping);
assertTrue("Expected container class [java.util.LinkedList] but was [" + mapping.getContainerPolicy().getContainerClassName() + "]", mapping.getContainerPolicy().getContainerClassName().equals("java.util.LinkedList"));
}
use of org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class SDOProperty method buildXMLCollectionReferenceMapping.
private DatabaseMapping buildXMLCollectionReferenceMapping(String mappingUri) {
XMLCollectionReferenceMapping mapping = new XMLCollectionReferenceMapping();
mapping.setAttributeName(getName());
if (getType().isDataObjectType()) {
getType().setImplClassName(SDOConstants.SDO_DATA_OBJECT_IMPL_CLASS_NAME);
}
mapping.setReferenceClassName(getType().getImplClassName());
mapping.setReferenceClass(getType().getImplClass());
mapping.setUsesSingleNode(true);
mapping.useCollectionClass(ArrayList.class);
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.XMLCollectionReferenceMapping 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.XMLCollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class CollectionReferenceReuseProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setDefaultRootElement("employee");
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("name/text()");
descriptor.addMapping(nameMapping);
XMLCollectionReferenceMapping addressesMapping = new XMLCollectionReferenceMapping();
addressesMapping.setAttributeName("addresses");
addressesMapping.setReferenceClass(Address.class);
addressesMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", "@id");
addressesMapping.setReuseContainer(true);
descriptor.addMapping(addressesMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class SelfAttributeProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.addPrimaryKeyFieldName("@id1");
descriptor.addPrimaryKeyFieldName("@ns:id2");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("ns", "urn:example");
descriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath(".");
idMapping.setReferenceClass(EmployeeID.class);
descriptor.addMapping(idMapping);
XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
managerMapping.setAttributeName("manager");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "@id1");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/@ns:fk2", "@ns:id2");
managerMapping.setReferenceClass(Employee.class);
descriptor.addMapping(managerMapping);
XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
employeesMapping.setAttributeName("teamMembers");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "@id1");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@ns:fk2", "@ns:id2");
employeesMapping.setReferenceClass(Employee.class);
descriptor.addMapping(employeesMapping);
return descriptor;
}
Aggregations