Search in sources :

Example 26 with WebParam

use of javax.jws.WebParam in project cxf by apache.

the class RequestWrapper method buildFields.

protected List<JavaField> buildFields(final Method method, final MessageInfo message) {
    List<JavaField> fields = new ArrayList<>();
    final Type[] paramClasses = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    for (MessagePartInfo mpi : message.getMessageParts()) {
        int idx = mpi.getIndex();
        String name = mpi.getName().getLocalPart();
        Type t = paramClasses[idx];
        String type = getTypeString(t);
        JavaField field = new JavaField(name, type, "");
        if (paramAnnotations != null && paramAnnotations.length == paramClasses.length) {
            WebParam wParam = getWebParamAnnotation(paramAnnotations[idx]);
            if (wParam != null && !StringUtils.isEmpty(wParam.targetNamespace())) {
                field.setTargetNamespace(wParam.targetNamespace());
            } else {
                field.setTargetNamespace("");
            }
        }
        List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx);
        field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
        fields.add(field);
    }
    return fields;
}
Also used : Type(java.lang.reflect.Type) WebParam(javax.jws.WebParam) JavaField(org.apache.cxf.tools.common.model.JavaField) ArrayList(java.util.ArrayList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation)

Example 27 with WebParam

use of javax.jws.WebParam in project cxf by apache.

the class ResponseWrapper method buildFields.

protected List<JavaField> buildFields(final Method method, final MessageInfo message) {
    List<JavaField> fields = new ArrayList<>();
    final Class<?> returnType = method.getReturnType();
    JavaField field = new JavaField();
    if (CollectionUtils.isEmpty(message.getMessageParts())) {
        return fields;
    }
    MessagePartInfo part = message.getMessageParts().get(0);
    field.setName(part.getName().getLocalPart());
    field.setTargetNamespace(part.getName().getNamespaceURI());
    if (method.getAnnotation(WebResult.class) == null && method.getAnnotation(javax.xml.ws.ResponseWrapper.class) == null || method.getAnnotation(WebResult.class) != null && method.getAnnotation(WebResult.class).targetNamespace().equals("")) {
        field.setTargetNamespace("");
    }
    boolean hasReturnType = false;
    if (!returnType.isAssignableFrom(void.class)) {
        hasReturnType = true;
        String type = getTypeString(method.getGenericReturnType());
        List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method);
        field.setType(type);
        field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
    }
    fields.add(field);
    final Type[] paramClasses = method.getGenericParameterTypes();
    for (MessagePartInfo mpi : message.getMessageParts()) {
        int idx = hasReturnType ? mpi.getIndex() - 1 : mpi.getIndex();
        if (idx >= 0) {
            String name = mpi.getName().getLocalPart();
            Type t = paramClasses[idx];
            String type = getTypeString(t);
            JavaField jf = new JavaField(name, type, "");
            List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx - 1);
            jf.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
            if (t instanceof ParameterizedType) {
                ParameterizedType pt = (ParameterizedType) t;
                Class<?> c = (Class<?>) pt.getRawType();
                if (Holder.class.isAssignableFrom(c)) {
                    Annotation[][] paramAnnotations = method.getParameterAnnotations();
                    WebParam wParam = getWebParamAnnotation(paramAnnotations[idx]);
                    if (wParam != null && !StringUtils.isEmpty(wParam.targetNamespace())) {
                        jf.setTargetNamespace(wParam.targetNamespace());
                    }
                }
            }
            fields.add(jf);
        }
    }
    return fields;
}
Also used : ArrayList(java.util.ArrayList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WebParam(javax.jws.WebParam) JavaField(org.apache.cxf.tools.common.model.JavaField) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass) WebResult(javax.jws.WebResult)

Example 28 with WebParam

use of javax.jws.WebParam in project cxf by apache.

the class AnnotationUtil method getWebParam.

public static WebParam getWebParam(Method method, String paraName) {
    Annotation[][] anno = getPrivParameterAnnotations(method);
    int count = method.getParameterTypes().length;
    for (int i = 0; i < count; i++) {
        for (Annotation ann : anno[i]) {
            if (ann.annotationType() == WebParam.class) {
                WebParam webParam = (WebParam) ann;
                if (paraName.equals(webParam.name())) {
                    return webParam;
                }
            }
        }
    }
    return null;
}
Also used : WebParam(javax.jws.WebParam) Annotation(java.lang.annotation.Annotation)

Aggregations

WebParam (javax.jws.WebParam)28 Test (org.junit.Test)15 Method (java.lang.reflect.Method)14 WebMethod (javax.jws.WebMethod)12 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)12 Annotation (java.lang.annotation.Annotation)7 File (java.io.File)5 WebResult (javax.jws.WebResult)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 SOAPBinding (javax.jws.soap.SOAPBinding)3 ObjectStreamClass (java.io.ObjectStreamClass)2 Type (java.lang.reflect.Type)2 Holder (javax.xml.ws.Holder)2 RequestWrapper (javax.xml.ws.RequestWrapper)2 ResponseWrapper (javax.xml.ws.ResponseWrapper)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Oneway (javax.jws.Oneway)1