Search in sources :

Example 1 with XMLAnyObjectMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project aai-aai-common by onap.

the class FromOxmVertexSchema method fromOxm.

public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException {
    name = vertexType;
    properties = new HashMap<String, PropertySchema>();
    annotations = new HashMap<String, String>();
    String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
    DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
    if (modelObjectType == null) {
        // Try to lookup by xml root element by exact match
        modelObjectType = xmlElementLookup.get(vertexType);
    }
    if (modelObjectType == null) {
        // Try to lookup by xml root element by lowercase
        modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
    }
    if (modelObjectType == null) {
        // Direct lookup as java-type name
        modelObjectType = jaxbContext.getDynamicType(vertexType);
    }
    if (modelObjectType == null) {
        // Vertex isn't found in the OXM
        throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM");
    }
    // Check annotations
    Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties();
    for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
        if (entry.getValue() instanceof String) {
            annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue());
        }
    }
    // Regular props
    for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
        if (mapping instanceof XMLAnyObjectMapping)
            continue;
        if (mapping instanceof XMLAnyCollectionMapping)
            continue;
        FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
        propSchema.fromOxm(mapping, modelObjectType, false);
        properties.put(propSchema.getName().toLowerCase(), propSchema);
    }
    // Reserved Props
    final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
    for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
        if (mapping.isAbstractDirectMapping()) {
            FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
            propSchema.fromOxm(mapping, reservedType, true);
            properties.put(propSchema.getName().toLowerCase(), propSchema);
        }
    }
}
Also used : PropertySchema(org.onap.aai.schemaif.definitions.PropertySchema) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) DynamicType(org.eclipse.persistence.dynamic.DynamicType) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) SchemaProviderException(org.onap.aai.schemaif.SchemaProviderException) Map(java.util.Map) HashMap(java.util.HashMap) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 2 with XMLAnyObjectMapping

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

the class CustomerProject method getCustomerDescriptor.

private XMLDescriptor getCustomerDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Customer.class);
    xmlDescriptor.setDefaultRootElement("customer");
    XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
    addressMapping.setReferenceClass(Address.class);
    addressMapping.setAttributeName("address");
    addressMapping.setXPath("customer-address");
    xmlDescriptor.addMapping(addressMapping);
    XMLCompositeCollectionMapping addressesMapping = new XMLCompositeCollectionMapping();
    addressesMapping.setReferenceClass(Address.class);
    addressesMapping.setAttributeName("addresses");
    addressesMapping.setXPath("customer-addresses/customer-address");
    xmlDescriptor.addMapping(addressesMapping);
    XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
    anyMapping.setAttributeName("any");
    anyMapping.setXPath("any-object");
    xmlDescriptor.addMapping(anyMapping);
    XMLAnyCollectionMapping anyCollectionMapping = new XMLAnyCollectionMapping();
    anyCollectionMapping.setAttributeName("anyCollection");
    anyCollectionMapping.setXPath("any-collection");
    xmlDescriptor.addMapping(anyCollectionMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 3 with XMLAnyObjectMapping

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

the class EmployeeProject method getEmployeeDescriptor.

public XMLDescriptor getEmployeeDescriptor() {
    if (null == employeeDescriptor) {
        employeeDescriptor = new XMLDescriptor();
        employeeDescriptor.setJavaClass(Employee.class);
        employeeDescriptor.setDefaultRootElement("ns:employee");
        employeeDescriptor.setSequencedObject(true);
        NamespaceResolver nsResolver = new NamespaceResolver();
        nsResolver.put("ns", "urn:example");
        employeeDescriptor.setNamespaceResolver(nsResolver);
        XMLDirectMapping idMapping = new XMLDirectMapping();
        idMapping.setAttributeName("id");
        idMapping.setXPath("@id");
        employeeDescriptor.addMapping(idMapping);
        XMLDirectMapping fnMapping = new XMLDirectMapping();
        fnMapping.setAttributeName("firstName");
        fnMapping.setXPath("personal-info/ns:first-name/text()");
        employeeDescriptor.addMapping(fnMapping);
        XMLDirectMapping lnMapping = new XMLDirectMapping();
        lnMapping.setAttributeName("lastName");
        lnMapping.setXPath("personal-info/last-name/text()");
        employeeDescriptor.addMapping(lnMapping);
        XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
        addressMapping.setAttributeName("address");
        addressMapping.setXPath("address");
        addressMapping.setReferenceClass(Address.class);
        employeeDescriptor.addMapping(addressMapping);
        XMLCompositeObjectMapping dependentMapping = new XMLCompositeObjectMapping();
        dependentMapping.setAttributeName("dependent");
        dependentMapping.setXPath("dependent");
        dependentMapping.setReferenceClass(Dependent.class);
        employeeDescriptor.addMapping(dependentMapping);
        XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
        anyMapping.setAttributeName("any");
        anyMapping.setUseXMLRoot(true);
        employeeDescriptor.addMapping(anyMapping);
        XMLFragmentMapping nodeMapping = new XMLFragmentMapping();
        nodeMapping.setAttributeName("node");
        nodeMapping.setXPath("fragment");
        employeeDescriptor.addMapping(nodeMapping);
    /*
            XMLChoiceMapping choiceMapping = new XMLChoiceMapping();
            choiceMapping.setAttributeName("choice");
            choiceMapping.addChoiceElement("choice-address", Address.class);
            choiceMapping.addChoiceElement("choice-dependent", Dependent.class);
            choiceMapping.addChoiceElement("choice-string/text()", String.class);
            employeeDescriptor.addMapping(choiceMapping);
             */
    }
    return employeeDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 4 with XMLAnyObjectMapping

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

the class TransformationMappingTestProject method getRootWithAnyObjectDescriptor.

public XMLDescriptor getRootWithAnyObjectDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(RootWithAnyObject.class);
    descriptor.setDefaultRootElement("root-with-any-object");
    XMLAnyObjectMapping objectMapping = new XMLAnyObjectMapping();
    objectMapping.setAttributeName("object");
    descriptor.addMapping(objectMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 5 with XMLAnyObjectMapping

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

the class AnyObjectAndAnyCollectionUC13NoDefaultRootComplexChildrenTestCases method buildRootDescriptor.

protected // 
ClassDescriptor buildRootDescriptor(// 
boolean firstMappingIsAnyCollection, // 
boolean firstMappingXPathSet, // 
boolean secondMappingIsAnyCollection, boolean secondMappingXPathSet) {
    // 
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Customer.class);
    descriptor.setDefaultRootElement("customer");
    DatabaseMapping anyMapping1 = null;
    // First Mapping
    if (!firstMappingIsAnyCollection) {
        anyMapping1 = new XMLAnyObjectMapping();
        anyMapping1.setAttributeName("anyObject");
        // ((XMLAnyObjectMapping) anyMapping1).setSetMethodName("setAnyObject");
        if (firstMappingXPathSet) {
            // set first mapping XPath
            ((XMLAnyObjectMapping) anyMapping1).setXPath(MAPPING_XPATH_OBJ);
        }
        descriptor.addMapping(anyMapping1);
    } else {
        anyMapping1 = new XMLAnyCollectionMapping();
        anyMapping1.setAttributeName("contactMethods");
        // ((XMLAnyCollectionMapping) anyMapping1).setSetMethodName("setAnyCollection");
        if (firstMappingXPathSet) {
            // set first mapping XPath
            ((XMLAnyCollectionMapping) anyMapping1).setXPath(MAPPING_XPATH);
        }
        descriptor.addMapping(anyMapping1);
    }
    // Second Mapping
    DatabaseMapping anyMapping2 = null;
    if (!secondMappingIsAnyCollection) {
        anyMapping2 = new XMLAnyObjectMapping();
        anyMapping2.setAttributeName("anyObject");
        // ((XMLAnyObjectMapping) anyMapping2).setSetMethodName("setAnyObject");
        if (secondMappingXPathSet) {
            // set second mapping XPath
            ((XMLAnyObjectMapping) anyMapping2).setXPath(MAPPING_XPATH_OBJ);
        }
        descriptor.addMapping(anyMapping2);
    } else {
        anyMapping2 = new XMLAnyCollectionMapping();
        anyMapping2.setAttributeName("contactMethods");
        // ((XMLAnyCollectionMapping) anyMapping2).setSetMethodName("setAnyCollection");
        if (secondMappingXPathSet) {
            // set second mapping XPath
            ((XMLAnyCollectionMapping) anyMapping2).setXPath(MAPPING_XPATH);
        }
        descriptor.addMapping(anyMapping2);
    }
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Aggregations

XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)28 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)25 XMLAnyCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)18 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)17 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)4 XMLField (org.eclipse.persistence.oxm.XMLField)3 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)2 InputStream (java.io.InputStream)1 Set (java.util.Set)1 QName (javax.xml.namespace.QName)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DynamicType (org.eclipse.persistence.dynamic.DynamicType)1 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)1