Search in sources :

Example 1 with DisplayOrder

use of com.adaptris.annotation.DisplayOrder 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);
}
Also used : ComponentProfile(com.adaptris.annotation.ComponentProfile) InputFieldDefault(com.adaptris.annotation.InputFieldDefault) ScanResult(io.github.classgraph.ScanResult) DisplayOrder(com.adaptris.annotation.DisplayOrder) ClassGraph(io.github.classgraph.ClassGraph) ArrayList(java.util.ArrayList) URLString(com.adaptris.util.URLString) Annotation(java.lang.annotation.Annotation) Field(java.lang.reflect.Field) XStreamJsonMarshaller(com.adaptris.core.XStreamJsonMarshaller) CoreException(com.adaptris.core.CoreException) Transient(java.beans.Transient)

Aggregations

ComponentProfile (com.adaptris.annotation.ComponentProfile)1 DisplayOrder (com.adaptris.annotation.DisplayOrder)1 InputFieldDefault (com.adaptris.annotation.InputFieldDefault)1 CoreException (com.adaptris.core.CoreException)1 XStreamJsonMarshaller (com.adaptris.core.XStreamJsonMarshaller)1 URLString (com.adaptris.util.URLString)1 ClassGraph (io.github.classgraph.ClassGraph)1 ScanResult (io.github.classgraph.ScanResult)1 Transient (java.beans.Transient)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1