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