// return the resource as a stream private InputStream mapResource(String publicId) { if (publicId == null || id2resource == null) return null; String resourceName = (String) id2resource.get(publicId); ClassLoader loader = null; if (resourceName == null) return null; if (id2loader != null) loader = (ClassLoader) id2loader.get(publicId); if (loader == null) return ClassLoader.getSystemResourceAsStream(resourceName); return loader.getResourceAsStream(resourceName); }
// This method is called whenever an external entity is accessed // for the first time. public InputSource resolveEntity(String publicId, String systemId) { // Map the external entity to a local file if (URL_PROPERTY_LIST.equals(systemId)) { return new InputSource(ClassLoader.getSystemResourceAsStream(FILENAME_PROPERTY_LIST)); } // Returning null causes the caller to try accessing the systemid return null; }
@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(); }