Search in sources :

Example 16 with XMLCollectionReferenceMapping

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

the class CompositeElementKeyWithGroupingProject 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
    XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping();
    addressMapping.useCollectionClass(ArrayList.class);
    addressMapping.setAttributeName("addresses");
    addressMapping.setXPath("grouping-element");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("address/id-city/text()", "city/text()");
    addressMapping.addSourceToTargetKeyFieldAssociation("address/id-zip/text()", "zip/text()");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)

Example 17 with XMLCollectionReferenceMapping

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

the class CompositeElementKeyWithGroupingSingleNodeProject 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
    XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping();
    addressMapping.useCollectionClass(ArrayList.class);
    addressMapping.setUsesSingleNode(true);
    addressMapping.setAttributeName("addresses");
    addressMapping.setXPath("grouping-element");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("address/id-city/text()", "city/text()");
    addressMapping.addSourceToTargetKeyFieldAssociation("address/id-zip/text()", "zip/text()");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)

Example 18 with XMLCollectionReferenceMapping

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

Example 19 with XMLCollectionReferenceMapping

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

the class CompositeElementKeyWithGroupingNSProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    // create namespace resolver
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(nsResolver);
    // 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("ns:name/text()");
    descriptor.addMapping(nameMapping);
    // create address mapping
    XMLCollectionReferenceMapping addressMapping = new XMLCollectionReferenceMapping();
    addressMapping.useCollectionClass(ArrayList.class);
    addressMapping.setAttributeName("addresses");
    addressMapping.setXPath("ns:grouping-element");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.addSourceToTargetKeyFieldAssociation("ns:address/ns:id-city/text()", "ns:city/text()");
    addressMapping.addSourceToTargetKeyFieldAssociation("ns:address/ns:id-zip/text()", "ns:zip/text()");
    descriptor.addMapping(addressMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 20 with XMLCollectionReferenceMapping

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

the class TestProject method getAddressDescriptor.

private XMLDescriptor getAddressDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);
    descriptor.addPrimaryKeyFieldName("@aid");
    descriptor.addPrimaryKeyFieldName("city/text()");
    descriptor.setAlias("Address");
    descriptor.setNamespaceResolver(nsr);
    if (setSchemaContext) {
        XMLSchemaReference sRef = new XMLSchemaURLReference();
        sRef.setSchemaContext("/address-type");
        sRef.setType(XMLSchemaReference.COMPLEX_TYPE);
        descriptor.setSchemaReference(sRef);
    }
    if (setDefaultRootElement) {
        descriptor.setDefaultRootElement("address");
    }
    // create id mapping
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@aid");
    idMapping.setAttributeClassification(Integer.class);
    descriptor.addMapping(idMapping);
    // create street mapping
    XMLDirectMapping streetMapping = new XMLDirectMapping();
    streetMapping.setAttributeName("street");
    streetMapping.setXPath("street/text()");
    descriptor.addMapping(streetMapping);
    // create city mapping
    XMLDirectMapping cityMapping = new XMLDirectMapping();
    cityMapping.setAttributeName("city");
    cityMapping.setXPath("city/text()");
    descriptor.addMapping(cityMapping);
    // create country mapping
    XMLDirectMapping countryMapping = new XMLDirectMapping();
    countryMapping.setAttributeName("country");
    countryMapping.setXPath("country/text()");
    descriptor.addMapping(countryMapping);
    // create postalCode mapping
    XMLDirectMapping postalMapping = new XMLDirectMapping();
    postalMapping.setAttributeName("postalCode");
    postalMapping.setXPath("@postal-code");
    descriptor.addMapping(postalMapping);
    // create thingy mapping
    XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
    anyMapping.setAttributeName("thingy");
    descriptor.addMapping(anyMapping);
    // create occupants mapping
    XMLCollectionReferenceMapping occupantsMapping = new XMLCollectionReferenceMapping();
    occupantsMapping.useCollectionClass(ArrayList.class);
    occupantsMapping.setAttributeName("occupants");
    occupantsMapping.setReferenceClass(Employee.class);
    occupantsMapping.addSourceToTargetKeyFieldAssociation("occupant/text()", "name/text()");
    descriptor.addMapping(occupantsMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Aggregations

XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)34 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)32 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)20 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)14 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)12 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)7 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)4 XMLField (org.eclipse.persistence.oxm.XMLField)3 ArrayList (java.util.ArrayList)2 XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)2 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)2 JAXBException (jakarta.xml.bind.JAXBException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)1 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)1