Search in sources :

Example 16 with XMLAnyObjectMapping

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

the class AnyObjectNoDefaultRootWithGroupingElementProject method buildRootDescriptor.

@Override
public ClassDescriptor buildRootDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Root.class);
    descriptor.setDefaultRootElement("root");
    XMLAnyObjectMapping anyObjectMapping = new XMLAnyObjectMapping();
    anyObjectMapping.setXPath("nested");
    anyObjectMapping.setAttributeName("any");
    anyObjectMapping.setGetMethodName("getAny");
    anyObjectMapping.setSetMethodName("setAny");
    descriptor.addMapping(anyObjectMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 17 with XMLAnyObjectMapping

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

Example 18 with XMLAnyObjectMapping

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

the class SOAPResponseWriter method initialize.

@SuppressWarnings("unchecked")
public void initialize() {
    SOAPResponseClassLoader loader = new SOAPResponseClassLoader(Thread.currentThread().getContextClassLoader());
    NamespaceResolver nr = new NamespaceResolver();
    nr.put(SERVICE_NAMESPACE_PREFIX, dbwsAdapter.getExtendedSchema().getTargetNamespace());
    for (Operation op : dbwsAdapter.getOperationsList()) {
        String className = op.getName() + "_Response";
        Class<?> opClass = loader.buildClass(className);
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setDefaultRootElement(SERVICE_NAMESPACE_PREFIX + ":" + op.getName() + "Response");
        descriptor.setNamespaceResolver(nr);
        descriptor.setJavaClass(opClass);
        if (op instanceof QueryOperation) {
            QueryOperation queryOperation = (QueryOperation) op;
            if (queryOperation.isSimpleXMLFormat()) {
                XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                mapping.setUseXMLRoot(true);
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                descriptor.addMapping(mapping);
                mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
            } else if (queryOperation.isAttachment()) {
                Attachment attachment = queryOperation.getResult().getAttachment();
                XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                mapping.setSwaRef(true);
                mapping.setShouldInlineBinaryData(false);
                mapping.setMimeType(attachment.getMimeType());
                descriptor.addMapping(mapping);
            } else {
                QName type = queryOperation.getResult().getType();
                String localElement = type.getLocalPart();
                // look for top-level complex types
                Set<Map.Entry<String, ComplexType>> entrySet = dbwsAdapter.getSchema().getTopLevelComplexTypes().entrySet();
                for (Map.Entry<String, ComplexType> me : entrySet) {
                    if (me.getValue().getName().equals(type.getLocalPart())) {
                        localElement = me.getKey();
                        break;
                    }
                }
                XMLDescriptor typeDescriptor = dbwsAdapter.getDescriptorsByQName().get(type);
                if (typeDescriptor != null) {
                    if (queryOperation.isCollection()) {
                        XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.useCollectionClass(ArrayList.class);
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    } else {
                        XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    }
                } else {
                    if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
                        XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        descriptor.addMapping(mapping);
                    } else if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, BASE_64_BINARY))) {
                        XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        mapping.setShouldInlineBinaryData(true);
                        ((XMLField) mapping.getField()).setSchemaType(type);
                        descriptor.addMapping(mapping);
                    } else {
                        XMLDirectMapping mapping = new XMLDirectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/text()");
                        descriptor.addMapping(mapping);
                    }
                }
            }
        }
        dbwsAdapter.getOXSession().getProject().addDescriptor(descriptor);
        ((DatabaseSessionImpl) dbwsAdapter.getOXSession()).initializeDescriptorIfSessionAlive(descriptor);
        dbwsAdapter.getXMLContext().storeXMLDescriptorByQName(descriptor);
        resultDescriptors.put(op.getName(), descriptor);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) Set(java.util.Set) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Attachment(org.eclipse.persistence.internal.xr.Attachment) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Operation(org.eclipse.persistence.internal.xr.Operation) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) HashMap(java.util.HashMap) Map(java.util.Map) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 19 with XMLAnyObjectMapping

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

the class AnyTypeProject method getCustomerDescriptor.

public XMLDescriptor getCustomerDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Customer.class);
    descriptor.setDefaultRootElement("customer");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLAnyObjectMapping contactMapping = new XMLAnyObjectMapping();
    contactMapping.setAttributeName("contact");
    descriptor.addMapping(contactMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 20 with XMLAnyObjectMapping

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

the class UnmappedChildWithAnyTestCases method testAnyMapping.

public void testAnyMapping() {
    EmployeeProject employeeProject = new EmployeeProject();
    XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
    anyMapping.setAttributeName("any");
    employeeProject.getEmployeeDescriptor().addMapping(anyMapping);
    XMLContext xmlContext = new XMLContext(employeeProject);
    xmlUnmarshaller = xmlContext.createUnmarshaller();
    xmlUnmarshaller.setUnmappedContentHandlerClass(MyUnmappedContentHandler.class);
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_RESOURCE);
    xmlUnmarshaller.unmarshal(inputStream);
    assertEquals(2, MyUnmappedContentHandler.INSTANCE_COUNTER);
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) InputStream(java.io.InputStream) 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