Search in sources :

Example 1 with ComponentAccess

use of oms3.ComponentAccess in project hortonmachine by TheHortonMachine.

the class ModelsSupporter method generateHelp.

public static String generateHelp(Object parent) throws Exception {
    Class<?> moduleClass = parent.getClass();
    StringBuilder sb = new StringBuilder();
    // try with module description
    Description description = moduleClass.getAnnotation(Description.class);
    String descriptionStr = description.value();
    String NEWLINE = "\n";
    if (description != null) {
        sb.append("Description").append(NEWLINE);
        sb.append("-----------").append(NEWLINE);
        sb.append(NEWLINE);
        sb.append(descriptionStr);
        sb.append(NEWLINE);
        sb.append(NEWLINE);
    }
    // general info
    sb.append("General Information").append(NEWLINE);
    sb.append("-------------------").append(NEWLINE);
    sb.append(NEWLINE);
    // general info: status
    Status status = moduleClass.getAnnotation(Status.class);
    if (status != null) {
        sb.append("Module status: " + ModelsSupporter.getStatusString(status.value())).append(NEWLINE);
    }
    // general info: authors
    Author author = moduleClass.getAnnotation(Author.class);
    if (author != null) {
        String authorNameStr = author.name();
        String[] authorNameSplit = authorNameStr.split(",");
        String authorContactStr = author.contact();
        String[] authorContactSplit = authorContactStr.split(",");
        sb.append("Authors").append(NEWLINE);
        for (String authorName : authorNameSplit) {
            sb.append("* ").append(authorName.trim()).append(NEWLINE);
        }
        sb.append(NEWLINE);
        sb.append("Contacts: ").append(NEWLINE);
        for (String authorContact : authorContactSplit) {
            sb.append("* ").append(authorContact.trim()).append(NEWLINE);
        }
        sb.append(NEWLINE);
    }
    // general info: license
    License license = moduleClass.getAnnotation(License.class);
    if (license != null) {
        String licenseStr = license.value();
        sb.append("License: " + licenseStr).append(NEWLINE);
    }
    // general info: keywords
    Keywords keywords = moduleClass.getAnnotation(Keywords.class);
    if (keywords != null) {
        String keywordsStr = keywords.value();
        sb.append("Keywords: " + keywordsStr).append(NEWLINE);
    }
    sb.append(NEWLINE);
    // gather input fields
    Object annotatedObject = moduleClass.newInstance();
    ComponentAccess cA = new ComponentAccess(annotatedObject);
    // parameters
    sb.append("Parameters").append(NEWLINE);
    sb.append("----------").append(NEWLINE);
    sb.append(NEWLINE);
    // parameters: fields
    Collection<Access> inputs = cA.inputs();
    StringBuilder sbTmp = new StringBuilder();
    ModelsSupporter.collectParameters(sbTmp, inputs, "\t");
    String params = sbTmp.toString();
    if (params.trim().length() > 0) {
        sb.append("\tInput Parameters").append(NEWLINE);
        sb.append("\t----------------").append(NEWLINE);
        sb.append(params);
        sb.append(NEWLINE);
    }
    Collection<Access> outputs = cA.outputs();
    sbTmp = new StringBuilder();
    ModelsSupporter.collectParameters(sbTmp, outputs, "\t");
    params = sbTmp.toString();
    if (params.trim().length() > 0) {
        sb.append("\tOutput Parameters").append(NEWLINE);
        sb.append("\t-----------------").append(NEWLINE);
        sb.append(params);
        sb.append(NEWLINE);
    }
    sb.append(NEWLINE);
    return sb.toString();
}
Also used : Status(oms3.annotations.Status) Description(oms3.annotations.Description) Keywords(oms3.annotations.Keywords) License(oms3.annotations.License) Access(oms3.Access) ComponentAccess(oms3.ComponentAccess) ComponentAccess(oms3.ComponentAccess) Author(oms3.annotations.Author)

Example 2 with ComponentAccess

use of oms3.ComponentAccess in project hortonmachine by TheHortonMachine.

the class SpatialToolboxUtils method collectParameters.

// /**
// * Get the path for a module doc html.
// *
// * @param moduleClassName the name of the module to get the path for.
// * @return the path to the html file.
// * @throws Exception
// */
// public static String getModuleDocumentationPath( String moduleClassName ) throws Exception {
// File configurationsFolder = SpatialToolboxSessionPluginSingleton.getInstance().getConfigurationsFolder();
// File htmlDocsFolder = new File(configurationsFolder, STAGEHTMLDOCS);
// File htmlDocs = new File(htmlDocsFolder, moduleClassName + ".html");
// if (!htmlDocs.exists()) {
// htmlDocs = new File(htmlDocsFolder, "Oms" + moduleClassName + ".html");
// if (!htmlDocs.exists()) {
// return NO_DOCUMENTATION_AVAILABLE;
// }
// }
// return htmlDocs.getAbsolutePath();
// }
// /**
// * Porge the html docs folder.
// *
// * @throws Exception
// */
// public static void cleanModuleDocumentation() throws Exception {
// File configurationsFolder = SpatialToolboxSessionPluginSingleton.getInstance().getConfigurationsFolder();
// File htmlDocsFolder = new File(configurationsFolder, STAGEHTMLDOCS);
// if (htmlDocsFolder.exists()) {
// FileUtilities.deleteFileOrDir(htmlDocsFolder);
// }
// }
// 
// /**
// * Generate the module documentation in the configuration area.
// *
// * @param moduleClassName the class for which to generate the doc.
// * @throws Exception
// */
// @SuppressWarnings("nls")
// public static void generateModuleDocumentation( String moduleClassName ) throws Exception {
// 
// Class< ? > moduleClass = StageModulesManager.getInstance().getModulesClass(moduleClassName);
// 
// StringBuilder sb = new StringBuilder();
// sb.append("<html><body>\n");
// 
// // modules documentation
// Documentation documentation = moduleClass.getAnnotation(Documentation.class);
// String documentationStr = null;
// if (documentation != null) {
// documentationStr = AnnotationUtilities.getLocalizedDocumentation(documentation);
// if (documentationStr.length() == 0) {
// documentationStr = null;
// } else if (documentationStr.equals(" - ")) {
// documentationStr = null;
// }
// }
// if (documentation != null && documentationStr != null) {
// if (documentationStr.endsWith(DOCSSUFFIX)) {
// // have to get the file
// String modulePackage = moduleClassName.substring(0, moduleClassName.lastIndexOf('.'));
// String path = modulePackage.replaceAll("\\.", "/") + "/" + documentationStr;
// InputStream inStream = StageModulesManager.getInstance().getResourceAsStream(path);
// // InputStream inStream = moduleClass.getResourceAsStream(documentationStr);
// if (inStream != null) {
// BufferedReader br = null;
// try {
// br = new BufferedReader(new InputStreamReader(inStream));
// StringBuilder tmpSb = new StringBuilder();
// String line = "";
// while( (line = br.readLine()) != null ) {
// tmpSb.append(line).append(NEWLINE);
// }
// documentationStr = tmpSb.toString();
// } finally {
// if (br != null)
// br.close();
// }
// }
// }
// sb.append("<h2>Description</h2>").append(NEWLINE);
// sb.append(NEWLINE);
// sb.append("<blockquote>");
// sb.append(documentationStr);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// sb.append(NEWLINE);
// } else {
// // try with module description
// Description description = moduleClass.getAnnotation(Description.class);
// String descriptionStr = AnnotationUtilities.getLocalizedDescription(description);
// if (description != null) {
// sb.append("<h2>Description</h2>").append(NEWLINE);
// sb.append(NEWLINE);
// sb.append("<blockquote>");
// sb.append(descriptionStr);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// sb.append(NEWLINE);
// }
// }
// // general info
// sb.append("<h2>General Information</h2>").append(NEWLINE);
// sb.append(NEWLINE);
// // general info: status
// Status status = moduleClass.getAnnotation(Status.class);
// if (status != null) {
// sb.append("<blockquote>");
// sb.append("Module status: " + getStatusString(status.value())).append(NEWLINE);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// }
// 
// // general info: script name
// Name name = moduleClass.getAnnotation(Name.class);
// String nameStr = AnnotationUtilities.getLocalizedName(name);
// if (name != null) {
// sb.append("<blockquote>");
// sb.append(" Name to use in a script: <b>" + nameStr + "</b>").append(NEWLINE);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// }
// // general info: authors
// Author author = moduleClass.getAnnotation(Author.class);
// if (author != null) {
// String authorNameStr = author.name();
// String[] authorNameSplit = authorNameStr.split(",");
// 
// String authorContactStr = author.contact();
// String[] authorContactSplit = authorContactStr.split(",");
// 
// sb.append("<blockquote>");
// sb.append(" Authors ").append(NEWLINE);
// sb.append(HTMLNEWLINE);
// sb.append("<ul>").append(NEWLINE);
// for( String authorName : authorNameSplit ) {
// sb.append("<li>").append(authorName.trim());
// }
// sb.append("</li>").append(NEWLINE);
// sb.append("</ul>").append(NEWLINE);
// sb.append(NEWLINE);
// sb.append(HTMLNEWLINE);
// sb.append(HTMLNEWLINE);
// // if (authorContactStr.startsWith("http")) {
// // authorContactStr = "<a href=\"" + authorContactStr + "\">" + authorContactStr +
// // "</a>";
// // }
// sb.append(" Contacts: ").append(NEWLINE);
// sb.append(HTMLNEWLINE);
// sb.append("<ul>").append(NEWLINE);
// for( String authorContact : authorContactSplit ) {
// sb.append("<li>").append(authorContact.trim());
// }
// sb.append("</li>").append(NEWLINE);
// sb.append("</ul>").append(NEWLINE);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// }
// // general info: license
// License license = moduleClass.getAnnotation(License.class);
// if (license != null) {
// String licenseStr = AnnotationUtilities.getLocalizedLicense(license);
// sb.append("<blockquote>");
// sb.append(" License: " + licenseStr).append(NEWLINE);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// }
// // general info: keywords
// Keywords keywords = moduleClass.getAnnotation(Keywords.class);
// if (keywords != null) {
// String keywordsStr = AnnotationUtilities.getLocalizedKeywords(keywords);
// sb.append("<blockquote>");
// sb.append(" Keywords: " + keywordsStr).append(NEWLINE);
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// }
// sb.append(NEWLINE);
// 
// // gather input fields
// Object annotatedObject = moduleClass.newInstance();
// ComponentAccess cA = new ComponentAccess(annotatedObject);
// 
// // parameters
// sb.append("<h2>Parameters</h2>").append(NEWLINE);
// sb.append(NEWLINE);
// sb.append("<blockquote>");
// // parameters: fields
// Collection<Access> inputs = cA.inputs();
// StringBuilder sbTmp = new StringBuilder();
// collectParameters(sbTmp, inputs);
// toTable(sb, sbTmp, "Input parameters");
// sb.append(NEWLINE);
// Collection<Access> outputs = cA.outputs();
// sbTmp = new StringBuilder();
// collectParameters(sbTmp, outputs);
// toTable(sb, sbTmp, "Output parameters");
// sb.append("</blockquote>");
// sb.append(NEWLINE);
// sb.append(NEWLINE);
// 
// sb.append("</body></html>");
// 
// File configurationsFolder = SpatialToolboxSessionPluginSingleton.getInstance().getConfigurationsFolder();
// File htmlDocsFolder = new File(configurationsFolder, STAGEHTMLDOCS);
// if (!htmlDocsFolder.exists()) {
// if (!htmlDocsFolder.mkdir()) {
// throw new RuntimeException();
// }
// }
// 
// File htmlDocs = new File(htmlDocsFolder, moduleClassName + ".html");
// FileUtilities.writeFile(sb.toString(), htmlDocs);
// }
private static void collectParameters(StringBuilder sbTmp, Collection<Access> accessList) throws Exception {
    for (Access access : accessList) {
        Field field = access.getField();
        String fieldName = field.getName();
        Description descriptionAnnot = field.getAnnotation(Description.class);
        if (fieldName.equals("pm")) {
            // ignore progress monitor
            continue;
        }
        String fieldDescription = " - ";
        if (descriptionAnnot != null) {
            fieldDescription = AnnotationUtilities.getLocalizedDescription(descriptionAnnot);
            if (fieldDescription == null) {
                fieldDescription = " - ";
            }
            Unit unitAnn = field.getAnnotation(Unit.class);
            if (unitAnn != null) {
                fieldDescription = fieldDescription + " [" + unitAnn.value() + "]";
            }
        }
        sbTmp.append("<tr>").append(NEWLINE);
        sbTmp.append("<td width=\"40%\"> <b>").append(fieldName).append("</b> </td><td width=\"60%\"> ");
        sbTmp.append(fieldDescription).append(" </td>").append(NEWLINE);
        sbTmp.append("</tr>").append(NEWLINE);
    }
}
Also used : Field(java.lang.reflect.Field) Description(oms3.annotations.Description) Access(oms3.Access) Unit(oms3.annotations.Unit)

Example 3 with ComponentAccess

use of oms3.ComponentAccess in project hortonmachine by TheHortonMachine.

the class HortonMachine method gatherInformations.

private void gatherInformations() {
    try {
        if (baseclassUrl == null) {
            baseclassUrl = ClasspathUrlFinder.findClassBase(HortonMachine.class);
        }
        AnnotationDB db = new AnnotationDB();
        db.scanArchives(baseclassUrl);
        Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
        Set<String> simpleClasses = annotationIndex.get(Execute.class.getName());
        for (String className : simpleClasses) {
            if (!className.startsWith("org.hortonmachine.hmachine")) {
                continue;
            }
            int lastDot = className.lastIndexOf('.');
            String name = className.substring(lastDot + 1);
            Class<?> clazz = null;
            try {
                clazz = Class.forName(className);
                moduleName2Class.put(name, clazz);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        /*
             * extract all classes and fields
             */
        List<String> classNames = new ArrayList<String>();
        List<String> fieldNamesList = new ArrayList<String>();
        Set<Entry<String, Class<?>>> moduleName2ClassEntries = moduleName2Class.entrySet();
        for (Entry<String, Class<?>> moduleName2ClassEntry : moduleName2ClassEntries) {
            String moduleName = moduleName2ClassEntry.getKey();
            Class<?> moduleClass = moduleName2ClassEntry.getValue();
            Status annotation = moduleClass.getAnnotation(Status.class);
            if (annotation == null) {
                System.out.println("Missing status: " + moduleClass.getCanonicalName());
                continue;
            }
            String statusString = null;
            int status = annotation.value();
            switch(status) {
                case Status.CERTIFIED:
                    statusString = "CERTIFIED";
                    break;
                case Status.DRAFT:
                    statusString = "DRAFT";
                    break;
                case Status.TESTED:
                    statusString = "TESTED";
                    break;
                default:
                    statusString = "UNKNOWN";
                    break;
            }
            classNames.add(moduleName);
            List<ClassField> tmpfields = new ArrayList<ClassField>();
            Object annotatedObject = moduleClass.newInstance();
            ComponentAccess cA = new ComponentAccess(annotatedObject);
            Collection<Access> inputs = cA.inputs();
            for (Access access : inputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isIn = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            Collection<Access> outputs = cA.outputs();
            for (Access access : outputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isOut = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            moduleName2Fields.put(moduleName, tmpfields);
        }
        Collections.sort(fieldNamesList);
        allFields = (String[]) fieldNamesList.toArray(new String[fieldNamesList.size()]);
        Collections.sort(classNames);
        allClasses = (String[]) classNames.toArray(new String[classNames.size()]);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : AnnotationDB(org.scannotation.AnnotationDB) Set(java.util.Set) Description(oms3.annotations.Description) Execute(oms3.annotations.Execute) ArrayList(java.util.ArrayList) Access(oms3.Access) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Field(java.lang.reflect.Field) Entry(java.util.Map.Entry) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Status(oms3.annotations.Status) IOException(java.io.IOException)

Example 4 with ComponentAccess

use of oms3.ComponentAccess in project hortonmachine by TheHortonMachine.

the class Lesto method gatherInformations.

private void gatherInformations() {
    try {
        if (baseclassUrl == null) {
            baseclassUrl = ClasspathUrlFinder.findClassBase(Lesto.class);
        }
        AnnotationDB db = new AnnotationDB();
        db.scanArchives(baseclassUrl);
        Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
        Set<String> simpleClasses = annotationIndex.get(Execute.class.getName());
        for (String className : simpleClasses) {
            if (!className.startsWith("org.hortonmachine.lesto")) {
                continue;
            }
            int lastDot = className.lastIndexOf('.');
            String name = className.substring(lastDot + 1);
            Class<?> clazz = null;
            try {
                clazz = Class.forName(className);
                moduleName2Class.put(name, clazz);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        /*
             * extract all classes and fields
             */
        List<String> classNames = new ArrayList<String>();
        List<String> fieldNamesList = new ArrayList<String>();
        Set<Entry<String, Class<?>>> moduleName2ClassEntries = moduleName2Class.entrySet();
        for (Entry<String, Class<?>> moduleName2ClassEntry : moduleName2ClassEntries) {
            String moduleName = moduleName2ClassEntry.getKey();
            Class<?> moduleClass = moduleName2ClassEntry.getValue();
            Status annotation = moduleClass.getAnnotation(Status.class);
            if (annotation == null) {
                System.out.println("Missing status: " + moduleClass.getCanonicalName());
                continue;
            }
            String statusString = null;
            int status = annotation.value();
            switch(status) {
                case Status.CERTIFIED:
                    statusString = "CERTIFIED";
                    break;
                case Status.DRAFT:
                    statusString = "DRAFT";
                    break;
                case Status.TESTED:
                    statusString = "TESTED";
                    break;
                default:
                    statusString = "UNKNOWN";
                    break;
            }
            classNames.add(moduleName);
            List<ClassField> tmpfields = new ArrayList<ClassField>();
            Object annotatedObject = moduleClass.newInstance();
            ComponentAccess cA = new ComponentAccess(annotatedObject);
            Collection<Access> inputs = cA.inputs();
            for (Access access : inputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isIn = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            Collection<Access> outputs = cA.outputs();
            for (Access access : outputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isOut = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            moduleName2Fields.put(moduleName, tmpfields);
        }
        Collections.sort(fieldNamesList);
        allFields = (String[]) fieldNamesList.toArray(new String[fieldNamesList.size()]);
        Collections.sort(classNames);
        allClasses = (String[]) classNames.toArray(new String[classNames.size()]);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : AnnotationDB(org.scannotation.AnnotationDB) Set(java.util.Set) Description(oms3.annotations.Description) Execute(oms3.annotations.Execute) ArrayList(java.util.ArrayList) Access(oms3.Access) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Field(java.lang.reflect.Field) Entry(java.util.Map.Entry) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Status(oms3.annotations.Status) IOException(java.io.IOException)

Example 5 with ComponentAccess

use of oms3.ComponentAccess in project hortonmachine by TheHortonMachine.

the class JGrassGears method gatherInformations.

private void gatherInformations() {
    try {
        if (baseclassUrl == null) {
            baseclassUrl = ClasspathUrlFinder.findClassBase(JGrassGears.class);
        }
        // logger.debug("base class url: " + baseclassUrl);
        AnnotationDB db = new AnnotationDB();
        db.scanArchives(baseclassUrl);
        Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
        Set<String> simpleClasses = annotationIndex.get(Execute.class.getName());
        for (String className : simpleClasses) {
            if (!className.startsWith("org.hortonmachine.gears")) {
                continue;
            }
            // logger.debug("check: " + className);
            int lastDot = className.lastIndexOf('.');
            String name = className.substring(lastDot + 1);
            Class<?> clazz = null;
            try {
                clazz = Class.forName(className);
                moduleName2Class.put(name, clazz);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        /*
             * extract all classes and fields
             */
        List<String> classNames = new ArrayList<>();
        List<String> fieldNamesList = new ArrayList<>();
        Set<Entry<String, Class<?>>> moduleName2ClassEntries = moduleName2Class.entrySet();
        for (Entry<String, Class<?>> moduleName2ClassEntry : moduleName2ClassEntries) {
            String moduleName = moduleName2ClassEntry.getKey();
            Class<?> moduleClass = moduleName2ClassEntry.getValue();
            Status annotation = moduleClass.getAnnotation(Status.class);
            if (annotation == null) {
                System.out.println("Missing status: " + moduleClass.getCanonicalName());
                continue;
            }
            String statusString;
            int status = annotation.value();
            switch(status) {
                case Status.CERTIFIED:
                    statusString = "CERTIFIED";
                    break;
                case Status.DRAFT:
                    statusString = "DRAFT";
                    break;
                case Status.TESTED:
                    statusString = "TESTED";
                    break;
                default:
                    statusString = "UNKNOWN";
                    break;
            }
            classNames.add(moduleName);
            List<ClassField> tmpfields = new ArrayList<>();
            Object annotatedObject = moduleClass.newInstance();
            ComponentAccess cA = new ComponentAccess(annotatedObject);
            Collection<Access> inputs = cA.inputs();
            for (Access access : inputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isIn = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            Collection<Access> outputs = cA.outputs();
            for (Access access : outputs) {
                Field field = access.getField();
                String name = field.getName();
                Description descriptionAnnot = field.getAnnotation(Description.class);
                String description = name;
                if (descriptionAnnot != null) {
                    description = descriptionAnnot.value();
                    if (description == null) {
                        description = name;
                    }
                }
                Class<?> fieldClass = field.getType();
                ClassField cf = new ClassField();
                cf.isOut = true;
                cf.fieldName = name;
                cf.fieldDescription = description;
                cf.fieldClass = fieldClass;
                cf.parentClass = moduleClass;
                cf.parentClassStatus = statusString;
                if (!fieldNamesList.contains(name)) {
                    fieldNamesList.add(name);
                }
                tmpfields.add(cf);
            }
            moduleName2Fields.put(moduleName, tmpfields);
        }
        Collections.sort(fieldNamesList);
        allFields = (String[]) fieldNamesList.toArray(new String[fieldNamesList.size()]);
        Collections.sort(classNames);
        allClasses = (String[]) classNames.toArray(new String[classNames.size()]);
    } catch (InstantiationException | IllegalAccessException | IOException e) {
        e.printStackTrace();
    }
}
Also used : AnnotationDB(org.scannotation.AnnotationDB) Set(java.util.Set) Description(oms3.annotations.Description) Execute(oms3.annotations.Execute) ArrayList(java.util.ArrayList) Access(oms3.Access) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Field(java.lang.reflect.Field) Entry(java.util.Map.Entry) ComponentAccess(oms3.ComponentAccess) ClassField(org.hortonmachine.gears.libs.modules.ClassField) Status(oms3.annotations.Status) IOException(java.io.IOException)

Aggregations

Access (oms3.Access)11 ComponentAccess (oms3.ComponentAccess)11 ArrayList (java.util.ArrayList)9 Description (oms3.annotations.Description)8 Status (oms3.annotations.Status)6 Field (java.lang.reflect.Field)5 Entry (java.util.Map.Entry)5 IOException (java.io.IOException)4 Set (java.util.Set)4 Execute (oms3.annotations.Execute)4 Role (oms3.annotations.Role)4 ClassField (org.hortonmachine.gears.libs.modules.ClassField)4 AnnotationDB (org.scannotation.AnnotationDB)4 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Bound (oms3.annotations.Bound)2 Range (oms3.annotations.Range)2 FileWriter (java.io.FileWriter)1