@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)); } }
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()); }
@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; }
public OperatorDiscoverer() { classLoader = ClassLoader.getSystemClassLoader(); }