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;