for (Class<?> clazzInLoop = clazz; clazzInLoop != null; clazzInLoop = clazzInLoop.getSuperclass()) {
Field[] fields = clazzInLoop.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(Property.class)) {
String property = field.getName();
Property r = field.getAnnotation(Property.class);
boolean annotationRedefinesName =!r.name().isEmpty()
&& r.deprecatedMessage().isEmpty();
if (annotationRedefinesName) {
property = r.name();
}
if(property == null || property.isEmpty()) {
throw new IllegalArgumentException("Cannot create empty attribute name for element xs:attribute, field is " + field);
}
Element attributeElement = xmldoc.createElement("xs:attribute");
attributeElement.setAttribute("name", property);
// Agreement with Bela Ban on Jan-20-2009 (Go Obama!!!) to treat all types as
// xs:string since we do not know where users are going to use
// replacement tokens in configuration files. Therefore, the type becomes
// indeterminate.
attributeElement.setAttribute("type", "xs:string");
complexType.appendChild(attributeElement);
Element annotationElement = xmldoc.createElement("xs:annotation");
attributeElement.appendChild(annotationElement);
Element documentationElement = xmldoc.createElement("xs:documentation");
documentationElement.setTextContent(r.description());
annotationElement.appendChild(documentationElement);
}
}
}
// iterate methods
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Property.class)) {
Property annotation = method.getAnnotation(Property.class);
String name = annotation.name();
if (name.length() < 1) {
name = Util.methodNameToAttributeName(method.getName());
}
Element attributeElement = xmldoc.createElement("xs:attribute");
attributeElement.setAttribute("name", name);
attributeElement.setAttribute("type", "xs:string");
complexType.appendChild(attributeElement);
String desc = annotation.description();
if (!desc.isEmpty()) {
Element annotationElement = xmldoc.createElement("xs:annotation");
attributeElement.appendChild(annotationElement);
Element documentationElement = xmldoc.createElement("xs:documentation");
documentationElement.setTextContent(annotation.description());
annotationElement.appendChild(documentationElement);
}
}
}
return classElement;