Search in sources :

Example 1 with JavaField

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

the class WrapperBeanFieldAnnotator method annotate.

public void annotate(final JavaAnnotatable field) {
    final JavaField jField;
    if (field instanceof JavaField) {
        jField = (JavaField) field;
    } else {
        throw new RuntimeException("WrapperBeanFiledAnnotator expect JavaField as input");
    }
    String rawName = jField.getRawName();
    boolean hasEl = false;
    for (Annotation ann : jField.getJaxbAnnotaions()) {
        if (ann instanceof XmlMimeType) {
            JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
            mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType) ann).value()));
            jField.addAnnotation(mimeAnno);
        } else if (ann instanceof XmlJavaTypeAdapter) {
            JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
            jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter) ann).value()));
            jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter) ann).type()));
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlAttachmentRef) {
            JAnnotation jaxbAnn = new JAnnotation(XmlAttachmentRef.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlList) {
            JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
            jField.addAnnotation(jaxbAnn);
        } else if (ann instanceof XmlElement) {
            hasEl = true;
            XmlElement el = (XmlElement) ann;
            JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
            xmlElementAnnotation.addElement(new JAnnotationElement("name", el.name()));
            if (!StringUtils.isEmpty(el.namespace())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("namespace", el.namespace()));
            }
            if (el.nillable()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("nillable", el.nillable(), true));
            }
            if (el.required()) {
                xmlElementAnnotation.addElement(new JAnnotationElement("required", el.required(), true));
            }
            if (!StringUtils.isEmpty(el.defaultValue())) {
                xmlElementAnnotation.addElement(new JAnnotationElement("defaultValue", el.defaultValue()));
            }
            jField.addAnnotation(xmlElementAnnotation);
        }
    }
    if (!hasEl) {
        JAnnotation xmlElementAnnotation = new JAnnotation(XmlElement.class);
        xmlElementAnnotation.addElement(new JAnnotationElement("name", rawName));
        if (!StringUtils.isEmpty(jField.getTargetNamespace())) {
            xmlElementAnnotation.addElement(new JAnnotationElement("namespace", jField.getTargetNamespace()));
        }
        jField.addAnnotation(xmlElementAnnotation);
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) XmlAttachmentRef(javax.xml.bind.annotation.XmlAttachmentRef) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Example 2 with JavaField

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

the class RequestWrapperTest method testBuildRequestFields.

@Test
public void testBuildRequestFields() {
    // Test String[]
    Class<?> testingClass = GreeterArray.class;
    OperationInfo opInfo = getOperation(testingClass, "sayStringArray");
    assertNotNull(opInfo);
    RequestWrapper requestWrapper = new RequestWrapper();
    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());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) GreeterArray(org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Method(java.lang.reflect.Method) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Example 3 with JavaField

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

the class RequestWrapperTest method testCXF1752.

@Test
public void testCXF1752() throws Exception {
    OperationInfo opInfo = getOperation(AddNumbersPortType.class, "testCXF1752");
    RequestWrapper wrapper = new RequestWrapper();
    wrapper.setOperationInfo(opInfo);
    wrapper.buildWrapperBeanClass();
    List<JavaField> fields = wrapper.getJavaClass().getFields();
    assertEquals(6, fields.size());
    assertEquals("java.util.List<java.lang.Long>", fields.get(0).getClassName());
    assertEquals("byte[]", fields.get(2).getClassName());
    assertEquals("org.apache.cxf.tools.fortest.xmllist.AddNumbersPortType.UserObject[]", fields.get(3).getClassName());
    assertEquals("java.util.List<org.apache.cxf.tools.fortest.xmllist.AddNumbersPortType.UserObject>", fields.get(4).getClassName());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) Test(org.junit.Test)

Example 4 with JavaField

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

the class RequestWrapperTest method testNoAnnotationNoClass.

@Test
public void testNoAnnotationNoClass() throws Exception {
    String pkgName = "org.apache.cxf.tools.fortest.classnoanno.docwrapped";
    Class<?> testingClass = Class.forName(pkgName + ".Stock");
    OperationInfo opInfo = getOperation(testingClass, "getPrice");
    Wrapper wrapper = new RequestWrapper();
    wrapper.setOperationInfo(opInfo);
    assertTrue(wrapper.isWrapperAbsent());
    assertTrue(wrapper.isToDifferentPackage());
    assertFalse(wrapper.isWrapperBeanClassNotExist());
    assertEquals(pkgName + ".jaxws", wrapper.getJavaClass().getPackageName());
    assertEquals("GetPrice", wrapper.getJavaClass().getName());
    JavaClass jClass = wrapper.buildWrapperBeanClass();
    assertNotNull(jClass);
    List<JavaField> jFields = jClass.getFields();
    assertEquals(1, jFields.size());
    assertEquals("arg0", jFields.get(0).getName());
    assertEquals("java.lang.String", jFields.get(0).getClassName());
    List<JavaMethod> jMethods = jClass.getMethods();
    assertEquals(2, jMethods.size());
    JavaMethod jMethod = jMethods.get(0);
    assertEquals("getArg0", jMethod.getName());
    assertTrue(jMethod.getParameterListWithoutAnnotation().isEmpty());
    jMethod = jMethods.get(1);
    assertEquals("setArg0", jMethod.getName());
    assertEquals(1, jMethod.getParameterListWithoutAnnotation().size());
    assertEquals("java.lang.String newArg0", jMethod.getParameterListWithoutAnnotation().get(0));
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) JavaClass(org.apache.cxf.tools.common.model.JavaClass) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Example 5 with JavaField

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

the class ResponseWrapperTest method testBuildFields.

@Test
public void testBuildFields() {
    // Test String[]
    Class<?> testingClass = GreeterArray.class;
    OperationInfo opInfo = getOperation(testingClass, "sayStringArray");
    assertNotNull(opInfo);
    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());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) GreeterArray(org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray) Method(java.lang.reflect.Method) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

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