Search in sources :

Example 1 with XMLAnyCollectionMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping 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 XMLAnyCollectionMapping

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

the class XmlAnyElementListTestCases method testContainerType.

public void testContainerType() {
    XMLDescriptor xDesc = xmlContext.getDescriptor(new QName("employee"));
    assertNotNull("No descriptor was generated for EmployeeWithList.", xDesc);
    DatabaseMapping mapping = xDesc.getMappingForAttributeName("stuff");
    assertNotNull("No mapping exists on EmployeeWithList for attribute [stuff].", mapping);
    assertTrue("Expected an XMLAnyCollectionMapping for attribute [stuff], but was [" + mapping.toString() + "].", mapping instanceof XMLAnyCollectionMapping);
    assertTrue("Expected container class [java.util.LinkedList] but was [" + mapping.getContainerPolicy().getContainerClassName() + "]", mapping.getContainerPolicy().getContainerClassName().equals("java.util.LinkedList"));
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) QName(javax.xml.namespace.QName) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 3 with XMLAnyCollectionMapping

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

the class SDOObjectType method addOpenMappings.

protected void addOpenMappings() {
    XMLAnyCollectionMapping anyMapping = new XMLAnyCollectionMapping();
    anyMapping.setAttributeName(ANY_MAPPING_ATTRIBUTE_NAME);
    anyMapping.setGetMethodName(ANY_MAPPING_GET_METHOD_NAME);
    anyMapping.setSetMethodName(ANY_MAPPING_SET_METHOD_NAME);
    anyMapping.setUseXMLRoot(true);
    getXmlDescriptor().addMapping(anyMapping);
    XMLAnyAttributeMapping anyAttrMapping = new XMLAnyAttributeMapping();
    anyAttrMapping.setAttributeName("openContentPropertiesAttributes");
    anyAttrMapping.setGetMethodName("_getOpenContentPropertiesAttributesMap");
    anyAttrMapping.setSetMethodName("_setOpenContentPropertiesAttributesMap");
    getXmlDescriptor().addMapping(anyAttrMapping);
}
Also used : XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)

Example 4 with XMLAnyCollectionMapping

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

the class ChildAndGeneratedPrefixClashProject method getRootDescriptor.

private XMLDescriptor getRootDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Root.class);
    xmlDescriptor.setDefaultRootElement("aaa:root");
    // XMLCompositeCollectionMapping companiesMapping = new XMLCompositeCollectionMapping();
    XMLAnyCollectionMapping companiesMapping = new XMLAnyCollectionMapping();
    companiesMapping.setAttributeName("companies");
    companiesMapping.setXPath("aaa:companies");
    companiesMapping.setUseXMLRoot(true);
    // companiesMapping.setReferenceClass(Company.class);
    xmlDescriptor.addMapping(companiesMapping);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("aaa", "http://www.example.com/aaa");
    xmlDescriptor.setNamespaceResolver(nsResolver);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 5 with XMLAnyCollectionMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping 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)

Aggregations

XMLAnyCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)32 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)26 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)18 XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)18 InputStream (java.io.InputStream)3 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)3 XMLField (org.eclipse.persistence.oxm.XMLField)3 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)3 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 XMLSchemaReference (org.eclipse.persistence.oxm.schema.XMLSchemaReference)2 SOAPBodyElement (jakarta.xml.soap.SOAPBodyElement)1 SOAPElement (jakarta.xml.soap.SOAPElement)1 SOAPException (jakarta.xml.soap.SOAPException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1