Search in sources :

Example 1 with UI

use of oms3.annotations.UI in project hortonmachine by TheHortonMachine.

the class HortonMachine method main.

public static void main(String[] args) throws IOException {
    HortonMachine hm = HortonMachine.getInstance();
    Set<Entry<String, Class<?>>> cls = hm.moduleName2Class.entrySet();
    for (Entry<String, Class<?>> cl : cls) {
        System.out.println(cl.getValue().getCanonicalName());
    }
    if (true)
        return;
    LinkedHashMap<String, List<ClassField>> moduleName2Fields = hm.moduleName2Fields;
    LinkedHashMap<String, Class<?>> moduleName2Class = hm.moduleName2Class;
    Set<Entry<String, List<ClassField>>> entrySet = moduleName2Fields.entrySet();
    for (Entry<String, List<ClassField>> entry : entrySet) {
        String moduleName = entry.getKey();
        StringBuilder sb = new StringBuilder();
        Class<?> moduleClass = moduleName2Class.get(moduleName);
        Description description = moduleClass.getAnnotation(Description.class);
        sb.append("public static final String " + moduleName.toUpperCase() + "_DESCRIPTION = \"" + description.value() + "\";\n");
        Documentation documentation = moduleClass.getAnnotation(Documentation.class);
        String doc;
        if (documentation == null) {
            doc = "";
        } else {
            doc = documentation.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_DOCUMENTATION = \"" + doc + "\";\n");
        Keywords keywords = moduleClass.getAnnotation(Keywords.class);
        String k;
        if (keywords == null) {
            k = "";
        } else {
            k = keywords.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_KEYWORDS = \"" + k + "\";\n");
        Label label = moduleClass.getAnnotation(Label.class);
        String lab;
        if (label == null) {
            lab = "";
        } else {
            lab = label.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_LABEL = \"" + lab + "\";\n");
        Name name = moduleClass.getAnnotation(Name.class);
        String n;
        if (name == null) {
            n = "";
        } else {
            n = name.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_NAME = \"" + n + "\";\n");
        Status status = moduleClass.getAnnotation(Status.class);
        // String st = "";
        // switch( status.value() ) {
        // case 5:
        // st = "EXPERIMENTAL";
        // break;
        // case 10:
        // st = "DRAFT";
        // break;
        // case 20:
        // st = "TESTED";
        // break;
        // case 30:
        // st = "VALIDATED";
        // break;
        // case 40:
        // st = "CERTIFIED";
        // break;
        // default:
        // st = "DRAFT";
        // break;
        // }
        sb.append("public static final int " + moduleName.toUpperCase() + "_STATUS = " + status.value() + ";\n");
        License license = moduleClass.getAnnotation(License.class);
        sb.append("public static final String " + moduleName.toUpperCase() + "_LICENSE = \"" + license.value() + "\";\n");
        Author author = moduleClass.getAnnotation(Author.class);
        String authorName = author.name();
        sb.append("public static final String " + moduleName.toUpperCase() + "_AUTHORNAMES = \"" + authorName + "\";\n");
        String authorContact = author.contact();
        sb.append("public static final String " + moduleName.toUpperCase() + "_AUTHORCONTACTS = \"" + authorContact + "\";\n");
        UI ui = moduleClass.getAnnotation(UI.class);
        if (ui != null) {
            sb.append("public static final String " + moduleName.toUpperCase() + "_UI = \"" + ui.value() + "\";\n");
        }
        List<ClassField> value = entry.getValue();
        for (ClassField classField : value) {
            String fieldName = classField.fieldName;
            if (fieldName.equals("pm")) {
                continue;
            }
            String fieldDescription = classField.fieldDescription;
            String str = "public static final String " + moduleName.toUpperCase() + "_" + fieldName + "_DESCRIPTION = \"" + fieldDescription + "\";\n";
            sb.append(str);
        }
        System.out.println(sb.toString());
        System.out.println();
    }
// for( String className : hm.allClasses ) {
// System.out.println(className);
// }
// for( String fieldName : hm.allFields ) {
// System.out.println(fieldName);
// }
}
Also used : Status(oms3.annotations.Status) Description(oms3.annotations.Description) Keywords(oms3.annotations.Keywords) Documentation(oms3.annotations.Documentation) Label(oms3.annotations.Label) License(oms3.annotations.License) Name(oms3.annotations.Name) Entry(java.util.Map.Entry) UI(oms3.annotations.UI) Author(oms3.annotations.Author) ArrayList(java.util.ArrayList) List(java.util.List) ClassField(org.hortonmachine.gears.libs.modules.ClassField)

Example 2 with UI

use of oms3.annotations.UI in project hortonmachine by TheHortonMachine.

the class HortonmachineModulesManager method addInput.

private void addInput(Access access, ModuleDescription module) throws Exception {
    Field field = access.getField();
    Description descriptionAnn = field.getAnnotation(Description.class);
    String descriptionStr = "No description available";
    if (descriptionAnn != null) {
        descriptionStr = AnnotationUtilities.getLocalizedDescription(descriptionAnn);
    }
    StringBuilder sb = new StringBuilder();
    sb.append(descriptionStr);
    Unit unitAnn = field.getAnnotation(Unit.class);
    if (unitAnn != null) {
        sb.append(" [");
        sb.append(unitAnn.value());
        sb.append("]");
    }
    Range rangeAnn = field.getAnnotation(Range.class);
    if (rangeAnn != null) {
        sb.append(" [");
        sb.append(rangeAnn.min());
        sb.append(" ,");
        sb.append(rangeAnn.max());
        sb.append("]");
    }
    descriptionStr = sb.toString();
    String fieldName = field.getName();
    if (doIgnore(fieldName)) {
        return;
    }
    Class<?> fieldClass = field.getType();
    Object fieldValue = access.getFieldValue();
    // $NON-NLS-1$
    String defaultValue = "";
    if (fieldValue != null) {
        defaultValue = fieldValue.toString();
    }
    UI uiHintAnn = field.getAnnotation(UI.class);
    String uiHint = null;
    if (uiHintAnn != null) {
        uiHint = uiHintAnn.value();
    }
    module.addInput(fieldName, fieldClass.getCanonicalName(), descriptionStr, defaultValue, uiHint);
}
Also used : Field(java.lang.reflect.Field) Description(oms3.annotations.Description) UI(oms3.annotations.UI) Unit(oms3.annotations.Unit) Range(oms3.annotations.Range)

Example 3 with UI

use of oms3.annotations.UI in project hortonmachine by TheHortonMachine.

the class HortonmachineModulesManager method init.

public void init() throws Exception {
    synchronized (modulesMap) {
        if (modulesMap.size() > 0) {
            return;
        }
    }
    LinkedHashMap<String, Class<?>> moduleNames2Classes = Modules.getInstance().moduleName2Class;
    // LinkedHashMap<String, List<ClassField>> moduleName2Fields =
    // Modules.getInstance().moduleName2Fields;
    LinkedHashMap<String, Class<?>> lestoModuleNames2Class = Lesto.getInstance().moduleName2Class;
    // LinkedHashMap<String, List<ClassField>> lestoModuleName2Fields =
    // Lesto.getInstance().moduleName2Fields;
    // also gather horton and gears
    HortonMachine.getInstance();
    Map<String, Class<?>> gearsModuleName2Class = JGrassGears.getInstance().moduleName2Class;
    for (Entry<String, Class<?>> entry : lestoModuleNames2Class.entrySet()) {
        String name = entry.getKey();
        if (name.startsWith("Oms")) {
            continue;
        }
        moduleNames2Classes.put(name, entry.getValue());
    }
    for (Entry<String, Class<?>> entry : gearsModuleName2Class.entrySet()) {
        String name = entry.getKey();
        if (name.startsWith("Oms")) {
            continue;
        }
        moduleNames2Classes.put(name, entry.getValue());
    }
    Collection<Class<?>> classesList = moduleNames2Classes.values();
    for (Class<?> moduleClass : classesList) {
        try {
            String simpleName = moduleClass.getSimpleName();
            UI uiHints = moduleClass.getAnnotation(UI.class);
            if (uiHints != null) {
                String uiHintStr = uiHints.value();
                if (uiHintStr.contains(HMConstants.HIDE_UI_HINT)) {
                    continue;
                }
            }
            Label category = moduleClass.getAnnotation(Label.class);
            String categoryStr = HMConstants.OTHER;
            if (category != null && categoryStr.trim().length() > 1) {
                categoryStr = category.value();
            }
            Description description = moduleClass.getAnnotation(Description.class);
            String descrStr = null;
            if (description != null) {
                descrStr = description.value();
            }
            Status status = moduleClass.getAnnotation(Status.class);
            ModuleDescription module = new ModuleDescription(moduleClass, categoryStr, descrStr, status);
            Object newInstance = null;
            try {
                newInstance = moduleClass.newInstance();
            } catch (Throwable e) {
                // ignore module
                continue;
            }
            try {
                // generate the html docs
                String className = module.getClassName();
            // FIXME
            // SpatialToolboxUtils.generateModuleDocumentation(className);
            } catch (Exception e) {
            // ignore doc if it breaks
            }
            ComponentAccess cA = new ComponentAccess(newInstance);
            Collection<Access> inputs = cA.inputs();
            for (Access access : inputs) {
                addInput(access, module);
            }
            Collection<Access> outputs = cA.outputs();
            for (Access access : outputs) {
                addOutput(access, module);
            }
            if (categoryStr.equals(HMConstants.GRIDGEOMETRYREADER) || categoryStr.equals(HMConstants.RASTERREADER) || categoryStr.equals(HMConstants.RASTERWRITER) || categoryStr.equals(HMConstants.FEATUREREADER) || categoryStr.equals(HMConstants.FEATUREWRITER) || categoryStr.equals(HMConstants.GENERICREADER) || categoryStr.equals(HMConstants.GENERICWRITER) || categoryStr.equals(HMConstants.HASHMAP_READER) || categoryStr.equals(HMConstants.HASHMAP_WRITER) || categoryStr.equals(HMConstants.LIST_READER) || categoryStr.equals(HMConstants.LIST_WRITER)) {
            // ignore for now
            } else {
                List<ModuleDescription> modulesList4Category = modulesMap.get(categoryStr);
                if (modulesList4Category == null) {
                    modulesList4Category = new ArrayList<ModuleDescription>();
                    modulesMap.put(categoryStr, modulesList4Category);
                }
                modulesList4Category.add(module);
            }
        } catch (NoClassDefFoundError e) {
            if (moduleClass != null)
                Logger.INSTANCE.insertError("", "ERROR", e.getCause());
        }
    }
    // sort
    Set<Entry<String, List<ModuleDescription>>> entrySet = modulesMap.entrySet();
    for (Entry<String, List<ModuleDescription>> entry : entrySet) {
        Collections.sort(entry.getValue(), new ModuleDescription.ModuleDescriptionNameComparator());
    }
}
Also used : Description(oms3.annotations.Description) Label(oms3.annotations.Label) Access(oms3.Access) ComponentAccess(oms3.ComponentAccess) Entry(java.util.Map.Entry) ComponentAccess(oms3.ComponentAccess) UI(oms3.annotations.UI) ArrayList(java.util.ArrayList) List(java.util.List) Status(oms3.annotations.Status)

Example 4 with UI

use of oms3.annotations.UI in project hortonmachine by TheHortonMachine.

the class HortonmachineModulesManager method addOutput.

private void addOutput(Access access, ModuleDescription module) throws Exception {
    Field field = access.getField();
    Description descriptionAnn = field.getAnnotation(Description.class);
    String descriptionStr = "No description available";
    if (descriptionAnn != null) {
        descriptionStr = AnnotationUtilities.getLocalizedDescription(descriptionAnn);
    }
    StringBuilder sb = new StringBuilder();
    sb.append(descriptionStr);
    Unit unitAnn = field.getAnnotation(Unit.class);
    if (unitAnn != null) {
        sb.append(" [");
        sb.append(unitAnn.value());
        sb.append("]");
    }
    Range rangeAnn = field.getAnnotation(Range.class);
    if (rangeAnn != null) {
        sb.append(" [");
        sb.append(rangeAnn.min());
        sb.append(" ,");
        sb.append(rangeAnn.max());
        sb.append("]");
    }
    descriptionStr = sb.toString();
    String fieldName = field.getName();
    if (doIgnore(fieldName)) {
        return;
    }
    Class<?> fieldClass = field.getType();
    Object fieldValue = access.getFieldValue();
    // $NON-NLS-1$
    String defaultValue = "";
    if (fieldValue != null) {
        defaultValue = fieldValue.toString();
    }
    UI uiHintAnn = field.getAnnotation(UI.class);
    String uiHint = null;
    if (uiHintAnn != null) {
        uiHint = uiHintAnn.value();
    }
    module.addOutput(fieldName, fieldClass.getCanonicalName(), descriptionStr, defaultValue, uiHint);
}
Also used : Field(java.lang.reflect.Field) Description(oms3.annotations.Description) UI(oms3.annotations.UI) Unit(oms3.annotations.Unit) Range(oms3.annotations.Range)

Example 5 with UI

use of oms3.annotations.UI in project hortonmachine by TheHortonMachine.

the class Lesto method main.

public static void main(String[] args) throws IOException {
    Lesto hm = Lesto.getInstance();
    Set<Entry<String, Class<?>>> cls = hm.moduleName2Class.entrySet();
    for (Entry<String, Class<?>> cl : cls) {
        System.out.println(cl.getValue().getCanonicalName());
    }
    if (true)
        return;
    LinkedHashMap<String, List<ClassField>> moduleName2Fields = hm.moduleName2Fields;
    LinkedHashMap<String, Class<?>> moduleName2Class = hm.moduleName2Class;
    Set<Entry<String, List<ClassField>>> entrySet = moduleName2Fields.entrySet();
    for (Entry<String, List<ClassField>> entry : entrySet) {
        String moduleName = entry.getKey();
        StringBuilder sb = new StringBuilder();
        Class<?> moduleClass = moduleName2Class.get(moduleName);
        Description description = moduleClass.getAnnotation(Description.class);
        sb.append("public static final String " + moduleName.toUpperCase() + "_DESCRIPTION = \"" + description.value() + "\";\n");
        Documentation documentation = moduleClass.getAnnotation(Documentation.class);
        String doc;
        if (documentation == null) {
            doc = "";
        } else {
            doc = documentation.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_DOCUMENTATION = \"" + doc + "\";\n");
        Keywords keywords = moduleClass.getAnnotation(Keywords.class);
        String k;
        if (keywords == null) {
            k = "";
        } else {
            k = keywords.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_KEYWORDS = \"" + k + "\";\n");
        Label label = moduleClass.getAnnotation(Label.class);
        String lab;
        if (label == null) {
            lab = "";
        } else {
            lab = label.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_LABEL = \"" + lab + "\";\n");
        Name name = moduleClass.getAnnotation(Name.class);
        String n;
        if (name == null) {
            n = "";
        } else {
            n = name.value();
        }
        sb.append("public static final String " + moduleName.toUpperCase() + "_NAME = \"" + n + "\";\n");
        Status status = moduleClass.getAnnotation(Status.class);
        // String st = "";
        // switch( status.value() ) {
        // case 5:
        // st = "EXPERIMENTAL";
        // break;
        // case 10:
        // st = "DRAFT";
        // break;
        // case 20:
        // st = "TESTED";
        // break;
        // case 30:
        // st = "VALIDATED";
        // break;
        // case 40:
        // st = "CERTIFIED";
        // break;
        // default:
        // st = "DRAFT";
        // break;
        // }
        sb.append("public static final int " + moduleName.toUpperCase() + "_STATUS = " + status.value() + ";\n");
        License license = moduleClass.getAnnotation(License.class);
        sb.append("public static final String " + moduleName.toUpperCase() + "_LICENSE = \"" + license.value() + "\";\n");
        Author author = moduleClass.getAnnotation(Author.class);
        String authorName = author.name();
        sb.append("public static final String " + moduleName.toUpperCase() + "_AUTHORNAMES = \"" + authorName + "\";\n");
        String authorContact = author.contact();
        sb.append("public static final String " + moduleName.toUpperCase() + "_AUTHORCONTACTS = \"" + authorContact + "\";\n");
        UI ui = moduleClass.getAnnotation(UI.class);
        if (ui != null) {
            sb.append("public static final String " + moduleName.toUpperCase() + "_UI = \"" + ui.value() + "\";\n");
        }
        List<ClassField> value = entry.getValue();
        for (ClassField classField : value) {
            String fieldName = classField.fieldName;
            if (fieldName.equals("pm")) {
                continue;
            }
            String fieldDescription = classField.fieldDescription;
            String str = "public static final String " + moduleName.toUpperCase() + "_" + fieldName + "_DESCRIPTION = \"" + fieldDescription + "\";\n";
            sb.append(str);
        }
        System.out.println(sb.toString());
        System.out.println();
    }
// for( String className : hm.allClasses ) {
// System.out.println(className);
// }
// for( String fieldName : hm.allFields ) {
// System.out.println(fieldName);
// }
}
Also used : Status(oms3.annotations.Status) Description(oms3.annotations.Description) Keywords(oms3.annotations.Keywords) Documentation(oms3.annotations.Documentation) Label(oms3.annotations.Label) License(oms3.annotations.License) Name(oms3.annotations.Name) Entry(java.util.Map.Entry) UI(oms3.annotations.UI) Author(oms3.annotations.Author) ArrayList(java.util.ArrayList) List(java.util.List) ClassField(org.hortonmachine.gears.libs.modules.ClassField)

Aggregations

Description (oms3.annotations.Description)7 UI (oms3.annotations.UI)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Entry (java.util.Map.Entry)5 Label (oms3.annotations.Label)5 Status (oms3.annotations.Status)5 Author (oms3.annotations.Author)4 Documentation (oms3.annotations.Documentation)4 Keywords (oms3.annotations.Keywords)4 License (oms3.annotations.License)4 Name (oms3.annotations.Name)4 ClassField (org.hortonmachine.gears.libs.modules.ClassField)4 Field (java.lang.reflect.Field)2 Range (oms3.annotations.Range)2 Unit (oms3.annotations.Unit)2 Access (oms3.Access)1 ComponentAccess (oms3.ComponentAccess)1