List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:com.swordlord.gozer.builder.Parser.java
/** * Helper class for getClasses and getPackageNames (using Delegation) * /* w ww .j av a2s . c o m*/ * @param pckgname * @return * @throws ClassNotFoundException */ private static File getClassesHelper(String pckgname) throws ClassNotFoundException { // Get a File object for the package File directory = null; try { ClassLoader cld = Thread.currentThread().getContextClassLoader(); if (cld == null) { throw new ClassNotFoundException("Can't get class loader."); } String path = pckgname.replace('.', '/'); URL resource = cld.getResource(path); if (resource == null) { throw new ClassNotFoundException("No resource for " + path); } directory = new File(resource.getFile()); return directory; } catch (NullPointerException x) { throw new ClassNotFoundException( pckgname + " (" + directory + ") does not appear to be a valid package"); } }
From source file:com.jaspersoft.studio.utils.jasper.JasperReportsConfiguration.java
protected void initClassloader(IFile file) { if (javaclassloader != null && classpathlistener != null) javaclassloader.removeClasspathListener(classpathlistener); try {//from w w w . jav a 2 s .co m ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (file != null) { IProject project = file.getProject(); if (project != null && project.getNature(JavaCore.NATURE_ID) != null) { javaclassloader = JavaProjectClassLoader.instance(JavaCore.create(project), cl); classpathlistener = new ClasspathListener(); javaclassloader.addClasspathListener(classpathlistener); cl = javaclassloader; } } cl = JaspersoftStudioPlugin.getDriversManager().getClassLoader(cl); cl = new CompositeClassloader(cl, this.getClass().getClassLoader()) { @Override protected URL findResource(String name) { if (name.endsWith("GroovyEvaluator.groovy")) return null; return super.findResource(name); } @Override protected Class<?> findClass(String className) throws ClassNotFoundException { if (className.endsWith("GroovyEvaluator")) throw new ClassNotFoundException(className); return super.findClass(className); } }; setClassLoader(cl); } catch (CoreException e) { e.printStackTrace(); } }
From source file:net.collegeman.phpinjava.PHP.java
/** * Create a new instance of the PHP class <code>className</code>, initialized with * arguments <code>args</code>. * @return An instance of PHPObject, wrapping the new instance of <code>className</code>. *//* w ww .j a v a 2 s. c o m*/ public PHPObject newInstance(String className, Object... args) { QuercusClass clazz = getEnv().findClass(className); if (clazz == null) throw new RuntimeException(new ClassNotFoundException("PHP:" + className)); if (args != null && args.length > 0) { Value[] values = new Value[args.length]; for (int i = 0; i < args.length; i++) values[i] = toValue(getEnv(), args[i]); return new PHPObject(getEnv(), clazz.callNew(getEnv(), values)); } else { return new PHPObject(getEnv(), clazz.callNew(getEnv(), new Value[] {})); } }
From source file:Classes.java
/** * This method acts equivalently to invoking classLoader.loadClass(className) * but it also supports primitive types and array classes of object types or * primitive types.//from w w w . j a v a2s .c om * * @param className * the qualified name of the class or the name of primitive type or * array in the same format as returned by the * java.lang.Class.getName() method. * @param classLoader * the ClassLoader used to load classes * @return the Class object for the requested className * * @throws ClassNotFoundException * when the <code>classLoader</code> can not find the requested * class */ public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { // ClassLoader.loadClass() does not handle primitive types: // // B byte // C char // D double // F float // I int // J long // S short // Z boolean // V void // if (className.length() == 1) { char type = className.charAt(0); if (type == 'B') return Byte.TYPE; if (type == 'C') return Character.TYPE; if (type == 'D') return Double.TYPE; if (type == 'F') return Float.TYPE; if (type == 'I') return Integer.TYPE; if (type == 'J') return Long.TYPE; if (type == 'S') return Short.TYPE; if (type == 'Z') return Boolean.TYPE; if (type == 'V') return Void.TYPE; // else throw... throw new ClassNotFoundException(className); } // Check for a primative type if (isPrimitive(className) == true) return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className); // Check for the internal vm format: Lclassname; if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') return classLoader.loadClass(className.substring(1, className.length() - 1)); // first try - be optimistic // this will succeed for all non-array classes and array classes that have // already been resolved // try { return classLoader.loadClass(className); } catch (ClassNotFoundException e) { // if it was non-array class then throw it if (className.charAt(0) != '[') throw e; } // we are now resolving array class for the first time // count opening braces int arrayDimension = 0; while (className.charAt(arrayDimension) == '[') arrayDimension++; // resolve component type - use recursion so that we can resolve primitive // types also Class componentType = loadClass(className.substring(arrayDimension), classLoader); // construct array class return Array.newInstance(componentType, new int[arrayDimension]).getClass(); }
From source file:org.kles.m3.M3ClassLoader.java
@Override public final Class findClass(String name) throws ClassNotFoundException { byte[] b = loadClassData(name); if (b == null) { throw new ClassNotFoundException(name); }//from w ww . java 2s. co m return defineClass(name, b, 0, b.length); }
From source file:org.spout.api.inventory.ItemStack.java
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { short matId = in.readShort(); short matData = in.readShort(); material = MaterialRegistry.get(matId); if (matData != 0 && material != null) { material = material.getSubMaterial(matData); }/* w ww .java2 s . c om*/ amount = in.readInt(); data = in.readShort(); int auxDataSize = in.readInt(); if (auxDataSize > 0) { byte[] auxData = new byte[auxDataSize]; ManagedHashMap map = new ManagedHashMap(); map.deserialize(auxData); this.auxData = map; } boolean hasNBTData = in.readBoolean(); if (hasNBTData) { NBTInputStream is = new NBTInputStream(in, false); CompoundTag tag = (CompoundTag) is.readTag(); nbtData = tag.getValue(); is.close(); } if (material == null) { throw new ClassNotFoundException("No material matching {" + matId + ", " + matData + "} was found!"); } }
From source file:org.wisdom.framework.jpa.PersistenceUnitComponent.java
/** * In this method we just create a simple temporary class loader. This class * loader uses the bundle's class loader as parent but defines the classes * in this class loader. This has the implicit assumption that the temp * class loader is used BEFORE any bundle's classes are loaded since a class * loader does parent delegation first. Sigh, guess it works most of the * time. There is however, no good alternative though in OSGi we could * actually refresh the bundle.// w w w . j a va 2 s . c o m * * @see javax.persistence.spi.PersistenceUnitInfo#getNewTempClassLoader() */ @Override public ClassLoader getNewTempClassLoader() { return new ClassLoader(getClassLoader()) { //NOSONAR /** * Searches for the .class file and define it using the current class loader. * @param className the class name * @return the class object * @throws ClassNotFoundException if the class cannot be found */ @Override protected Class findClass(String className) throws ClassNotFoundException { // Use path of class, then get the resource String path = className.replace('.', '/').concat(".class"); URL resource = getParent().getResource(path); if (resource == null) { throw new ClassNotFoundException(className + " as resource " + path + " in " + getParent()); } try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.copy(resource.openStream(), bout); byte[] buffer = bout.toByteArray(); return defineClass(className, buffer, 0, buffer.length); } catch (Exception e) { throw new ClassNotFoundException(className + " as resource" + path + " in " + getParent(), e); } } /** * Finds a resource in the bundle. * @param resource the resource * @return the url of the resource from the bundle, {@code null} if not found. */ @Override protected URL findResource(String resource) { return getParent().getResource(resource); } /** * Finds resources in the bundle. * @param resource the resource * @return the url of the resources from the bundle, empty if not found. */ @Override protected Enumeration<URL> findResources(String resource) throws IOException { return getParent().getResources(resource); } }; }
From source file:org.zaproxy.zap.control.AddOnLoader.java
@Override public Class<?> loadClass(String name) throws ClassNotFoundException { try {//w w w .ja v a 2s .c o m return loadClass(name, false); } catch (ClassNotFoundException e) { // Continue for now } for (AddOnClassLoader loader : addOnLoaders.values()) { try { return loader.loadClass(name); } catch (ClassNotFoundException e) { // Continue for now } } throw new ClassNotFoundException(name); }
From source file:org.apache.axis2.jaxws.spi.handler.BaseHandlerResolver.java
/** * Return the class for this name/* w w w .j a v a 2s .c o m*/ * * @return Class */ private static Class forName(final String className, final boolean initialize, final ClassLoader classLoader) throws ClassNotFoundException { // NOTE: This method must remain protected because it uses AccessController Class cl = null; try { cl = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { try { if (log.isDebugEnabled()) { log.debug("HandlerResolverImpl attempting to load Class: " + className); } return Class.forName(className, initialize, classLoader); } catch (Throwable e) { // TODO Should the exception be swallowed ? if (log.isDebugEnabled()) { log.debug( "HandlerResolverImpl cannot load the following class Throwable Exception Occured: " + className); } throw new ClassNotFoundException( "HandlerResolverImpl cannot load the following class Throwable Exception Occured:" + className); } } }); } catch (PrivilegedActionException e) { if (log.isDebugEnabled()) { log.debug("Exception thrown from AccessController: " + e); } throw (ClassNotFoundException) e.getException(); } return cl; }
From source file:org.kawanfw.file.servlet.ServerFileDispatch.java
/** * Analyse the throwable and build the final Exception/Throwable * @param throwable the input throwable thrown * @return the new rewritten Throwable *//* www.j a v a 2s . c o m*/ public static Throwable getFinalThrowable(Throwable throwable) { Throwable finalThrowable = null; Throwable cause = throwable.getCause(); if (cause != null && cause instanceof ClassNotFoundException || cause != null && cause instanceof NoClassDefFoundError) { finalThrowable = new ClassNotFoundException(throwable.getMessage()); } else if (cause != null && cause instanceof UnsupportedClassVersionError) { finalThrowable = new UnsupportedClassVersionError(throwable.getMessage()); } else { if (cause != null) { finalThrowable = cause; } else { finalThrowable = throwable; } } return finalThrowable; }