use of com.adaptris.annotation.ComponentProfile in project interlok by adaptris.
the class AdapterRegistry method getClassDefinition.
@Override
public String getClassDefinition(String className) throws CoreException {
final ClassDescriptor classDescriptor = new ClassDescriptor(className);
try {
Class<?> clazz = Class.forName(className);
classDescriptor.setClassType(ClassDescriptor.ClassType.getTypeForClass(clazz).name().toLowerCase());
List<String> displayOrder = new ArrayList<>();
for (Annotation annotation : clazz.getAnnotations()) {
if (XStreamAlias.class.isAssignableFrom(annotation.annotationType())) {
classDescriptor.setAlias(((XStreamAlias) annotation).value());
} else if (ComponentProfile.class.isAssignableFrom(annotation.annotationType())) {
classDescriptor.setTags(((ComponentProfile) annotation).tag());
classDescriptor.setSummary(((ComponentProfile) annotation).summary());
} else if (DisplayOrder.class.isAssignableFrom(annotation.annotationType())) {
displayOrder = Arrays.asList(((DisplayOrder) annotation).order());
}
}
for (Field field : clazz.getDeclaredFields()) {
if ((!Modifier.isStatic(field.getModifiers())) && (field.getDeclaredAnnotation(Transient.class) == null)) {
// if we're not transient
ClassDescriptorProperty fieldProperty = new ClassDescriptorProperty();
fieldProperty.setOrder(displayOrder.contains(field.getName()) ? displayOrder.indexOf(field.getName()) + 1 : 999);
fieldProperty.setAdvanced(false);
fieldProperty.setClassName(field.getType().getName());
fieldProperty.setType(field.getType().getSimpleName());
fieldProperty.setName(field.getName());
fieldProperty.setAutoPopulated(field.getDeclaredAnnotation(AutoPopulated.class) != null);
fieldProperty.setNullAllowed(field.getDeclaredAnnotation(NotNull.class) != null);
for (Annotation annotation : field.getDeclaredAnnotations()) {
if (AdvancedConfig.class.isAssignableFrom(annotation.annotationType())) {
fieldProperty.setAdvanced(true);
} else if (InputFieldDefault.class.isAssignableFrom(annotation.annotationType())) {
fieldProperty.setDefaultValue(((InputFieldDefault) annotation).value());
}
}
classDescriptor.getClassDescriptorProperties().add(fieldProperty);
}
}
try (ScanResult result = new ClassGraph().enableAllInfo().blacklistPackages(FCS_BLACKLIST).scan()) {
List<String> subclassNames = result.getSubclasses(className).getNames();
for (String subclassName : subclassNames) {
classDescriptor.getSubTypes().add(subclassName);
}
}
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
return new XStreamJsonMarshaller().marshal(classDescriptor);
}
Aggregations