/** * Executes {@link #findString(String)} assuming the contents URL found is the name of * a class that should be loaded and returned. * * @param uri * @return * @throws IOException * @throws ClassNotFoundException */ public Class findClass(String uri) throws IOException, ClassNotFoundException { String className = findString(uri); return (Class) classLoaderInterface.loadClass(className); }
/** * Executes findAllStrings assuming the strings are * the names of a classes that should be loaded and returned. * <p/> * Any URL or class that cannot be loaded will cause an exception to be thrown. * * @param uri * @return * @throws IOException * @throws ClassNotFoundException */ public List<Class> findAllClasses(String uri) throws IOException, ClassNotFoundException { List<Class> classes = new ArrayList<Class>(); List<String> strings = findAllStrings(uri); for (String className : strings) { Class clazz = classLoaderInterface.loadClass(className); classes.add(clazz); } return classes; }
public Class get() throws ClassNotFoundException { if (clazz != null) return clazz; if (notFound != null) throw notFound; try { this.clazz = classFinder.getClassLoaderInterface().loadClass(name); return clazz; } catch (ClassNotFoundException notFound) { classFinder.getClassesNotLoaded().add(name); this.notFound = notFound; throw notFound; } }
/** * Assumes the class specified points to a file in the classpath that contains * the name of a class that implements or is a subclass of the specfied class. * <p/> * Any class that cannot be loaded will be cause an exception to be thrown. * <p/> * Example classpath: * <p/> * META-INF/java.io.InputStream # contains the classname org.acme.AcmeInputStream * META-INF/java.io.OutputStream * <p/> * ResourceFinder finder = new ResourceFinder("META-INF/"); * Class clazz = finder.findImplementation(java.io.InputStream.class); * clazz.getName(); // returns "org.acme.AcmeInputStream" * * @param interfase a superclass or interface * @return * @throws IOException if the URL cannot be read * @throws ClassNotFoundException if the class found is not loadable * @throws ClassCastException if the class found is not assignable to the specified superclass or interface */ public Class findImplementation(Class interfase) throws IOException, ClassNotFoundException { String className = findString(interfase.getName()); Class impl = classLoaderInterface.loadClass(className); if (!interfase.isAssignableFrom(impl)) { throw new ClassCastException("Class not of type: " + interfase.getName()); } return impl; }
/** * Executes findAvailableStrings assuming the strings are * the names of a classes that should be loaded and returned. * <p/> * Any class that cannot be loaded will be skipped and placed in the * 'resourcesNotLoaded' collection. * * @param uri * @return * @throws IOException if classLoader.getResources throws an exception */ public List<Class> findAvailableClasses(String uri) throws IOException { resourcesNotLoaded.clear(); List<Class> classes = new ArrayList<Class>(); List<String> strings = findAvailableStrings(uri); for (String className : strings) { try { Class clazz = classLoaderInterface.loadClass(className); classes.add(clazz); } catch (Exception notAvailable) { resourcesNotLoaded.add(className); } } return classes; }
String string = entry.getKey(); String className = entry.getValue(); Class clazz = classLoaderInterface.loadClass(className); classes.put(string, clazz);
List<String> strings = findAllStrings(interfase.getName()); for (String className : strings) { Class impl = classLoaderInterface.loadClass(className); if (!interfase.isAssignableFrom(impl)) { throw new ClassCastException("Class not of type: " + interfase.getName());
String className = entry.getValue(); try { Class clazz = classLoaderInterface.loadClass(className); classes.put(string, clazz); } catch (Exception notAvailable) {
String string = entry.getKey(); String className = entry.getValue(); Class impl = classLoaderInterface.loadClass(className); if (!interfase.isAssignableFrom(impl)) { throw new ClassCastException("Class not of type: " + interfase.getName());
for (String className : strings) { try { Class impl = classLoaderInterface.loadClass(className); if (interfase.isAssignableFrom(impl)) { implementations.add(impl);
String className = entry.getValue(); try { Class impl = classLoaderInterface.loadClass(className); if (interfase.isAssignableFrom(impl)) { implementations.put(string, impl);