List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.pentaho.platform.engine.core.system.objfac.spring.BeanPublishParser.java
private Class<?> findClass(String beanClassName) throws ClassNotFoundException { // try main classloader // getClass().getClassLoader() Class<?> clazz = loadClassFromClassloader(getClass().getClassLoader(), beanClassName); if (clazz != null) { return clazz; }//from w ww . j a va 2s .com if (getPluginManager() != null) { for (String s : getPluginManager().getRegisteredPlugins()) { clazz = loadClassFromClassloader(getPluginManager().getClassLoader(s), beanClassName); if (clazz != null) { return clazz; } } } throw new ClassNotFoundException(beanClassName); }
From source file:com.runwaysdk.generation.loader.RunwayClassLoader.java
/** * *//*from ww w . j av a2 s. c o m*/ protected Class<?> findClass(final String name) throws ClassNotFoundException { String mod = name.replace('.', '/') + ".class"; URL res = this.findResource(mod); if (res != null) { try { Class<?> clazz = null; Byte[] objectArray = FileIO.getBytesFromStream(res.openStream()); byte[] classBytes = ArrayUtils.toPrimitive(objectArray); if (implementsReloadable(classBytes)) { clazz = defineClass(name, classBytes, 0, classBytes.length); classes.put(name, clazz); return clazz; } } catch (IOException e1) { throw new ClassNotFoundException("Error reading class " + name); } // throw new ClassNotFoundException("Unable to find class " + name); } return null; }
From source file:org.seamless_ip.services.dao.IndicatorDaoImpl.java
@SuppressWarnings("unchecked") private IIndicatorTO createTO(Object dbItem) throws ClassNotFoundException { if (dbItem == null) return null; if (dbItem instanceof EndorsedIndicator) return createTO((EndorsedIndicator) dbItem); if (dbItem instanceof ModelVariable) return createTO((ModelVariable) dbItem); throw new ClassNotFoundException(dbItem.getClass().getName() + " is not a recognized indicator class!"); }
From source file:org.ireland.jnetty.loader.WebAppClassLoader.java
@Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz = loadClass0(name); if (clazz != null) { if (resolve) resolveClass(clazz);/*from ww w. j ava 2 s . co m*/ return (clazz); } throw new ClassNotFoundException(name); }
From source file:org.apache.openjpa.lib.conf.Configurations.java
/** * Helper method used by members of this package to instantiate plugin * values.// w ww.j av a 2 s . c o m */ static Object newInstance(String clsName, Value val, Configuration conf, ClassLoader loader, boolean fatal) { if (StringUtils.isEmpty(clsName)) return null; Class<?> cls = loadClass(clsName, findDerivedLoader(conf, loader)); if (cls == null) { cls = loadClass(clsName, findDerivedLoader(conf, null)); } if (cls == null && conf.getUserClassLoader() != null) { cls = loadClass(clsName, conf.getUserClassLoader()); } if (cls == null) { if (fatal) throw getCreateException(clsName, val, new ClassNotFoundException(clsName)); Log log = (conf == null) ? null : conf.getConfigurationLog(); if (log != null && log.isErrorEnabled()) log.error(_loc.get("plugin-creation-exception", val)); return null; } try { return AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(cls)); } catch (Exception e) { if (e instanceof PrivilegedActionException) { e = ((PrivilegedActionException) e).getException(); } RuntimeException re = new NestableRuntimeException(_loc.get("obj-create", cls).getMessage(), e); if (fatal) throw re; Log log = (conf == null) ? null : conf.getConfigurationLog(); if (log != null && log.isErrorEnabled()) log.error(_loc.get("plugin-creation-exception", val), re); return null; } }
From source file:FireWallClassLoader.java
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (negativeFilters != null) { for (int i = 0; i < negativeFilters.length; i++) { if (name.startsWith(negativeFilters[i])) { throw new ClassNotFoundException(name); }/*from www .ja va2s .c om*/ } } if (filters != null) { for (int i = 0; i < filters.length; i++) { if (name.startsWith(filters[i])) { return super.loadClass(name, resolve); } } } else { return super.loadClass(name, resolve); } throw new ClassNotFoundException(name); }
From source file:org.apache.nutch.webapp.common.PluginResourceLoader.java
public Class loadClass(String name) throws ClassNotFoundException { try {/*from w ww. ja v a2 s . c o m*/ // LOG.info("CUSTOM_LOADER->load"); Iterator i = classloaders.iterator(); Class retVal = null; while (i.hasNext()) { ClassLoader loader = (ClassLoader) i.next(); // LOG.info("trying to load " + name + " from:" + loader); try { retVal = loader.loadClass(name); } catch (Exception e) { LOG.info("Exception in loader " + e); } if (retVal != null) { // LOG.info("CUSTOM_LOADER->found"); return retVal; } } // LOG.info("CUSTOM_LOADER_not found"); } catch (Exception e) { LOG.info("Exception in loader " + e); e.printStackTrace(LogUtil.getInfoStream(LOG)); } throw new ClassNotFoundException(name); }
From source file:org.apache.river.container.classloading.VirtualFileSystemClassLoader.java
@Override protected Class<?> findClass(final String name) throws ClassNotFoundException { try {//from ww w.j av a 2s .co m return (Class) Security.doPrivileged(new PrivilegedExceptionAction<Class>() { public Class run() throws ClassNotFoundException { String resourceName = classToResourceName(name); FileObject resourceFileObject = findResourceFileObject(resourceName); if (resourceFileObject == null) { throw new ClassNotFoundException(name + "(" + resourceName + ")"); } try { byte[] bytes = FileUtil.getContent(resourceFileObject); return defineClass(name, bytes, 0, bytes.length); } catch (IOException ioe) { throw new ClassNotFoundException(name, ioe); } } }); } catch (PrivilegedActionException ex) { throw (ClassNotFoundException) ex.getException(); } }
From source file:io.neba.core.logviewer.LogfileViewerConsolePluginTest.java
@Test @SuppressWarnings("unchecked") public void testLogViewerToleratesMissingDecoratedObjectFactoryFactory() throws Exception { ClassLoader classLoaderWithoutDecoratedObjectFactory = new ClassLoader(getClass().getClassLoader()) { @Override/*from w ww. jav a 2s .c o m*/ public Class<?> loadClass(String name) throws ClassNotFoundException { if (DecoratedObjectFactory.class.getName().equals(name)) { // This optional dependency is not present on the class path in this test scenario. throw new ClassNotFoundException("THIS IS AN EXPECTED TEST EXCEPTION. The presence of " + DecoratedObjectFactory.class.getName() + " is optional."); } if (LogfileViewerConsolePlugin.class.getName().equals(name)) { // Define the test subject's class class in this class loader, thus its dependencies - // such as the DecoratedObjectFactory - are also loaded via this class loader. try { byte[] classFileData = toByteArray( getResourceAsStream(name.replace('.', '/').concat(".class"))); return defineClass(name, classFileData, 0, classFileData.length); } catch (IOException e) { throw new ClassNotFoundException("Unable to load " + name + ".", e); } } return super.loadClass(name); } }; Class<? extends Servlet> type = (Class<? extends Servlet>) classLoaderWithoutDecoratedObjectFactory .loadClass(LogfileViewerConsolePlugin.class.getName()); Servlet logViewerInstance = type.newInstance(); ServletConfig config = mock(ServletConfig.class); ServletContext context = mock(ServletContext.class); doReturn(context).when(config).getServletContext(); injectTailServlet(logViewerInstance); invokeInit(logViewerInstance, config); invokeDestroy(logViewerInstance); verify(context, never()).setAttribute(any(), any()); verify(context, never()).removeAttribute(any()); }
From source file:com.sshtools.j2ssh.util.ExtensionClassLoader.java
public Class findClass(String name) throws ClassNotFoundException { // The class object that will be returned. Class c = null;/*from www . ja v a2s .c o m*/ // Use the cached value, if this class is already loaded into // this classloader. ClassCacheEntry entry = (ClassCacheEntry) cache.get(name); if (entry != null) { if (log.isDebugEnabled()) { log.debug("Loaded " + name + " from cache"); } // Class found in our cache c = entry.loadedClass; resolveClass(c); return c; } // Try to load it from each classpath Iterator it = classpath.iterator(); // Cache entry. ClassCacheEntry classCache = new ClassCacheEntry(); while (it.hasNext()) { byte[] classData; File file = (File) it.next(); try { if (file.isDirectory()) { classData = loadClassFromDirectory(file, name, classCache); } else { classData = loadClassFromZipfile(file, name, classCache); } } catch (IOException ioe) { // Error while reading in data, consider it as not found classData = null; } if (classData != null) { // Does the package exist? String packageName = ""; if (name.lastIndexOf(".") > 0) { packageName = name.substring(0, name.lastIndexOf(".")); } if (!packageName.equals("") && !packages.containsKey(packageName)) { packages.put(packageName, definePackage(packageName, "", "", "", "", "", "", null)); // Define the class } c = defineClass(name, classData, 0, classData.length); // Cache the result; classCache.loadedClass = c; // Origin is set by the specific loader classCache.lastModified = classCache.origin.lastModified(); cache.put(name, classCache); resolveClass(c); if (log.isDebugEnabled()) { log.debug("Loaded " + name + " adding to cache and returning"); } return c; } } // If not found in any classpath throw new ClassNotFoundException(name); }