use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class WrapperBeanFieldAnnotatorTest method testAnnotate.
@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());
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class FaultBeanTest method testTransform.
@Test
public void testTransform() throws Exception {
Class<?> faultClass = Class.forName("org.apache.cxf.tools.fortest.cxf523.DBServiceFault");
FaultBean bean = new FaultBean();
WrapperBeanClass beanClass = bean.transform(faultClass, "org.apache.cxf.tools.fortest.cxf523.jaxws");
assertNotNull(beanClass);
assertEquals("DBServiceFaultBean", beanClass.getName());
assertEquals("org.apache.cxf.tools.fortest.cxf523.jaxws", beanClass.getPackageName());
assertEquals(1, beanClass.getFields().size());
JavaField field = beanClass.getFields().get(0);
assertEquals("message", field.getName());
assertEquals("java.lang.String", field.getType());
QName qname = beanClass.getElementName();
assertEquals("DBServiceFault", qname.getLocalPart());
assertEquals("http://cxf523.fortest.tools.cxf.apache.org/", qname.getNamespaceURI());
}
use of org.apache.cxf.tools.common.model.JavaField 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().isEmpty()) {
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[0]));
}
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[0]));
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;
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class WrapperBeanAnnotator method annotate.
public void annotate(final JavaAnnotatable clz) {
final WrapperBeanClass beanClass;
if (clz instanceof WrapperBeanClass) {
beanClass = (WrapperBeanClass) clz;
} else {
throw new RuntimeException("WrapperBeanAnnotator expect JavaClass as input");
}
JAnnotation xmlRootElement = new JAnnotation(XmlRootElement.class);
xmlRootElement.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlRootElement.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
JAnnotation xmlAccessorType = new JAnnotation(XmlAccessorType.class);
xmlAccessorType.addElement(new JAnnotationElement(null, XmlAccessType.FIELD));
XmlType tp = null;
if (sourceClass != null) {
tp = sourceClass.getAnnotation(XmlType.class);
}
JAnnotation xmlType = new JAnnotation(XmlType.class);
if (tp == null) {
xmlType.addElement(new JAnnotationElement("name", beanClass.getElementName().getLocalPart()));
xmlType.addElement(new JAnnotationElement("namespace", beanClass.getElementName().getNamespaceURI()));
} else {
if (!"##default".equals(tp.name())) {
xmlType.addElement(new JAnnotationElement("name", tp.name()));
}
if (!"##default".equals(tp.namespace())) {
xmlType.addElement(new JAnnotationElement("namespace", tp.namespace()));
}
if (!StringUtils.isEmpty(tp.factoryMethod())) {
xmlType.addElement(new JAnnotationElement("factoryMethod", tp.factoryMethod()));
}
if (tp.propOrder().length != 1 || !StringUtils.isEmpty(tp.propOrder()[0])) {
xmlType.addElement(new JAnnotationElement("propOrder", tp.propOrder()));
}
}
List<String> props = new ArrayList<>();
for (JavaField f : beanClass.getFields()) {
props.add(f.getParaName());
}
if (props.size() > 1) {
xmlType.addElement(new JAnnotationElement("propOrder", props));
}
// Revisit: why annotation is string?
beanClass.addAnnotation(xmlRootElement);
beanClass.addAnnotation(xmlAccessorType);
beanClass.addAnnotation(xmlType);
}
use of org.apache.cxf.tools.common.model.JavaField in project cxf by apache.
the class FaultBean method buildBeanFields.
private void buildBeanFields(final Class<?> exceptionClass, final JavaClass jClass) {
Map<String, JavaField> fields = new TreeMap<>();
for (Method method : exceptionClass.getMethods()) {
if (isIncludedGetter(method)) {
JavaField field = new JavaField(getFieldName(method), method.getReturnType().getName(), "");
field.setOwner(jClass);
fields.put(field.getName(), field);
}
}
for (Map.Entry<String, JavaField> ent : fields.entrySet()) {
jClass.addField(ent.getValue());
jClass.appendGetter(ent.getValue());
jClass.appendSetter(ent.getValue());
}
}
Aggregations