Package org.apache.cxf.tools.common.model

Examples of org.apache.cxf.tools.common.model.JavaField


    protected List<JavaField> buildFields(final Method method, final MessageInfo message) {
        List<JavaField> fields = new ArrayList<JavaField>();

        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());

        boolean hasReturnType = false;

        if (!returnType.isAssignableFrom(void.class)) {
            hasReturnType = true;
            String type;
            if (returnType.isArray()) {
                if (isBuiltInTypes(returnType.getComponentType())) {
                    type = returnType.getComponentType().getSimpleName() + "[]";
                } else {
                    type = returnType.getComponentType().getName() + "[]";
                }
            } else {
                type = returnType.getName();
            }
            List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method);
            field.setType(type);
            field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
            field.setTargetNamespace("");

        }
        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();
                String type = "Object";

                Type t = paramClasses[idx];
                if (t instanceof Class) {
                    Class clz = (Class) t;
                    if (clz.isArray()) {
                        if (isBuiltInTypes(clz.getComponentType())) {
                            type = clz.getComponentType().getSimpleName() + "[]";
                        } else {
                            type = clz.getComponentType().getName() + "[]";
                        }
                    } else {
                        type = clz.getName();
                    }
                } else if (t instanceof ParameterizedType) {
                    ParameterizedType pt = (ParameterizedType) t;
                    if (pt.getActualTypeArguments().length > 0
                        && pt.getActualTypeArguments()[0] instanceof Class) {
                        type = ((Class)pt.getActualTypeArguments()[0]).getName();
                    }
                }

                JavaField jf = new JavaField(name, type, "");
                List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx - 1);
                jf.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
                fields.add(new JavaField(name, type, ""));

            }
        }

        return fields;
View Full Code Here


            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;
    }
View Full Code Here

    @Test
    public void testAnnotate() {
        JavaClass clz = new JavaClass();
        clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHi");

        JavaField reqField = new JavaField("array",
                                           "String[]",
                                           "http://doc.withannotation.fortest.tools.cxf.apache.org/");

        reqField.setOwner(clz);
        List<JAnnotation> annotation = reqField.getAnnotations();
        assertEquals(0, annotation.size());
       
        reqField.annotate(new WrapperBeanFieldAnnotator());
        annotation = reqField.getAnnotations();

        String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
        assertEquals("@XmlElement(name = \"array\", namespace = \"" + expectedNamespace + "\")",
                     annotation.get(0).toString());

        clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
        JavaField resField = new JavaField("return",
                                           "String[]",
                                           "http://doc.withannotation.fortest.tools.cxf.apache.org/");
        resField.setOwner(clz);
        resField.annotate(new WrapperBeanFieldAnnotator());
        annotation = resField.getAnnotations();
        assertEquals("@XmlElement(name = \"return\", namespace = \"" + expectedNamespace + "\")",
                     annotation.get(0).toString());
    }
View Full Code Here

    @Test
    public void testAnnotate() {
        JavaClass clz = new JavaClass();
        clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHi");

        JavaField reqField = new JavaField("array",
                                           "String[]",
                                           "http://doc.withannotation.fortest.tools.cxf.apache.org/");

        reqField.setOwner(clz);
        JavaAnnotation annotation = reqField.getAnnotation();
        assertNull(annotation);
       
        reqField.annotate(new WrapperBeanFieldAnnotator());
        annotation = reqField.getAnnotation();

        String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
        assertEquals("@XmlElement(namespace = \"" + expectedNamespace + "\", name = \"array\")",
                     annotation.toString());

        clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
        JavaField resField = new JavaField("return",
                                           "String[]",
                                           "http://doc.withannotation.fortest.tools.cxf.apache.org/");
        resField.setOwner(clz);
        resField.annotate(new WrapperBeanFieldAnnotator());
        annotation = resField.getAnnotation();
        assertEquals("@XmlElement(namespace = \"" + expectedNamespace + "\", name = \"return\")",
                     annotation.toString());
    }
View Full Code Here

        MessageInfo message = opInfo.getUnwrappedOperation().getInput();
        Method method = (Method)opInfo.getProperty("operation.method");

        List<JavaField> fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        JavaField field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("String[]", field.getType());

        // Test int[]

        opInfo = getOperation(testingClass, "sayIntArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getInput();
        method = (Method) opInfo.getProperty("operation.method");

        fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("int[]", field.getType());

        // Test TestDataBean[]
       
        opInfo = getOperation(testingClass, "sayTestDataBeanArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getInput();
        method = (Method) opInfo.getProperty("operation.method");

        fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
    }
View Full Code Here

            //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);
View Full Code Here

        ResponseWrapper responseWrapper = new ResponseWrapper();

        MessageInfo message = opInfo.getUnwrappedOperation().getOutput();
        Method method = (Method)opInfo.getProperty("operation.method");

        JavaField field  = responseWrapper.buildFields(method, message).get(0);
        assertEquals("_return", field.getParaName());
        assertEquals("String[]", field.getType());

        // Test int[]

        opInfo = getOperation(testingClass, "sayIntArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getOutput();
        method = (Method) opInfo.getProperty("operation.method");

        field = responseWrapper.buildFields(method, message).get(0);
        assertEquals("_return", field.getParaName());
        assertEquals("int[]", field.getType());

        // Test TestDataBean[]
       
        opInfo = getOperation(testingClass, "sayTestDataBeanArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getOutput();
        method = (Method) opInfo.getProperty("operation.method");

        field = responseWrapper.buildFields(method, message).get(0);
        assertEquals("_return", field.getParaName());
        assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
    }
View Full Code Here

    }
   
    private void buildBeanFields(final Class exceptionClass, final JavaClass jClass) {
        for (Method method : exceptionClass.getMethods()) {
            if (isIncludedGetter(method)) {
                JavaField field = new JavaField(getFieldName(method),
                                                method.getReturnType().getName(),
                                                "");
                field.setOwner(jClass);
                jClass.addField(field);
                jClass.appendGetter(field);
                jClass.appendSetter(field);
            }
        }
View Full Code Here

                }
            } else {
                type = returnType.getName();
            }
            String name = part.getName().getLocalPart();
            JavaField field = new JavaField(name, type, "");
            field.setTargetNamespace("");
            fields.add(field);           
        }
       
        final Class[] paramClasses = method.getParameterTypes();
        for (MessagePartInfo mpi : message.getMessageParts()) {
            int idx = mpi.getIndex();
            if (idx > 0) {
                String name = mpi.getName().getLocalPart();
                String type;
                Class clz = paramClasses[idx - 1];
                if (clz.isArray()) {
                    if (isBuiltInTypes(clz.getComponentType())) {
                        type = clz.getComponentType().getSimpleName() + "[]";
                    } else {
                        type = clz.getComponentType().getName() + "[]";
                    }
                } else {
                    type = clz.getName();
                }
                JavaField field = new JavaField(name, type, "");
                field.setTargetNamespace("");
                fields.add(field);
            }
        }
       
        return fields;
View Full Code Here

        MessageInfo message = opInfo.getUnwrappedOperation().getInput();
        Method method = (Method)opInfo.getProperty("operation.method");

        List<JavaField> fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        JavaField field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("String[]", field.getType());

        // Test int[]

        opInfo = getOperation(testingClass, "sayIntArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getInput();
        method = (Method) opInfo.getProperty("operation.method");

        fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("int[]", field.getType());

        // Test TestDataBean[]
       
        opInfo = getOperation(testingClass, "sayTestDataBeanArray");
        assertNotNull(opInfo);

        message = opInfo.getUnwrappedOperation().getInput();
        method = (Method) opInfo.getProperty("operation.method");

        fields = requestWrapper.buildFields(method, message);
        assertEquals(1, fields.size());
        field = fields.get(0);
        assertEquals("arg0", field.getName());
        assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.tools.common.model.JavaField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.