public Set<String> getOperatorClasses(String parent, String searchTerm)
      throws ClassNotFoundException {
    if (CollectionUtils.isEmpty(operatorClassNames)) {
      loadOperatorClass();
    }
    if (parent == null) {
      parent = Operator.class.getName();
    } else {
      if (!typeGraph.isAncestor(Operator.class.getName(), parent)) {
        throw new IllegalArgumentException("Argument must be a subclass of Operator class");
      }
    }

    Set<String> filteredClass =
        Sets.filter(
            operatorClassNames,
            new Predicate<String>() {
              @Override
              public boolean apply(String className) {
                OperatorClassInfo oci = classInfo.get(className);
                return oci == null || !oci.tags.containsKey("@omitFromUI");
              }
            });

    if (searchTerm == null && parent.equals(Operator.class.getName())) {
      return filteredClass;
    }

    if (searchTerm != null) {
      searchTerm = searchTerm.toLowerCase();
    }

    Set<String> result = new HashSet<String>();
    for (String clazz : filteredClass) {
      if (parent.equals(Operator.class.getName()) || typeGraph.isAncestor(parent, clazz)) {
        if (searchTerm == null) {
          result.add(clazz);
        } else {
          if (clazz.toLowerCase().contains(searchTerm)) {
            result.add(clazz);
          } else {
            OperatorClassInfo oci = classInfo.get(clazz);
            if (oci != null) {
              if (oci.comment != null && oci.comment.toLowerCase().contains(searchTerm)) {
                result.add(clazz);
              } else {
                for (Map.Entry<String, String> entry : oci.tags.entrySet()) {
                  if (entry.getValue().toLowerCase().contains(searchTerm)) {
                    result.add(clazz);
                    break;
                  }
                }
              }
            }
          }
        }
      }
    }
    return result;
  }
Esempio n. 2
0
  /**
   * Introspects the given class and returns event property descriptors for each writable property
   * found in the class itself, it's superclasses and all interfaces this class and the superclasses
   * implements.
   *
   * @param clazz is the Class to introspect
   * @return list of properties
   */
  public static Set<WriteablePropertyDescriptor> getWritableProperties(Class clazz) {
    // Determine all interfaces implemented and the interface's parent interfaces if any
    Set<Class> propertyOrigClasses = new HashSet<Class>();
    getImplementedInterfaceParents(clazz, propertyOrigClasses);

    // Add class itself
    propertyOrigClasses.add(clazz);

    // Get the set of property names for all classes
    return getWritablePropertiesForClasses(propertyOrigClasses);
  }
Esempio n. 3
0
  private static void getImplementedInterfaceParents(Class clazz, Set<Class> classesResult) {
    Class[] interfaces = clazz.getInterfaces();

    if (interfaces == null) {
      return;
    }

    for (int i = 0; i < interfaces.length; i++) {
      classesResult.add(interfaces[i]);
      getImplementedInterfaceParents(interfaces[i], classesResult);
    }
  }
Esempio n. 4
0
  /**
   * Adds to the given list of property descriptors the mapped properties, ie. properties that have
   * a getter method taking a single String value as a parameter.
   *
   * @param clazz to introspect
   * @param result is the list to add to
   */
  protected static void addMappedProperties(Class clazz, List<InternalEventPropDescriptor> result) {
    Set<String> uniquePropertyNames = new HashSet<String>();
    Method[] methods = clazz.getMethods();

    for (int i = 0; i < methods.length; i++) {
      String methodName = methods[i].getName();
      if (!methodName.startsWith("get")) {
        continue;
      }

      String inferredName = methodName.substring(3, methodName.length());
      if (inferredName.length() == 0) {
        continue;
      }

      Class<?> parameterTypes[] = methods[i].getParameterTypes();
      if (parameterTypes.length != 1) {
        continue;
      }

      if (parameterTypes[0] != String.class) {
        continue;
      }

      String newInferredName = null;
      // Leave uppercase inferred names such as URL
      if (inferredName.length() >= 2) {
        if ((Character.isUpperCase(inferredName.charAt(0)))
            && (Character.isUpperCase(inferredName.charAt(1)))) {
          newInferredName = inferredName;
        }
      }
      // camelCase the inferred name
      if (newInferredName == null) {
        newInferredName = Character.toString(Character.toLowerCase(inferredName.charAt(0)));
        if (inferredName.length() > 1) {
          newInferredName += inferredName.substring(1, inferredName.length());
        }
      }
      inferredName = newInferredName;

      // if the property inferred name already exists, don't supply it
      if (uniquePropertyNames.contains(inferredName)) {
        continue;
      }

      result.add(
          new InternalEventPropDescriptor(inferredName, methods[i], EventPropertyType.MAPPED));
      uniquePropertyNames.add(inferredName);
    }
  }
Esempio n. 5
0
  private static void addIntrospectPropertiesWritable(
      Class clazz, Set<WriteablePropertyDescriptor> result) {
    PropertyDescriptor properties[] = introspect(clazz);
    for (int i = 0; i < properties.length; i++) {
      PropertyDescriptor property = properties[i];
      String propertyName = property.getName();
      Method writeMethod = property.getWriteMethod();

      if (writeMethod == null) {
        continue;
      }

      result.add(
          new WriteablePropertyDescriptor(
              propertyName, writeMethod.getParameterTypes()[0], writeMethod));
    }
  }
Esempio n. 6
0
 public void addReferenceProperty(String propName) {
   referenceProperties.add(propName);
 }
Esempio n. 7
0
 // Here's where the font is set on the editor pane, and we also keep
 // track of the panes in use for future font updates.
 public void install(JEditorPane pane) {
   if (Settings.debug) System.err.println("Installing kit into pane");
   delegate.install(pane);
   panes.add(pane);
   pane.setFont(Settings.font);
 }
  public void buildTypeGraph() {
    Map<String, JarFile> openJarFiles = new HashMap<String, JarFile>();
    Map<String, File> openClassFiles = new HashMap<String, File>();
    // use global cache to load resource in/out of the same jar as the classes
    Set<String> resourceCacheSet = new HashSet<>();
    try {
      for (String path : pathsToScan) {
        File f = null;
        try {
          f = new File(path);
          if (!f.exists()
              || f.isDirectory()
              || (!f.getName().endsWith("jar") && !f.getName().endsWith("class"))) {
            continue;
          }
          if (GENERATED_CLASSES_JAR.equals(f.getName())) {
            continue;
          }
          if (f.getName().endsWith("class")) {
            typeGraph.addNode(f);
            openClassFiles.put(path, f);
          } else {
            JarFile jar = new JarFile(path);
            openJarFiles.put(path, jar);
            java.util.Enumeration<JarEntry> entriesEnum = jar.entries();
            while (entriesEnum.hasMoreElements()) {
              final java.util.jar.JarEntry jarEntry = entriesEnum.nextElement();
              String entryName = jarEntry.getName();
              if (jarEntry.isDirectory()) {
                continue;
              }
              if (entryName.endsWith("-javadoc.xml")) {
                try {
                  processJavadocXml(jar.getInputStream(jarEntry));
                  // break;
                } catch (Exception ex) {
                  LOG.warn("Cannot process javadoc {} : ", entryName, ex);
                }
              } else if (entryName.endsWith(".class")) {
                TypeGraph.TypeGraphVertex newNode = typeGraph.addNode(jarEntry, jar);
                // check if any visited resources belong to this type
                for (Iterator<String> iter = resourceCacheSet.iterator(); iter.hasNext(); ) {
                  String entry = iter.next();
                  if (entry.startsWith(entryName.substring(0, entryName.length() - 6))) {
                    newNode.setHasResource(true);
                    iter.remove();
                  }
                }
              } else {
                String className = entryName;
                boolean foundClass = false;
                // check if this resource belongs to any visited type
                while (className.contains("/")) {
                  className = className.substring(0, className.lastIndexOf('/'));
                  TypeGraph.TypeGraphVertex tgv = typeGraph.getNode(className.replace('/', '.'));
                  if (tgv != null) {
                    tgv.setHasResource(true);
                    foundClass = true;
                    break;
                  }
                }
                if (!foundClass) {
                  resourceCacheSet.add(entryName);
                }
              }
            }
          }
        } catch (IOException ex) {
          LOG.warn("Cannot process file {}", f, ex);
        }
      }

      typeGraph.trim();

      typeGraph.updatePortTypeInfoInTypeGraph(openJarFiles, openClassFiles);
    } finally {
      for (Entry<String, JarFile> entry : openJarFiles.entrySet()) {
        try {
          entry.getValue().close();
        } catch (IOException e) {
          DTThrowable.wrapIfChecked(e);
        }
      }
    }
  }