Search in sources :

Example 11 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class SingleElementKeyProject 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/text()", "@aid");
    descriptor.addMapping(addressMapping);
    descriptor.setShouldPreserveDocument(true);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)

Example 12 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping 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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 13 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class SelfElementProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.addPrimaryKeyFieldName("id1/text()");
    descriptor.addPrimaryKeyFieldName("ns:id2/text()");
    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/text()", "id1/text()");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/ns:fk2/text()", "ns:id2/text()");
    managerMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(managerMapping);
    XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
    employeesMapping.setAttributeName("teamMembers");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/fk1/text()", "id1/text()");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/ns:fk2/text()", "ns:id2/text()");
    employeesMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(employeesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 14 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class ElementProject 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/text()", "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/text()", "id/id1/text()");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/ns:fk2/text()", "id/ns:id2/text()");
    employeesMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(employeesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 15 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class DynamicTestProject method addEmployeeDescriptor.

private void addEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClassName("org.eclipse.persistence.testing.oxm.dynamic.XEmployee");
    XMLDirectMapping name = new XMLDirectMapping();
    name.setAttributeName("name");
    name.setXPath("name/text()");
    descriptor.addMapping(name);
    XMLCompositeObjectMapping addr = new XMLCompositeObjectMapping();
    addr.setAttributeName("address");
    addr.setXPath("address");
    addr.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XAddress");
    descriptor.addMapping(addr);
    XMLCompositeCollectionMapping phone = new XMLCompositeCollectionMapping();
    phone.setAttributeName("phoneNumbers");
    phone.setXPath("phone-numbers/number");
    phone.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XPhoneNumber");
    phone.useCollectionClass(ArrayList.class);
    phone.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
    descriptor.addMapping(phone);
    XMLCollectionReferenceMapping emails = new XMLCollectionReferenceMapping();
    emails.setAttributeName("emails");
    emails.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XEmail");
    emails.addSourceToTargetKeyFieldAssociation("email-id/text()", "@id");
    descriptor.addMapping(emails);
    XMLObjectReferenceMapping secCred = new XMLObjectReferenceMapping();
    secCred.setAttributeName("securityCredential");
    secCred.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XSecurityCredential");
    secCred.addSourceToTargetKeyFieldAssociation("sec-cred-id/text()", "@id");
    descriptor.addMapping(secCred);
    this.addDescriptor(descriptor);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ArrayList(java.util.ArrayList) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Aggregations

XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)35 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)32 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)20 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)14 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)12 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)8 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)6 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)2 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)2 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)2 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1