/** * 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); }
/** * 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; }