use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.
the class NoRefClassProject method getCustomerDescriptor.
private XMLDescriptor getCustomerDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Customer.class);
XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
addressMapping.setAttributeName("address");
addressMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", null);
xmlDescriptor.addMapping(addressMapping);
XMLCollectionReferenceMapping phoneNumbersMapping = new XMLCollectionReferenceMapping();
phoneNumbersMapping.setAttributeName("phoneNumbers");
phoneNumbersMapping.addSourceToTargetKeyFieldAssociation("phone-number-id/text()", null);
phoneNumbersMapping.getContainerPolicy().setContainerClass(ArrayList.class);
xmlDescriptor.addMapping(phoneNumbersMapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.
the class SingleElementProject method getCustomerDescriptor.
private XMLDescriptor getCustomerDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Customer.class);
XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
addressMapping.setAttributeName("address");
addressMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", null);
xmlDescriptor.addMapping(addressMapping);
XMLCollectionReferenceMapping phoneNumbersMapping = new XMLCollectionReferenceMapping();
phoneNumbersMapping.setAttributeName("phoneNumbers");
phoneNumbersMapping.addSourceToTargetKeyFieldAssociation("phone-number-id/text()", null);
phoneNumbersMapping.getContainerPolicy().setContainerClass(ArrayList.class);
phoneNumbersMapping.setUsesSingleNode(true);
xmlDescriptor.addMapping(phoneNumbersMapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.
the class TestProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setAlias("Employee");
descriptor.addPrimaryKeyFieldName("name/text()");
descriptor.setNamespaceResolver(nsr);
if (setSchemaContext) {
XMLSchemaReference sRef = new XMLSchemaURLReference();
sRef.setSchemaContext("/employee-type");
sRef.setType(XMLSchemaReference.COMPLEX_TYPE);
descriptor.setSchemaReference(sRef);
}
if (setDefaultRootElement) {
descriptor.setDefaultRootElement("employee");
}
// create name mapping
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("name/text()");
descriptor.addMapping(nameMapping);
// create address mapping
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setAttributeName("address");
addressMapping.setXPath("address");
addressMapping.setReferenceClass(Address.class);
descriptor.addMapping(addressMapping);
// create phoneNumbers mapping
XMLCompositeCollectionMapping phonesMapping = new XMLCompositeCollectionMapping();
phonesMapping.setAttributeName("phoneNumbers");
phonesMapping.useCollectionClass(ArrayList.class);
phonesMapping.setXPath("phone-numbers");
phonesMapping.setReferenceClass(PhoneNumber.class);
descriptor.addMapping(phonesMapping);
// create projectIDs mapping
XMLCompositeDirectCollectionMapping projectIdsMapping = new XMLCompositeDirectCollectionMapping();
projectIdsMapping.setAttributeName("projectIDs");
projectIdsMapping.useCollectionClass(ArrayList.class);
projectIdsMapping.setXPath("project-id");
TypeConversionConverter tcc = new TypeConversionConverter(projectIdsMapping);
tcc.setObjectClass(BigDecimal.class);
projectIdsMapping.setValueConverter(tcc);
descriptor.addMapping(projectIdsMapping);
// create stuff mapping
XMLAnyCollectionMapping acMapping = new XMLAnyCollectionMapping();
acMapping.setAttributeName("stuff");
descriptor.addMapping(acMapping);
// Enable Choice testing when Bug 269880 has been fixed
// create choice mapping - choice
XMLChoiceObjectMapping choiceMapping = new XMLChoiceObjectMapping();
choiceMapping.setAttributeName("choice");
choiceMapping.addChoiceElement("nickname/text()", String.class);
choiceMapping.addChoiceElement("secondAddress", Address.class);
choiceMapping.addChoiceElement("age/text()", Integer.class);
// descriptor.addMapping(choiceMapping);
// Enable ChoiceCollection testing when Bug 269880 has been fixed
// create choices mapping
XMLChoiceCollectionMapping choiceCMapping = new XMLChoiceCollectionMapping();
choiceCMapping.setAttributeName("choices");
choiceCMapping.addChoiceElement("badgeId/text()", Integer.class);
choiceCMapping.addChoiceElement("alternateAddress", Address.class);
choiceCMapping.addChoiceElement("codename/text()", String.class);
// descriptor.addMapping(choiceCMapping);
// create billingAddress mapping
XMLObjectReferenceMapping orMapping = new XMLObjectReferenceMapping();
orMapping.setAttributeName("billingAddress");
orMapping.setReferenceClass(Address.class);
orMapping.addSourceToTargetKeyFieldAssociation("@bill-address-id", "@aid");
orMapping.addSourceToTargetKeyFieldAssociation("bill-address-city/text()", "city/text()");
descriptor.addMapping(orMapping);
// create data mapping
XMLBinaryDataMapping dataMapping = new XMLBinaryDataMapping();
dataMapping.setAttributeName("data");
XMLField field = new XMLField("data");
field.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
dataMapping.setField(field);
dataMapping.setShouldInlineBinaryData(false);
dataMapping.setSwaRef(true);
dataMapping.setMimeType("application/binary");
descriptor.addMapping(dataMapping);
// create bytes mapping
XMLBinaryDataCollectionMapping bytesMapping = new XMLBinaryDataCollectionMapping();
bytesMapping.setAttributeName("bytes");
XMLField theField = new XMLField("bytes");
theField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
bytesMapping.setField(theField);
bytesMapping.setShouldInlineBinaryData(false);
bytesMapping.setSwaRef(false);
bytesMapping.setMimeType("text/plain");
descriptor.addMapping(bytesMapping);
// create URL mapping
XMLDirectMapping urlMapping = new XMLDirectMapping();
urlMapping.setAttributeName("aUrl");
urlMapping.setXPath("aUrl/text()");
descriptor.addMapping(urlMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.
the class AttributeProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.addPrimaryKeyFieldName("id/@id1");
descriptor.addPrimaryKeyFieldName("id/@ns:id2");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("ns", "urn:example");
descriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("id");
idMapping.setReferenceClass(EmployeeID.class);
descriptor.addMapping(idMapping);
XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
managerMapping.setAttributeName("manager");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "id/@id1");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/@ns:fk2", "id/@ns:id2");
managerMapping.setReferenceClass(Employee.class);
descriptor.addMapping(managerMapping);
XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
employeesMapping.setAttributeName("teamMembers");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "id/@id1");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@ns:fk2", "id/@ns:id2");
employeesMapping.setReferenceClass(Employee.class);
descriptor.addMapping(employeesMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.
the class SingleNodeProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.addPrimaryKeyFieldName("id/id1/text()");
descriptor.addPrimaryKeyFieldName("id/ns:id2/text()");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("ns", "urn:example");
descriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("id");
idMapping.setReferenceClass(EmployeeID.class);
descriptor.addMapping(idMapping);
XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
managerMapping.setAttributeName("manager");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "id/id1/text()");
managerMapping.addSourceToTargetKeyFieldAssociation("manager/ns:fk2/text()", "id/ns:id2/text()");
managerMapping.setReferenceClass(Employee.class);
descriptor.addMapping(managerMapping);
XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
employeesMapping.setAttributeName("teamMembers");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "id/id1/text()");
employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/ns:fk2/text()", "id/ns:id2/text()");
employeesMapping.setReferenceClass(Employee.class);
employeesMapping.setUsesSingleNode(true);
descriptor.addMapping(employeesMapping);
return descriptor;
}
Aggregations