Search in sources :

Example 6 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateSOAPMessages.

/**
 * Generates messages for a SOAPBinding
 * @param method The {@link JavaMethod} to generate messages for
 * @param binding The {@link com.sun.xml.ws.api.model.soap.SOAPBinding} to add the generated messages to
 */
protected void generateSOAPMessages(JavaMethodImpl method, com.sun.xml.ws.api.model.soap.SOAPBinding binding) {
    boolean isDoclit = binding.isDocLit();
    // Message message = portDefinitions.message().name(method.getOperation().getName().getLocalPart());
    Message message = portDefinitions.message().name(method.getRequestMessageName());
    extension.addInputMessageExtension(message, method);
    com.sun.xml.ws.wsdl.writer.document.Part part;
    BindingContext jaxbContext = model.getBindingContext();
    boolean unwrappable = true;
    for (ParameterImpl param : method.getRequestParameters()) {
        if (isDoclit) {
            if (isHeaderParameter(param))
                unwrappable = false;
            part = message.part().name(param.getPartName());
            part.element(param.getName());
        } else {
            if (param.isWrapperStyle()) {
                for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                    part = message.part().name(childParam.getPartName());
                    part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                }
            } else {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            }
        }
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        message = portDefinitions.message().name(method.getResponseMessageName());
        extension.addOutputMessageExtension(message, method);
        for (ParameterImpl param : method.getResponseParameters()) {
            if (isDoclit) {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            } else {
                if (param.isWrapperStyle()) {
                    for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                        part = message.part().name(childParam.getPartName());
                        part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                    }
                } else {
                    part = message.part().name(param.getPartName());
                    part.element(param.getName());
                }
            }
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        QName tagName = exception.getDetailType().tagName;
        String messageName = exception.getMessageName();
        QName messageQName = new QName(model.getTargetNamespace(), messageName);
        if (processedExceptions.contains(messageQName))
            continue;
        message = portDefinitions.message().name(messageName);
        extension.addFaultMessageExtension(message, method, exception);
        // tagName.getLocalPart());
        part = message.part().name("fault");
        part.element(tagName);
        processedExceptions.add(messageQName);
    }
}
Also used : Message(com.sun.xml.ws.wsdl.writer.document.Message) QName(javax.xml.namespace.QName) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) BindingContext(com.sun.xml.ws.spi.db.BindingContext) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 7 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class TieHandler method createResponseMessageBuilder.

/**
 * prepare objects for creating response {@link Message}
 */
private EndpointResponseMessageBuilder createResponseMessageBuilder(List<MessageFiller> fillers) {
    EndpointResponseMessageBuilder tmpBodyBuilder = null;
    List<ParameterImpl> rp = javaMethodModel.getResponseParameters();
    for (ParameterImpl param : rp) {
        ValueGetter getter = ValueGetter.get(param);
        switch(param.getOutBinding().kind) {
            case BODY:
                if (param.isWrapperStyle()) {
                    if (param.getParent().getBinding().isRpcLit()) {
                        tmpBodyBuilder = new EndpointResponseMessageBuilder.RpcLit((WrapperParameter) param, soapVersion);
                    } else {
                        tmpBodyBuilder = new EndpointResponseMessageBuilder.DocLit((WrapperParameter) param, soapVersion);
                    }
                } else {
                    tmpBodyBuilder = new EndpointResponseMessageBuilder.Bare(param, soapVersion);
                }
                break;
            case HEADER:
                fillers.add(new MessageFiller.Header(param.getIndex(), param.getXMLBridge(), getter));
                break;
            case ATTACHMENT:
                fillers.add(MessageFiller.AttachmentFiller.createAttachmentFiller(param, getter));
                break;
            case UNBOUND:
                break;
            default:
                // impossible
                throw new AssertionError();
        }
    }
    if (tmpBodyBuilder == null) {
        // no parameter binds to body. we create an empty message
        switch(soapVersion) {
            case SOAP_11:
                tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP11;
                break;
            case SOAP_12:
                tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP12;
                break;
            default:
                throw new AssertionError();
        }
    }
    return tmpBodyBuilder;
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter)

Example 8 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class JAXBContextFactory method newContext.

@Override
protected BindingContext newContext(BindingInfo bi) {
    Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
    Map<String, Object> properties = new HashMap<>();
    Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
    // chen workaround for document-literal wrapper - new feature on eclipselink API requested
    for (TypeInfo tinfo : map.keySet()) {
        WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
        if (wp != null) {
            Class<?> wrpCls = (Class) tinfo.type;
            Element javaAttributes = null;
            for (ParameterImpl p : wp.getWrapperChildren()) {
                Element xmlelem = findXmlElement(p.getTypeInfo().properties());
                if (xmlelem != null) {
                    if (javaAttributes == null) {
                        javaAttributes = javaAttributes(wrpCls, extMapping);
                    }
                    xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
                    String fieldName = getFieldName(p, wrpCls);
                    xmlelem.setAttribute("java-attribute", fieldName);
                    javaAttributes.appendChild(xmlelem);
                }
            }
            if (wrpCls.getPackage() != null)
                wrpCls.getPackage().getName();
        }
    }
    // Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
    // if (src != null){
    // TransformerFactory tf = TransformerFactory.newInstance();
    // try {
    // Transformer t = tf.newTransformer();
    // java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
    // StreamResult sax = new StreamResult(bo);
    // t.transform(src, sax);
    // System.out.println(new String(bo.toByteArray()));
    // } catch (TransformerConfigurationException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // } catch (TransformerException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // }
    // }
    HashSet<Type> typeSet = new HashSet<>();
    HashSet<TypeMappingInfo> typeList = new HashSet<>();
    for (TypeMappingInfo tmi : map.values()) {
        typeList.add(tmi);
        typeSet.add(tmi.getType());
    }
    for (Class<?> clss : bi.contentClasses()) {
        if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
            typeSet.add(clss);
            TypeMappingInfo tmi = new TypeMappingInfo();
            tmi.setType(clss);
            typeList.add(tmi);
        }
    }
    TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
    if (extMapping != null) {
        properties.put(OXM_XML_OVERRIDE, extMapping);
    }
    if (bi.getDefaultNamespace() != null) {
        properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
    }
    try {
        org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
        return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
    } catch (JAXBException e) {
        throw new DatabindingException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) XmlElement(jakarta.xml.bind.annotation.XmlElement) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) JAXBContext(jakarta.xml.bind.JAXBContext) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) HashSet(java.util.HashSet) JAXBException(jakarta.xml.bind.JAXBException) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlType(jakarta.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class StubHandler method buildResponseBuilder.

ResponseBuilder buildResponseBuilder(JavaMethodImpl method, ValueSetterFactory setterFactory) {
    // prepare objects for processing response
    List<ParameterImpl> rp = method.getResponseParameters();
    List<ResponseBuilder> builders = new ArrayList<>();
    for (ParameterImpl param : rp) {
        ValueSetter setter;
        switch(param.getOutBinding().kind) {
            case BODY:
                if (param.isWrapperStyle()) {
                    if (param.getParent().getBinding().isRpcLit())
                        builders.add(new ResponseBuilder.RpcLit((WrapperParameter) param, setterFactory));
                    else
                        builders.add(new ResponseBuilder.DocLit((WrapperParameter) param, setterFactory));
                } else {
                    setter = setterFactory.get(param);
                    builders.add(new ResponseBuilder.Body(param.getXMLBridge(), setter));
                }
                break;
            case HEADER:
                setter = setterFactory.get(param);
                builders.add(new ResponseBuilder.Header(soapVersion, param, setter));
                break;
            case ATTACHMENT:
                setter = setterFactory.get(param);
                builders.add(ResponseBuilder.AttachmentBuilder.createAttachmentBuilder(param, setter));
                break;
            case UNBOUND:
                setter = setterFactory.get(param);
                builders.add(new ResponseBuilder.NullSetter(setter, ResponseBuilder.getVMUninitializedValue(param.getTypeInfo().type)));
                break;
            default:
                throw new AssertionError();
        }
    }
    ResponseBuilder rb;
    switch(builders.size()) {
        case 0:
            rb = ResponseBuilder.NONE;
            break;
        case 1:
            rb = builders.get(0);
            break;
        default:
            rb = new ResponseBuilder.Composite(builders);
    }
    return rb;
}
Also used : ArrayList(java.util.ArrayList) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 10 with ParameterImpl

use of com.sun.xml.ws.model.ParameterImpl in project metro-jax-ws by eclipse-ee4j.

the class TieHandler method createArgumentsBuilder.

/**
 * It builds EndpointArgumentsBuilder which converts request {@link Message} to endpoint method's invocation
 * arguments Object[]
 *
 * @return EndpointArgumentsBuilder
 */
private EndpointArgumentsBuilder createArgumentsBuilder() {
    EndpointArgumentsBuilder argsBuilder;
    List<ParameterImpl> rp = javaMethodModel.getRequestParameters();
    List<EndpointArgumentsBuilder> builders = new ArrayList<>();
    for (ParameterImpl param : rp) {
        EndpointValueSetter setter = EndpointValueSetter.get(param);
        switch(param.getInBinding().kind) {
            case BODY:
                if (param.isWrapperStyle()) {
                    if (param.getParent().getBinding().isRpcLit())
                        builders.add(new EndpointArgumentsBuilder.RpcLit((WrapperParameter) param));
                    else
                        builders.add(new EndpointArgumentsBuilder.DocLit((WrapperParameter) param, Mode.OUT));
                } else {
                    builders.add(new EndpointArgumentsBuilder.Body(param.getXMLBridge(), setter));
                }
                break;
            case HEADER:
                builders.add(new EndpointArgumentsBuilder.Header(soapVersion, param, setter));
                break;
            case ATTACHMENT:
                builders.add(EndpointArgumentsBuilder.AttachmentBuilder.createAttachmentBuilder(param, setter));
                break;
            case UNBOUND:
                builders.add(new EndpointArgumentsBuilder.NullSetter(setter, EndpointArgumentsBuilder.getVMUninitializedValue(param.getTypeInfo().type)));
                break;
            default:
                throw new AssertionError();
        }
    }
    // creates {@link Holder} arguments for OUT parameters
    List<ParameterImpl> resp = javaMethodModel.getResponseParameters();
    for (ParameterImpl param : resp) {
        if (param.isWrapperStyle()) {
            WrapperParameter wp = (WrapperParameter) param;
            List<ParameterImpl> children = wp.getWrapperChildren();
            for (ParameterImpl p : children) {
                if (p.isOUT() && p.getIndex() != -1) {
                    EndpointValueSetter setter = EndpointValueSetter.get(p);
                    builders.add(new EndpointArgumentsBuilder.NullSetter(setter, null));
                }
            }
        } else if (param.isOUT() && param.getIndex() != -1) {
            EndpointValueSetter setter = EndpointValueSetter.get(param);
            builders.add(new EndpointArgumentsBuilder.NullSetter(setter, null));
        }
    }
    switch(builders.size()) {
        case 0:
            argsBuilder = EndpointArgumentsBuilder.NONE;
            break;
        case 1:
            argsBuilder = builders.get(0);
            break;
        default:
            argsBuilder = new EndpointArgumentsBuilder.Composite(builders);
    }
    return argsBuilder;
}
Also used : ArrayList(java.util.ArrayList) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Aggregations

ParameterImpl (com.sun.xml.ws.model.ParameterImpl)15 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)9 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)5 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)3 QName (javax.xml.namespace.QName)3 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)2 SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)2 BindingOperationType (com.sun.xml.ws.wsdl.writer.document.BindingOperationType)2 Fault (com.sun.xml.ws.wsdl.writer.document.Fault)2 Body (com.sun.xml.ws.wsdl.writer.document.soap.Body)2 SOAPFault (com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)2 Schema (com.sun.xml.ws.wsdl.writer.document.xsd.Schema)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 HashMap (java.util.HashMap)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)1 Message (com.sun.xml.ws.wsdl.writer.document.Message)1