Search in sources :

Example 1 with ConstructorParameterOrder

use of org.apache.openejb.jee.ConstructorParameterOrder in project tomee by apache.

the class HeavyweightOperationInfoBuilder method mapFaults.

private JaxRpcFaultInfo mapFaults(Fault fault) throws OpenEJBException {
    Message message = fault.getMessage();
    ExceptionMapping exceptionMapping = mapping.getExceptionMappingMap().get(message.getQName());
    if (exceptionMapping == null) {
        throw new OpenEJBException("No exception mapping for fault " + fault.getName() + " and fault message " + message.getQName() + " for operation " + operationName);
    }
    // TODO investigate whether there are other cases in which the namespace of faultQName can be determined.
    // this is weird, but I can't figure out what it should be.
    // if part has an element rather than a type, it should be part.getElementName() (see below)
    Part part;
    if (exceptionMapping.getWsdlMessagePartName() != null) {
        // According to schema documentation, this will only be set when several headerfaults use the same message.
        String headerFaultMessagePartName = exceptionMapping.getWsdlMessagePartName();
        part = message.getPart(headerFaultMessagePartName);
    } else {
        part = (Part) message.getOrderedParts(null).iterator().next();
    }
    // Determine the fault qname and xml schema type
    QName faultQName;
    XmlTypeInfo faultTypeInfo;
    if (part.getElementName() != null) {
        XmlElementInfo elementInfo = schemaInfo.elements.get(part.getElementName());
        if (elementInfo == null) {
            throw new OpenEJBException("Can not find element: " + part.getElementName() + ", known elements: " + schemaInfo.elements.keySet());
        }
        faultTypeInfo = schemaInfo.types.get(elementInfo.xmlType);
        if (faultTypeInfo == null) {
            throw new OpenEJBException("Can not find type " + elementInfo.xmlType + " for element " + elementInfo.qname + ", known types: " + schemaInfo.types.keySet());
        }
        faultQName = part.getElementName();
    } else if (part.getTypeName() != null) {
        faultTypeInfo = schemaInfo.types.get(part.getTypeName());
        if (faultTypeInfo == null) {
            throw new OpenEJBException("Can not find type: " + part.getTypeName() + ", known elements: " + schemaInfo.types.keySet());
        }
        faultQName = new QName("", fault.getName());
    } else {
        throw new OpenEJBException("Neither type nor element name supplied for part: " + part);
    }
    //
    // Build the fault info
    //
    JaxRpcFaultInfo faultInfo = new JaxRpcFaultInfo();
    faultInfo.qname = faultQName;
    faultInfo.xmlType = faultTypeInfo.qname;
    faultInfo.javaType = exceptionMapping.getExceptionType();
    faultInfo.complex = faultTypeInfo.simpleBaseType == null;
    //
    if (exceptionMapping.getConstructorParameterOrder() != null) {
        if (faultTypeInfo.simpleBaseType != null) {
            throw new OpenEJBException("ConstructorParameterOrder can only be set for complex types, not " + faultTypeInfo.qname);
        }
        Map<String, XmlElementInfo> elements = new HashMap<String, XmlElementInfo>();
        for (XmlElementInfo element : faultTypeInfo.elements.values()) {
            elements.put(element.qname.getLocalPart(), element);
        }
        ConstructorParameterOrder constructorParameterOrder = exceptionMapping.getConstructorParameterOrder();
        for (int i = 0; i < constructorParameterOrder.getElementName().size(); i++) {
            String paramName = constructorParameterOrder.getElementName().get(i);
            // get the parameter element
            XmlElementInfo paramElementInfo = elements.get(paramName);
            if (paramElementInfo == null) {
                throw new OpenEJBException("Can not find element " + paramName + " in fault type " + faultTypeInfo.qname + ", known elements: " + elements.keySet());
            }
            // Java Type
            String paramJavaType = null;
            XmlTypeInfo paramTypeInfo = schemaInfo.types.get(paramElementInfo.xmlType);
            if (paramTypeInfo != null) {
                if (paramTypeInfo.anonymous) {
                    paramJavaType = anonymousTypes.get(paramTypeInfo.qname.getLocalPart());
                } else {
                    paramJavaType = publicTypes.get(paramTypeInfo.qname);
                }
            }
            // if we don't have a java type yet, check the simple types
            if (paramJavaType == null) {
                paramJavaType = qnameToJavaType.get(paramElementInfo.xmlType);
            }
            if (paramJavaType == null) {
                throw new OpenEJBException("No class mapped for element type: " + paramElementInfo.xmlType);
            }
            JaxRpcParameterInfo parameterInfo = new JaxRpcParameterInfo();
            parameterInfo.qname = paramElementInfo.qname;
            parameterInfo.mode = Mode.OUT;
            // todo could be a soap header
            parameterInfo.soapHeader = false;
            parameterInfo.xmlType = paramElementInfo.xmlType;
            parameterInfo.javaType = paramJavaType;
            faultInfo.parameters.add(parameterInfo);
        }
    }
    return faultInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder) Message(javax.wsdl.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ExceptionMapping(org.apache.openejb.jee.ExceptionMapping) Part(javax.wsdl.Part)

Example 2 with ConstructorParameterOrder

use of org.apache.openejb.jee.ConstructorParameterOrder in project tomee by apache.

the class ExceptionMapping$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final ExceptionMapping exceptionMapping, RuntimeContext context) throws Exception {
    if (exceptionMapping == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (ExceptionMapping.class != exceptionMapping.getClass()) {
        context.unexpectedSubclass(writer, exceptionMapping, ExceptionMapping.class);
        return;
    }
    context.beforeMarshal(exceptionMapping, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = exceptionMapping.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(exceptionMapping, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ELEMENT: exceptionType
    final String exceptionTypeRaw = exceptionMapping.exceptionType;
    String exceptionType = null;
    try {
        exceptionType = Adapters.collapsedStringAdapterAdapter.marshal(exceptionTypeRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(exceptionMapping, "exceptionType", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (exceptionType != null) {
        writer.writeStartElement(prefix, "exception-type", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(exceptionType);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(exceptionMapping, "exceptionType");
    }
    // ELEMENT: wsdlMessage
    final QName wsdlMessage = exceptionMapping.wsdlMessage;
    if (wsdlMessage != null) {
        writer.writeStartElement(prefix, "wsdl-message", "http://java.sun.com/xml/ns/javaee");
        writer.writeQName(wsdlMessage);
        writer.writeEndElement();
    } else {
        context.unexpectedNullValue(exceptionMapping, "wsdlMessage");
    }
    // ELEMENT: wsdlMessagePartName
    final String wsdlMessagePartNameRaw = exceptionMapping.wsdlMessagePartName;
    String wsdlMessagePartName = null;
    try {
        wsdlMessagePartName = Adapters.collapsedStringAdapterAdapter.marshal(wsdlMessagePartNameRaw);
    } catch (final Exception e) {
        context.xmlAdapterError(exceptionMapping, "wsdlMessagePartName", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (wsdlMessagePartName != null) {
        writer.writeStartElement(prefix, "wsdl-message-part-name", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters(wsdlMessagePartName);
        writer.writeEndElement();
    }
    // ELEMENT: constructorParameterOrder
    final ConstructorParameterOrder constructorParameterOrder = exceptionMapping.constructorParameterOrder;
    if (constructorParameterOrder != null) {
        writer.writeStartElement(prefix, "constructor-parameter-order", "http://java.sun.com/xml/ns/javaee");
        writeConstructorParameterOrder(writer, constructorParameterOrder, context);
        writer.writeEndElement();
    }
    context.afterMarshal(exceptionMapping, LifecycleCallback.NONE);
}
Also used : ConstructorParameterOrder$JAXB.writeConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder$JAXB.writeConstructorParameterOrder) ConstructorParameterOrder$JAXB.readConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder$JAXB.readConstructorParameterOrder) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) QName(javax.xml.namespace.QName) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext)

Example 3 with ConstructorParameterOrder

use of org.apache.openejb.jee.ConstructorParameterOrder in project tomee by apache.

the class ExceptionMapping$JAXB method _read.

public static final ExceptionMapping _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final ExceptionMapping exceptionMapping = new ExceptionMapping();
    context.beforeUnmarshal(exceptionMapping, LifecycleCallback.NONE);
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("exception-mappingType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, ExceptionMapping.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, exceptionMapping);
            exceptionMapping.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("exception-type" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: exceptionType
            final String exceptionTypeRaw = elementReader.getElementAsString();
            final String exceptionType;
            try {
                exceptionType = Adapters.collapsedStringAdapterAdapter.unmarshal(exceptionTypeRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            exceptionMapping.exceptionType = exceptionType;
        } else if (("wsdl-message" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: wsdlMessage
            final QName wsdlMessage = elementReader.getElementAsQName();
            exceptionMapping.wsdlMessage = wsdlMessage;
        } else if (("wsdl-message-part-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: wsdlMessagePartName
            final String wsdlMessagePartNameRaw = elementReader.getElementAsString();
            final String wsdlMessagePartName;
            try {
                wsdlMessagePartName = Adapters.collapsedStringAdapterAdapter.unmarshal(wsdlMessagePartNameRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
                continue;
            }
            exceptionMapping.wsdlMessagePartName = wsdlMessagePartName;
        } else if (("constructor-parameter-order" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: constructorParameterOrder
            final ConstructorParameterOrder constructorParameterOrder = readConstructorParameterOrder(elementReader, context);
            exceptionMapping.constructorParameterOrder = constructorParameterOrder;
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "exception-type"), new QName("http://java.sun.com/xml/ns/javaee", "wsdl-message"), new QName("http://java.sun.com/xml/ns/javaee", "wsdl-message-part-name"), new QName("http://java.sun.com/xml/ns/javaee", "constructor-parameter-order"));
        }
    }
    context.afterUnmarshal(exceptionMapping, LifecycleCallback.NONE);
    return exceptionMapping;
}
Also used : ConstructorParameterOrder$JAXB.writeConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder$JAXB.writeConstructorParameterOrder) ConstructorParameterOrder$JAXB.readConstructorParameterOrder(org.apache.openejb.jee.ConstructorParameterOrder$JAXB.readConstructorParameterOrder) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Aggregations

QName (javax.xml.namespace.QName)3 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)2 ConstructorParameterOrder$JAXB.readConstructorParameterOrder (org.apache.openejb.jee.ConstructorParameterOrder$JAXB.readConstructorParameterOrder)2 ConstructorParameterOrder$JAXB.writeConstructorParameterOrder (org.apache.openejb.jee.ConstructorParameterOrder$JAXB.writeConstructorParameterOrder)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 HashMap (java.util.HashMap)1 Message (javax.wsdl.Message)1 Part (javax.wsdl.Part)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 ConstructorParameterOrder (org.apache.openejb.jee.ConstructorParameterOrder)1 ExceptionMapping (org.apache.openejb.jee.ExceptionMapping)1 Attribute (org.metatype.sxc.util.Attribute)1 XoXMLStreamReader (org.metatype.sxc.util.XoXMLStreamReader)1