Search in sources :

Example 11 with JavaField

use of org.apache.cxf.tools.common.model.JavaField 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[0]));
        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 12 with JavaField

use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.

the class Wrapper method buildWrapperBeanClass.

public WrapperBeanClass buildWrapperBeanClass() {
    WrapperBeanClass jClass = getJavaClass();
    List<JavaField> fields = buildFields();
    for (JavaField field : fields) {
        field.setOwner(jClass);
        field.annotate(new WrapperBeanFieldAnnotator());
        jClass.addField(field);
        jClass.appendGetter(field);
        jClass.appendSetter(field);
    }
    jClass.annotate(new WrapperBeanAnnotator());
    return jClass;
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) WrapperBeanAnnotator(org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanAnnotator) WrapperBeanFieldAnnotator(org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator.WrapperBeanFieldAnnotator) WrapperBeanClass(org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)

Example 13 with JavaField

use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.

the class FaultGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        Map<String, JavaExceptionClass> exceptionClasses = javaModel.getExceptionClasses();
        for (Entry<String, JavaExceptionClass> entry : exceptionClasses.entrySet()) {
            JavaExceptionClass expClz = entry.getValue();
            clearAttributes();
            if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
                String faultSerialVersionUID = penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
                setAttributes("faultSerialVersionUID", faultSerialVersionUID);
                if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
                } else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateTimestampSUID());
                } else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
                    // nothing
                    setAttributes("suid", "");
                } else {
                    // do a quick Parse to make sure it looks like a Long
                    try {
                        Long.parseLong(faultSerialVersionUID);
                    } catch (NumberFormatException nfe) {
                        throw new ToolException(nfe);
                    }
                    setAttributes("suid", faultSerialVersionUID);
                }
            } else {
                setAttributes("suid", "");
            }
            setAttributes("expClass", expClz);
            String exceptionSuperclass;
            if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
                exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
            } else {
                exceptionSuperclass = "java.lang.Exception";
            }
            String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
            String exceptionSuperclassString = simpleName;
            for (JavaField jf : expClz.getFields()) {
                String jfClassName = jf.getClassName();
                if (jfClassName.substring(jfClassName.lastIndexOf('.') + 1).equals(simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
                setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
            }
            ClassCollector collector = penv.get(ClassCollector.class);
            for (String pkg : collector.getTypesPackages()) {
                if (collector.containTypesClass(pkg, simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
            }
            if (expClz.getName().equals(exceptionSuperclassString)) {
                exceptionSuperclassString = exceptionSuperclass;
            }
            setAttributes("exceptionSuperclass", exceptionSuperclassString);
            if (!exceptionSuperclass.startsWith("java.lang.") && !exceptionSuperclassString.equals(exceptionSuperclass)) {
                expClz.addImport(exceptionSuperclass);
            }
            setCommonAttributes();
            doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(), expClz.getName()));
        }
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) ToolException(org.apache.cxf.tools.common.ToolException)

Example 14 with JavaField

use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.

the class FaultProcessor method processFault.

private void processFault(JavaMethod method, FaultInfo faultMessage) throws ToolException {
    JavaModel model = method.getInterface().getJavaModel();
    String name = NameUtil.mangleNameToClassName(faultMessage.getName().getLocalPart());
    String namespace = faultMessage.getName().getNamespaceURI();
    String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
    if (namespace.equals(method.getInterface().getNamespace())) {
        packageName = method.getInterface().getPackageName();
    }
    JAXWSBinding jaxwsBinding = faultMessage.getExtensor(JAXWSBinding.class);
    if (jaxwsBinding != null) {
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        if (jaxwsBinding.getJaxwsClass() != null && jaxwsBinding.getJaxwsClass().getClassName() != null) {
            name = jaxwsBinding.getJaxwsClass().getClassName();
            if (name.contains(".")) {
                packageName = name.substring(0, name.lastIndexOf('.'));
                name = name.substring(name.lastIndexOf('.') + 1);
            }
        }
    }
    while (isNameCollision(packageName, name)) {
        name = name + "_Exception";
    }
    String fullClassName = packageName + "." + name;
    collector.addExceptionClassName(packageName, name, fullClassName);
    boolean samePackage = method.getInterface().getPackageName().equals(packageName);
    method.addException(new JavaException(faultMessage.getName().getLocalPart(), samePackage ? name : fullClassName, namespace));
    List<MessagePartInfo> faultParts = faultMessage.getMessageParts();
    JavaExceptionClass expClass = new JavaExceptionClass(model);
    expClass.setName(name);
    expClass.setNamespace(namespace);
    expClass.setPackageName(packageName);
    for (MessagePartInfo part : faultParts) {
        final String fName;
        String fNamespace;
        if (part.getElementQName() != null) {
            fNamespace = part.getElementQName().getNamespaceURI();
            // fNamespace = part.getConcreteName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        } else {
            fNamespace = part.getTypeQName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        }
        if (StringUtils.isEmpty(fNamespace)) {
            fNamespace = namespace;
        }
        String fType = ProcessorUtil.getType(part, context, false);
        // REVISIT - custom JAXB package names
        String fPackageName = method.getInterface().getPackageName();
        JavaField fField = new JavaField(fName, fType, fNamespace);
        fField.setQName(ProcessorUtil.getElementName(part));
        if (!method.getInterface().getPackageName().equals(fPackageName)) {
            fField.setClassName(ProcessorUtil.getFullClzName(part, context, false));
        }
        if (!fType.equals(ProcessorUtil.resolvePartType(part))) {
            fField.setClassName(ProcessorUtil.getType(part, context, true));
        }
        expClass.addField(fField);
    }
    model.addExceptionClass(packageName + "." + name, expClass);
    expClass.setClassJavaDoc(faultMessage.getDocumentation());
}
Also used : JavaException(org.apache.cxf.tools.common.model.JavaException) JavaField(org.apache.cxf.tools.common.model.JavaField) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

JavaField (org.apache.cxf.tools.common.model.JavaField)14 Test (org.junit.Test)6 OperationInfo (org.apache.cxf.service.model.OperationInfo)4 WrapperBeanClass (org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass)4 Annotation (java.lang.annotation.Annotation)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)3 Type (java.lang.reflect.Type)2 WebParam (javax.jws.WebParam)2 QName (javax.xml.namespace.QName)2 MessageInfo (org.apache.cxf.service.model.MessageInfo)2 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)2 JavaClass (org.apache.cxf.tools.common.model.JavaClass)2 JavaExceptionClass (org.apache.cxf.tools.common.model.JavaExceptionClass)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 GreeterArray (org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray)2 ParameterizedType (java.lang.reflect.ParameterizedType)1