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 annotation = field.getAnnotation(Property.class);
boolean annotationRedefinesName = annotation.name().length() > 0;
if(annotationRedefinesName){
property = annotation.name();
}
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", fieldToXMLSchemaAttributeType(field));
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(annotation.description());
annotationElement.appendChild(documentationElement);
}
}
}
// iterate methods
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Property.class) && method.getName().startsWith("set")) {
Property annotation = method.getAnnotation(Property.class);
String name = annotation.name();
if (name.length() < 1) {
name = Configurator.renameFromJavaCodingConvention(method.getName().substring(3));
}
Element attributeElement = xmldoc.createElement("xs:attribute");
attributeElement.setAttribute("name", name);
attributeElement.setAttribute("type", "xs:string");
complexType.appendChild(attributeElement);
String desc = annotation.description();
if (desc.length() > 0) {
Element annotationElement = xmldoc.createElement("xs:annotation");
attributeElement.appendChild(annotationElement);
Element documentationElement = xmldoc.createElement("xs:documentation");
documentationElement.setTextContent(annotation.description());
annotationElement.appendChild(documentationElement);
}
}
}