Search in sources :

Example 1 with XMLCollectionReferenceMapping

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"));
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor)

Example 2 with XMLCollectionReferenceMapping

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

Example 3 with XMLCollectionReferenceMapping

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) Setting(org.eclipse.persistence.oxm.sequenced.Setting) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 4 with XMLCollectionReferenceMapping

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

Example 5 with XMLCollectionReferenceMapping

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;
}
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)

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