Пример #1
0
  private static Set<String> getAnnotationIndex(String path) throws IOException {
    URL[] findClassPaths = ClasspathUrlFinder.findClassPaths("bin");

    AnnotationDB db = new AnnotationDB();
    db.scanArchives(findClassPaths);

    Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
    Set<String> set = annotationIndex.get(path);

    return set;
  }
Пример #2
0
  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.jgrasstools.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();
    }
  }