Search in sources :

Example 11 with ComplexType

use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method processReferenceDescriptor.

/**
 */
protected Element processReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) {
    ComplexType ctype = null;
    if (refDesc.getSchemaReference() == null) {
        ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
    } else {
        element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
    }
    XPathFragment frag = field.getXPathFragment();
    String fragUri = frag.getNamespaceURI();
    if (fragUri != null) {
        // may need to add a global element
        Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
        String targetNS = workingSchema.getTargetNamespace();
        if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
            if (s.getTopLevelElements().get(frag.getShortName()) == null) {
                Element globalElement = new Element();
                globalElement.setName(frag.getLocalName());
                if (ctype != null) {
                    globalElement.setComplexType(ctype);
                } else {
                    globalElement.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
                }
                s.getTopLevelElements().put(frag.getShortName(), globalElement);
            }
            element = new Element();
            element.setMinOccurs(Occurs.ZERO);
            if (isCollection) {
                element.setMaxOccurs(Occurs.UNBOUNDED);
            }
            element.setRef(frag.getShortName());
        } else {
            element.setComplexType(ctype);
        }
    } else if (ctype != null) {
        element.setComplexType(ctype);
    }
    return element;
}
Also used : Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 12 with ComplexType

use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildSchemaComponentsForXPath.

/**
 * This method will build element/complexType/sequence components for a given XPath,
 * and return the sequence that the target element of the mapping should be added
 * to. For example, if the XPath was "contact-info/address/street/text()", street
 * would be the target.  This method defers processing of the target path element
 * to the calling method, allowing for differences in handling, such as direct
 * mappings versus composite mappings, etc.
 */
protected Sequence buildSchemaComponentsForXPath(XPathFragment frag, Sequence seq, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    // the mapping will handle processing of the target fragment; return the sequence it will be added to
    if (frag.getNextFragment() == null || frag.getNextFragment().nameIsText()) {
        return seq;
    }
    Sequence currentSequence = seq;
    // if the current element exists, use it; otherwise create a new one
    Element currentElement = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), currentSequence);
    boolean currentElementExists = (currentElement != null);
    if (currentElement == null) {
        currentElement = new Element();
        // don't set the element name yet, as it may end up being a ref
        ComplexType cType = new ComplexType();
        Sequence sequence = new Sequence();
        cType.setSequence(sequence);
        currentElement.setComplexType(cType);
    }
    Element globalElement = null;
    String fragUri = frag.getNamespaceURI();
    if (fragUri != null) {
        Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
        String targetNS = workingSchema.getTargetNamespace();
        if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
            // must generate a global element are create a reference to it
            // if the global element exists, use it; otherwise create a new one
            globalElement = s.getTopLevelElements().get(frag.getLocalName());
            if (globalElement == null) {
                globalElement = new Element();
                globalElement.setName(frag.getLocalName());
                ComplexType gCType = new ComplexType();
                Sequence gSequence = new Sequence();
                gCType.setSequence(gSequence);
                globalElement.setComplexType(gCType);
                s.addTopLevelElement(globalElement);
            }
            // if the current element doesn't exist set a ref and add it to the sequence
            if (!currentElementExists) {
                // ref won't have a complex type
                currentElement.setComplexType(null);
                currentElement.setRef(frag.getShortName());
                currentSequence.addElement(currentElement);
                currentElementExists = true;
            }
            // make the global element current
            currentElement = globalElement;
        }
    }
    // if we didn't process a global element, and the current element isn't already in the sequence, add it
    if (!currentElementExists && globalElement == null) {
        currentElement.setName(frag.getLocalName());
        currentSequence.addElement(currentElement);
    }
    // set the correct sequence to use/return
    currentSequence = currentElement.getComplexType().getSequence();
    // don't process the last element in the path - let the calling mapping process it
    frag = frag.getNextFragment();
    if (frag.getNextFragment() != null && !frag.getNextFragment().nameIsText()) {
        Element childElt = buildElement(frag, null, Occurs.ZERO, null);
        currentSequence.addElement(childElt);
    }
    // call back into this method to process the next path element
    return buildSchemaComponentsForXPath(frag, currentSequence, schemaForNamespace, workingSchema, properties);
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 13 with ComplexType

use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildComplexType.

/**
 * Create and return a ComplexType for a given XMLDescriptor.  Assumes that the descriptor has a schema context
 * set.
 */
protected ComplexType buildComplexType(boolean anonymous, Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    if (!anonymous) {
        ct.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
    }
    CoreInheritancePolicy inheritancePolicy = desc.getInheritancePolicyOrNull();
    Extension extension = null;
    if (inheritancePolicy != null && inheritancePolicy.getParentClass() != null) {
        extension = new Extension();
        extension.setBaseType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
        ComplexContent complexContent = new ComplexContent();
        complexContent.setExtension(extension);
        ct.setComplexContent(complexContent);
    }
    Sequence seq = new Sequence();
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        processMapping(mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
    }
    if (extension != null) {
        extension.setSequence(seq);
    } else {
        ct.setSequence(seq);
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) CoreInheritancePolicy(org.eclipse.persistence.core.descriptors.CoreInheritancePolicy) ComplexContent(org.eclipse.persistence.internal.oxm.schema.model.ComplexContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Example 14 with ComplexType

use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildComplexTypeWithSimpleContent.

/**
 * Create and return a ComplexType containing simple content for a given XMLDescriptor.  Assumes
 * that the descriptor has a schema context set.
 */
private ComplexType buildComplexTypeWithSimpleContent(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    SimpleContent sc = new SimpleContent();
    Extension extension = new Extension();
    sc.setExtension(extension);
    ct.setSimpleContent(sc);
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        Field xFld = (Field) mapping.getField();
        if (xFld.getXPath().equals(TEXT)) {
            extension.setBaseType(getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema));
        } else if (xFld.getXPathFragment().isAttribute()) {
            String schemaTypeString = getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema);
            Attribute attr = buildAttribute((DirectMapping) mapping, schemaTypeString);
            extension.getOrderedAttributes().add(attr);
        }
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) Field(org.eclipse.persistence.internal.oxm.mappings.Field) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Example 15 with ComplexType

use of org.eclipse.persistence.internal.oxm.schema.model.ComplexType in project eclipselink by eclipse-ee4j.

the class ProviderHelper method invoke.

@SuppressWarnings({ "unchecked" })
public SOAPMessage invoke(SOAPMessage request) {
    Map<String, DataHandler> attachments = null;
    if (mtomEnabled) {
        attachments = (Map<String, DataHandler>) mc.get(INBOUND_MESSAGE_ATTACHMENTS);
    }
    SOAPMessage response;
    boolean usesSOAP12;
    DBWSAdapter dbwsAdapter = (DBWSAdapter) xrService;
    SOAPEnvelope envelope;
    try {
        envelope = request.getSOAPPart().getEnvelope();
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    }
    // check soap 1.2 Namespace in envelope
    String namespaceURI = envelope.getNamespaceURI();
    usesSOAP12 = namespaceURI.equals(URI_NS_SOAP_1_2_ENVELOPE);
    SOAPElement body;
    try {
        body = getSOAPBodyElement(envelope);
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    }
    if (body == null) {
        SOAPFault soapFault;
        try {
            SOAPFactory soapFactory;
            if (usesSOAP12) {
                soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
            } else {
                soapFactory = SOAPFactory.newInstance();
            }
            QName faultCodeQName;
            if (usesSOAP12) {
                faultCodeQName = SENDER_QNAME;
            } else {
                faultCodeQName = CLIENT_QNAME;
            }
            soapFault = soapFactory.createFault("SOAPMessage request format error - missing body element", faultCodeQName);
        } catch (SOAPException se) {
            throw new WebServiceException(se.getMessage(), se);
        }
        throw new SOAPFaultException(soapFault);
    }
    XMLRoot xmlRoot;
    try {
        XMLContext xmlContext = dbwsAdapter.getXMLContext();
        XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
        if (attachments != null && attachments.size() > 0) {
            unmarshaller.setAttachmentUnmarshaller(new XMLAttachmentUnmarshaller() {

                Map<String, DataHandler> attachments;

                public XMLAttachmentUnmarshaller setAttachments(Map<String, DataHandler> attachments) {
                    this.attachments = attachments;
                    return this;
                }

                @Override
                public boolean isXOPPackage() {
                    return true;
                }

                @Override
                public DataHandler getAttachmentAsDataHandler(String id) {
                    // strip off 'cid:' (Is this needed?)
                    String attachmentRefId = id;
                    if (attachmentRefId.startsWith("cid:")) {
                        attachmentRefId = attachmentRefId.substring(4);
                    }
                    return attachments.get(attachmentRefId);
                }

                @Override
                public byte[] getAttachmentAsByteArray(String id) {
                    ByteArrayOutputStream out = null;
                    try {
                        DataHandler dh = attachments.get(id);
                        if (dh == null) {
                            return null;
                        }
                        InputStream in = dh.getInputStream();
                        out = new ByteArrayOutputStream(1024);
                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                    } catch (IOException e) {
                    // e.printStackTrace();
                    }
                    if (out != null) {
                        return out.toByteArray();
                    }
                    return null;
                }
            }.setAttachments(attachments));
            dbwsAdapter.setCurrentAttachmentUnmarshaller(unmarshaller.getAttachmentUnmarshaller());
        }
        xmlRoot = (XMLRoot) unmarshaller.unmarshal(body, Invocation.class);
    } catch (Exception e) {
        SOAPFault soapFault;
        try {
            SOAPFactory soapFactory;
            if (usesSOAP12) {
                soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
            } else {
                soapFactory = SOAPFactory.newInstance();
            }
            QName faultCodeQName;
            if (usesSOAP12) {
                faultCodeQName = SENDER_QNAME;
            } else {
                faultCodeQName = CLIENT_QNAME;
            }
            Throwable e1 = e;
            if (e.getCause() != null) {
                e1 = e.getCause();
            }
            soapFault = soapFactory.createFault("SOAPMessage request format error - " + e1, faultCodeQName);
        } catch (SOAPException se) {
            throw new WebServiceException(se.getMessage(), se);
        }
        throw new SOAPFaultException(soapFault);
    }
    Invocation invocation = (Invocation) xmlRoot.getObject();
    invocation.setName(xmlRoot.getLocalName());
    Operation op = dbwsAdapter.getOperation(invocation.getName());
    /*
         * Fix up types for arguments - scan the extended schema for the operation's Request type.
         *
         * For most parameters, the textual node content is fine, but for date/time and
         * binary objects, we must convert
         */
    org.eclipse.persistence.internal.oxm.schema.model.Element invocationElement = dbwsAdapter.getExtendedSchema().getTopLevelElements().get(invocation.getName());
    String typeName = invocationElement.getType();
    int idx = typeName.indexOf(':');
    if (idx != -1) {
        // strip-off any namespace prefix
        typeName = typeName.substring(idx + 1);
    }
    ComplexType complexType = dbwsAdapter.getExtendedSchema().getTopLevelComplexTypes().get(typeName);
    if (complexType.getSequence() != null) {
        // which has the arguments to the operation
        for (Iterator<org.eclipse.persistence.internal.oxm.schema.model.Element> i = complexType.getSequence().getOrderedElements().iterator(); i.hasNext(); ) {
            org.eclipse.persistence.internal.oxm.schema.model.Element e = i.next();
            String argName = e.getName();
            Object argValue = invocation.getParameter(argName);
            String argType = e.getType();
            if (argType != null) {
                String argTypePrefix = null;
                String nameSpaceURI = null;
                idx = argType.indexOf(':');
                if (idx != -1) {
                    argTypePrefix = argType.substring(0, idx);
                    argType = argType.substring(idx + 1);
                    nameSpaceURI = dbwsAdapter.getSchema().getNamespaceResolver().resolveNamespacePrefix(argTypePrefix);
                }
                QName argQName = argTypePrefix == null ? new QName(nameSpaceURI, argType) : new QName(nameSpaceURI, argType, argTypePrefix);
                Class<?> clz = SCHEMA_2_CLASS.get(argQName);
                if (clz != null) {
                    argValue = ((XMLConversionManager) dbwsAdapter.getOXSession().getDatasourcePlatform().getConversionManager()).convertObject(argValue, clz, argQName);
                    invocation.setParameter(argName, argValue);
                }
            }
        // incoming attachments ?
        }
    }
    Object result;
    try {
        result = op.invoke(dbwsAdapter, invocation);
        if (result instanceof ValueObject) {
            result = ((ValueObject) result).value;
        }
        response = responseWriter.generateResponse(op, usesSOAP12, result);
    } catch (SOAPException se) {
        throw new WebServiceException(se.getMessage(), se);
    } catch (Exception e) {
        try {
            response = responseWriter.generateResponse(op, usesSOAP12, e);
        } catch (SOAPException soape1) {
            SOAPFault soapFault;
            try {
                SOAPFactory soapFactory;
                if (usesSOAP12) {
                    soapFactory = SOAPFactory.newInstance(SOAP_1_2_PROTOCOL);
                } else {
                    soapFactory = SOAPFactory.newInstance();
                }
                QName faultCodeQName;
                if (usesSOAP12) {
                    faultCodeQName = RECEIVER_QNAME;
                } else {
                    faultCodeQName = SERVER_QNAME;
                }
                soapFault = soapFactory.createFault("SOAPMessage response error - " + e.getMessage(), faultCodeQName);
            } catch (SOAPException soape2) {
                throw new WebServiceException(soape2.getMessage(), soape2);
            }
            throw new SOAPFaultException(soapFault);
        }
    }
    return response;
}
Also used : Invocation(org.eclipse.persistence.internal.xr.Invocation) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) DataHandler(jakarta.activation.DataHandler) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) Operation(org.eclipse.persistence.internal.xr.Operation) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPFactory(jakarta.xml.soap.SOAPFactory) XMLAttachmentUnmarshaller(org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller) SOAPException(jakarta.xml.soap.SOAPException) SOAPElement(jakarta.xml.soap.SOAPElement) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ValueObject(org.eclipse.persistence.internal.xr.ValueObject) WebServiceException(jakarta.xml.ws.WebServiceException) XMLContext(org.eclipse.persistence.oxm.XMLContext) QName(javax.xml.namespace.QName) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) InputStream(java.io.InputStream) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPException(jakarta.xml.soap.SOAPException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) DBWSException(org.eclipse.persistence.exceptions.DBWSException) SOAPFault(jakarta.xml.soap.SOAPFault) ValueObject(org.eclipse.persistence.internal.xr.ValueObject) Map(java.util.Map) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Aggregations

ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)29 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)14 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)13 QName (javax.xml.namespace.QName)12 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)9 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)7 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)7 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)6 SDOType (org.eclipse.persistence.sdo.SDOType)5 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)4 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)4 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)4 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)4 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)4 XMLContext (org.eclipse.persistence.oxm.XMLContext)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)4 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3