コード例 #1
0
 @SuppressWarnings("unchecked")
 public void addDefaultValue(String className, JSONObject oper) throws Exception {
   ObjectMapper defaultValueMapper = ObjectMapperFactory.getOperatorValueSerializer();
   Class<? extends Operator> clazz = (Class<? extends Operator>) classLoader.loadClass(className);
   if (clazz != null) {
     Operator operIns = clazz.newInstance();
     String s = defaultValueMapper.writeValueAsString(operIns);
     oper.put("defaultValue", new JSONObject(s).get(className));
   }
 }
コード例 #2
0
 public OperatorDiscoverer(String[] jars) {
   URL[] urls = new URL[jars.length];
   for (int i = 0; i < jars.length; i++) {
     pathsToScan.add(jars[i]);
     try {
       urls[i] = new URL("file://" + jars[i]);
     } catch (MalformedURLException ex) {
       throw new RuntimeException(ex);
     }
   }
   classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
 }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public Class<? extends Operator> getOperatorClass(String className)
      throws ClassNotFoundException {
    if (CollectionUtils.isEmpty(operatorClassNames)) {
      loadOperatorClass();
    }

    Class<?> clazz = classLoader.loadClass(className);

    if (!Operator.class.isAssignableFrom(clazz)) {
      throw new IllegalArgumentException("Argument must be a subclass of Operator class");
    }
    return (Class<? extends Operator>) clazz;
  }
コード例 #4
0
 public OperatorDiscoverer() {
   classLoader = ClassLoader.getSystemClassLoader();
 }