List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.nebulaframework.deployment.classloading.GridArchiveClassLoader.java
/** * {@inheritDoc}/* www . ja va 2 s . c o m*/ * @throws ClassNotFoundException if class is not found * @throws SecurityException if class is not accessible due to security reasons */ @Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException, SecurityException { // Check if the class is Prohibited to be accessed // (throws SecurityException in such cases) checkProhibited(name); try { // Delegate to Super Class // (which will call findClass) return super.loadClass(name, resolve); } catch (ClassNotFoundException e) { // Ignore : Super class cannot find if (log.isDebugEnabled()) { log.debug("GridArchiveClassLoader unable to load class " + name); } } // If not found by super class or by GridArchive loading // Note that we do not rely on java.lang.ClassLoader to invoke // parent class loader. if (parent != null) { // Delegate to parent ClassLoader return parent.loadClass(name); } else { throw new ClassNotFoundException("Unable to find class " + name); } }
From source file:com.sshtools.j2ssh.configuration.ConfigurationLoader.java
/** * * * @param name// ww w .jav a 2 s.c o m * * @return * * @throws ClassNotFoundException * @throws ConfigurationException */ public static Class getExtensionClass(String name) throws ClassNotFoundException, ConfigurationException { if (!initialized) { initialize(false); } if (ext == null) { throw new ClassNotFoundException("Configuration not initialized"); } return ext.loadClass(name); }
From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java
@Override protected Class<?> findClass(final String name) throws ClassNotFoundException { try {/* www. j a v a 2s . c o m*/ return (Class) Security.doPrivileged(new PrivilegedExceptionAction<Class>() { public Class run() throws ClassNotFoundException { String resourceName = classToResourceName(name); FileObject resourceFileObject = findResourceFileObject(resourceName); if (resourceFileObject == null) { if (log.isLoggable(Level.FINE)) { log.fine(getDebugName() + " was asked for " + resourceName + " but couldn't find it."); } throw new ClassNotFoundException(name + "(" + resourceName + ")"); } try { byte[] bytes = FileUtil.getContent(resourceFileObject); return defineClass(name, bytes, 0, bytes.length); } catch (IOException ioe) { if (log.isLoggable(Level.FINE)) { log.fine(getDebugName() + " was asked for " + resourceName + " but got IOException while loading it."); } throw new ClassNotFoundException(name, ioe); } } }); } catch (PrivilegedActionException ex) { throw (ClassNotFoundException) ex.getException(); } }
From source file:FileErrorManager.java
/** * Wraps the given stream as a NewLineOutputStream. * * @param out the stream to wrap./*from w w w . j a va 2 s . c o m*/ * @return the original or wrapped output stream. */ @SuppressWarnings("UseSpecificCatch") private OutputStream wrap(OutputStream out) { assert out != null; Class<?> k; try { k = Class.forName("NewlineOutputStream"); if (OutputStream.class.isAssignableFrom(k)) { Constructor<?> c = k.getConstructor(OutputStream.class); return (OutputStream) c.newInstance(out); } else { super.error("Unable to switch newlines", new ClassNotFoundException(k.getName()), ErrorManager.GENERIC_FAILURE); } } catch (RuntimeException re) { super.error("Unable to switch newlines", re, ErrorManager.GENERIC_FAILURE); } catch (Exception ex) { super.error("Unable to switch newlines", ex, ErrorManager.GENERIC_FAILURE); } catch (LinkageError le) { super.error("Unable to switch newlines", new ClassNotFoundException("", le), ErrorManager.GENERIC_FAILURE); } return out; }
From source file:org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.java
public Class<?> loadClass(String className) throws ClassNotFoundException { Class<?> clazz = null;/* ww w .j a v a 2 s. c o m*/ try { if (JavaPrimitive.isPrimitive(className)) { clazz = JavaPrimitive.forName(className); } else { clazz = this.classLoader.loadClass(className); } } catch (ClassNotFoundException e) { throw e; } catch (Throwable e) { log.error(e.getLocalizedMessage(), e); } if (null == clazz) { throw new ClassNotFoundException(className); } return clazz; }
From source file:org.seamless_ip.services.dao.IndicatorValueDaoImpl.java
@SuppressWarnings("unchecked") private IIndicatorValueTO createTO(Object dbItem) throws ClassNotFoundException { if (dbItem == null) return null; if (dbItem instanceof IndicatorValueBetweenCountryAggregates) return createTO((IndicatorValueBetweenCountryAggregates) dbItem); if (dbItem instanceof IndicatorValueActivity) return createTO((IndicatorValueActivity) dbItem); if (dbItem instanceof IndicatorValueActivityGroupCountry) return createTO((IndicatorValueActivityGroupCountry) dbItem); if (dbItem instanceof IndicatorValueActivityGroupCountryAggregate) return createTO((IndicatorValueActivityGroupCountryAggregate) dbItem); if (dbItem instanceof IndicatorValueActivityGroupNUTSRegion) return createTO((IndicatorValueActivityGroupNUTSRegion) dbItem); if (dbItem instanceof IndicatorValueCountry) return createTO((IndicatorValueCountry) dbItem); if (dbItem instanceof IndicatorValueCountryAggregate) return createTO((IndicatorValueCountryAggregate) dbItem); if (dbItem instanceof IndicatorValueCrop) return createTO((IndicatorValueCrop) dbItem); if (dbItem instanceof IndicatorValueFarm) return createTO((IndicatorValueFarm) dbItem); if (dbItem instanceof IndicatorValueFarmAgriEnvironmentalZone) return createTO((IndicatorValueFarmAgriEnvironmentalZone) dbItem); if (dbItem instanceof IndicatorValueNUTSRegion) return createTO((IndicatorValueNUTSRegion) dbItem); if (dbItem instanceof IndicatorValueInputGroupCountry) return createTO((IndicatorValueInputGroupCountry) dbItem); if (dbItem instanceof IndicatorValueInputGroupCountryAggregate) return createTO((IndicatorValueInputGroupCountryAggregate) dbItem); if (dbItem instanceof IndicatorValueInputGroupNUTSRegion) return createTO((IndicatorValueInputGroupNUTSRegion) dbItem); if (dbItem instanceof IndicatorValueProductGroupCountry) return createTO((IndicatorValueProductGroupCountry) dbItem); if (dbItem instanceof IndicatorValueProductGroupCountryAggregate) return createTO((IndicatorValueProductGroupCountryAggregate) dbItem); if (dbItem instanceof IndicatorValueProductGroupNUTSRegion) return createTO((IndicatorValueProductGroupNUTSRegion) dbItem); throw new ClassNotFoundException( dbItem.getClass().getName() + " is not a recognized indicator value class!"); }
From source file:org.apache.axis2.description.ParameterIncludeImpl.java
/** * Restore the contents of the object that was previously saved. * <p/>/*w w w . ja v a 2 s . c om*/ * NOTE: The field data must read back in the same order and type * as it was written. Some data will need to be validated when * resurrected. * * @param in The stream to read the object contents from * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput inObject) throws IOException, ClassNotFoundException { SafeObjectInputStream in = SafeObjectInputStream.install(inObject); // trace point if (log.isTraceEnabled()) { log.trace( myClassName + ":readExternal(): BEGIN bytes available in stream [" + in.available() + "] "); } // serialization version ID long suid = in.readLong(); // revision ID int revID = in.readInt(); // make sure the object data is in a version we can handle if (suid != serialVersionUID) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_SUID); } // make sure the object data is in a revision level we can handle if (revID != REVISION_2) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_REVID); } //--------------------------------------------------------- // collection of parameters //--------------------------------------------------------- in.readMap(parameters); //--------------------------------------------------------- // done //--------------------------------------------------------- }
From source file:SearchlistClassLoader.java
/** * Return the local class instance for <i>name</i>. * *<br>This does <i>not</i> search the searchlist. Only classes loaded * directly by this loader or its parent are returned. * *<br>This method can be used to retrieve the <i>canonical</i> instance * of a class.//from ww w. ja v a 2 s. co m * If this method is called on a set of SearchlistClassLoaders, then * the only classloader which will return the class is the one which * originally loaded it (assuming no duplicates have been created yet). * * @param name the fully-qualified name of the class * @return the loaded class. * * @throws ClassNotFoundException if the class is not found. */ public Class loadLocalClass(String name) throws ClassNotFoundException { ClassNotFoundException err = null; if (getParent() != null) { try { return getParent().loadClass(name); } catch (ClassNotFoundException e) { err = e; } } if (content != null) { // try the cache first Class result = (cache != null ? (Class) cache.get(name) : null); if (result != null) return result; // try loading the class data byte[] data = loadClassData(content.loader, name); if (data != null) { // define the class result = defineClass(name, data, 0, data.length); if (result != null) { //System.out.println("defined class: " + name); // cache the result if (cache == null) cache = new Hashtable(1024); cache.put(name, result); return result; } } } throw (err != null ? err : new ClassNotFoundException(name)); }
From source file:org.apache.axis2.classloader.MultiParentClassLoader.java
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { ////from w w w. j ava2 s . c om // Check if class is in the loaded classes cache // Class cachedClass = findLoadedClass(name); if (cachedClass != null) { return resolveClass(cachedClass, resolve); } // // if we are using inverse class loading, check local urls first // if (inverseClassLoading && !isDestroyed() && !isNonOverridableClass(name)) { try { Class clazz = findClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { } } // // Check parent class loaders // if (!isHiddenClass(name)) { for (int i = 0; i < parents.length; i++) { ClassLoader parent = parents[i]; try { Class clazz = parent.loadClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { // this parent didn't have the class; try the next one // TODO REVIEW FOR JAVA 6 // In Java 5, if you passed an array string such as "[Lcom.mypackage.MyClass;" to // loadClass, the class would indeed be loaded. // In JDK6, a ClassNotFoundException is thrown. // The work-around is to use code Class.forName instead. // Example: // try { // classLoader.loadClass(name); // } catch (ClassNotFoundException e) { // Class.forName(name, false, loader); // } } } } // // if we are not using inverse class loading, check local urls now // // don't worry about excluding non-overridable classes here... we // have alredy checked he parent and the parent didn't have the // class, so we can override now if (!isDestroyed()) { try { Class clazz = findClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { } } throw new ClassNotFoundException(name); }
From source file:com.googlecode.janrain4j.conf.PropertyConfigTest.java
@Test public void testPropertyConfigWithoutSpring() throws Exception { Log log = mock(Log.class); mockStatic(LogFactory.class); when(LogFactory.getLog(PropertyConfig.class)).thenReturn(log); ClassNotFoundException cnfe = new ClassNotFoundException("org.springframework.util.SystemPropertyUtils"); mockStatic(Class.class); when(Class.forName("org.springframework.util.SystemPropertyUtils")).thenThrow(cnfe); ServletContext servletContext = mock(ServletContext.class); // create config config = new PropertyConfig(servletContext, "janrain4j.properties"); verifyStatic();/*from w w w . java2s .c om*/ Class.forName("org.springframework.util.SystemPropertyUtils"); verify(log).debug("Trying to load janrain4j properties using Springframework classes..."); verify(log).debug( "Unable to load janrain4j properties file using Springframework classes, falling back to normal properties loading", cnfe); assertEquals("my-config-api-key", config.getApiKey()); assertEquals("my-config-application-id", config.getApplicationID()); assertEquals("http://my-config-application-domain.com", config.getApplicationDomain()); assertEquals("http://my-config-token-url.com", config.getTokenUrl()); assertEquals("my-config-language-preference", config.getLanguagePreference()); assertEquals("http://my-config-proxy-host.com", config.getProxyHost()); assertEquals(8080, config.getProxyPort()); assertEquals("my-config-proxy-username", config.getProxyUsername()); assertEquals("my-config-proxy-password", config.getProxyPassword()); assertEquals(30000, config.getConnectTimeout()); assertEquals(60000, config.getReadTimeout()); assertEquals(Arrays.asList("my-set-status-provider-name1", "my-set-status-provider-name2"), config.getSetStatusProviderNames()); assertEquals(Arrays.asList("my-activity-provider-name1", "my-activity-provider-name2"), config.getActivityProviderNames()); }