Example usage for java.lang ClassNotFoundException ClassNotFoundException

List of usage examples for java.lang ClassNotFoundException ClassNotFoundException

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException ClassNotFoundException.

Prototype

public ClassNotFoundException(String s) 

Source Link

Document

Constructs a ClassNotFoundException with the specified detail message.

Usage

From source file:com.simiacryptus.mindseye.lang.Layer.java

/**
 * From json nn key./*ww w.  jav a2  s.  c o m*/
 *
 * @param json the json
 * @param rs   the rs
 * @return the nn key
 */
@Nonnull
static Layer fromJson(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    JsonElement classElement = json.get("class");
    assert null != classElement : json.toString();
    final String className = classElement.getAsString();
    try {
        final Class<?> clazz = Class.forName(className);
        if (null == clazz)
            throw new ClassNotFoundException(className);
        final Method method = clazz.getMethod("fromJson", JsonObject.class, Map.class);
        if (method.getDeclaringClass() == Layer.class) {
            throw new IllegalArgumentException("Cannot find deserialization method for " + className);
        }
        @Nonnull
        Layer invoke = (Layer) method.invoke(null, json, rs);
        if (null == invoke)
            throw new IllegalStateException();
        return invoke;
    } catch (@Nonnull IllegalAccessException | InvocationTargetException | NoSuchMethodException
            | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader.java

@Override
public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    Class<?> resultClass = null;

    // Check local class caches
    resultClass = (resultClass == null ? findLoadedClass0(name) : resultClass);
    resultClass = (resultClass == null ? findLoadedClass(name) : resultClass);
    if (resultClass != null) {
        return resolveIfNecessary(resultClass, resolve);
    }/*from   w  w w .ja v  a  2s  .c  o m*/

    // Check security
    checkPackageAccess(name);

    // Perform the actual load
    boolean delegateLoad = (this.delegate || filter(name));

    if (delegateLoad) {
        resultClass = (resultClass == null ? loadFromParent(name) : resultClass);
    }
    resultClass = (resultClass == null ? findClassIgnoringNotFound(name) : resultClass);
    if (!delegateLoad) {
        resultClass = (resultClass == null ? loadFromParent(name) : resultClass);
    }

    if (resultClass == null) {
        throw new ClassNotFoundException(name);
    }

    return resolveIfNecessary(resultClass, resolve);
}

From source file:org.mrgeo.utils.ClassLoaderUtil.java

public static List<URL> getChildResources(String path) throws IOException, ClassNotFoundException {
    List<URL> result = new LinkedList<URL>();

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> p = classLoader.getResources(path);
    while (p.hasMoreElements()) {
        URL resource = p.nextElement();
        //System.out.println("resource: " + resource.toString());
        if (resource.getProtocol().equalsIgnoreCase("FILE")) {
            result.addAll(loadDirectory(resource.getFile()));
        } else if (resource.getProtocol().equalsIgnoreCase("JAR")) {
            result.addAll(loadJar(path, resource));
        } else if (resource.getProtocol().equalsIgnoreCase("VFS")) {
            result.addAll(loadVfs(resource));
        } else {//w  w w.  j  a va  2  s . c  o  m
            throw new ClassNotFoundException(
                    "Unknown protocol on class resource: " + resource.toExternalForm());
        }
    }

    return result;
}

From source file:net.ion.radon.cload.stores.ResourceStoreClassLoader.java

@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    // log.debug(getId() + " looking for: " + name);
    Class<?> clazz = findLoadedClass(name);

    if (clazz == null) {
        clazz = fastFindClass(name);//from  www.  jav  a  2  s .c om

        if (clazz == null) {

            final ClassLoader parent = getParent();
            if (parent != null) {
                clazz = parent.loadClass(name);
                // log.debug(getId() + " delegating loading to parent: " + name);
            } else {
                throw new ClassNotFoundException(name);
            }

        } else {
            log.debug(getId() + " loaded from store: " + name);
        }
    }

    if (resolve) {
        resolveClass(clazz);
    }

    return clazz;
}

From source file:org.eclipse.skalli.core.rest.RestletServlet.java

@Override
protected Class<?> loadClass(String className) throws ClassNotFoundException {
    Class<?> ret = null;//from w w w  .  j  a v a  2 s. c o  m

    // Try restlet classloader first
    if (ret == null) {
        try {
            ret = super.loadClass(className);
        } catch (ClassNotFoundException e) {
            // Ignore, because that's the whole point here...
            LOG.debug(MessageFormat.format("Class {0} not found in current bundle", className)); //$NON-NLS-1$
        }
    }

    // Next, try the current context classloader
    if (ret == null) {
        try {
            ret = Thread.currentThread().getContextClassLoader().loadClass(className);
        } catch (ClassNotFoundException e) {
            // Ignore, because that's the whole point here...
            LOG.debug(MessageFormat.format("Class {0} not found by context class loader", className)); //$NON-NLS-1$
        }
    }

    if (ret == null) {
        throw new ClassNotFoundException("Class not found: " + className); //$NON-NLS-1$
    }

    return ret;
}

From source file:Main.java

/**
 * Convert a given String into the appropriate Class.
 * /*w  ww  . j  a  v  a  2  s  . c  o  m*/
 * @param name
 *          Name of class
 * @param cl
 *          ClassLoader to use
 * 
 * @return The class for the given name
 * 
 * @throws ClassNotFoundException
 *           When the class could not be found by the specified ClassLoader
 */
private final static Class convertToJavaClass(String name, ClassLoader cl) throws ClassNotFoundException {
    int arraySize = 0;
    while (name.endsWith("[]")) {
        name = name.substring(0, name.length() - 2);
        arraySize++;
    }

    // Check for a primitive type
    Class c = (Class) PRIMITIVE_NAME_TYPE_MAP.get(name);

    if (c == null) {
        // No primitive, try to load it from the given ClassLoader
        try {
            c = cl.loadClass(name);
        } catch (ClassNotFoundException cnfe) {
            throw new ClassNotFoundException("Parameter class not found: " + name);
        }
    }

    // if we have an array get the array class
    if (arraySize > 0) {
        int[] dims = new int[arraySize];
        for (int i = 0; i < arraySize; i++) {
            dims[i] = 1;
        }
        c = Array.newInstance(c, dims).getClass();
    }

    return c;
}

From source file:com.galeoconsulting.leonardinius.api.impl.ChainingClassLoader.java

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    for (ClassLoader classloader : classLoaders) {
        try {/*from   w w  w . jav  a 2s. c  o  m*/
            Class<?> classInstance = callFindClass(classloader, name);
            if (classInstance != null) {
                return classInstance;
            }
        } catch (ClassNotFoundException e) {
            // ignoring until we reach the end of the list since we are chaining
        }
    }

    throw new ClassNotFoundException(name);
}

From source file:org.mule.module.launcher.application.CompositeApplicationClassLoader.java

@Override
protected synchronized Class<?> loadClass(String s, boolean b) throws ClassNotFoundException {
    for (ClassLoader classLoader : classLoaders) {
        try {/*from  w  ww .  j  av  a 2  s .c  om*/
            Class<?> aClass = loadClass(classLoader, s, b);
            if (logger.isDebugEnabled()) {
                logger.debug(String.format("Class '%s' loaded from classLoader '%s", s, classLoader));
            }

            return aClass;
        } catch (ClassNotFoundException e) {
            // Ignoring
        }
    }

    throw new ClassNotFoundException(String.format("Cannot load class '%s'", s));
}

From source file:org.efaps.admin.program.esjp.EFapsClassLoader.java

/**
 * @see java.lang.ClassLoader#findClass(java.lang.String)
 * @param _name name of the class//w  w w . j a v a 2  s. co  m
 * @return Class
 * @throws ClassNotFoundException if class was not found
 */
@Override
public Class<?> findClass(final String _name) throws ClassNotFoundException {
    Class<?> ret = null;
    if (this.offline) {
        throw new ClassNotFoundException(_name);
    } else {
        final byte[] b = loadClassData(_name);
        if (b != null) {
            ret = defineClass(_name, b, 0, b.length);
        } else {
            throw new ClassNotFoundException(_name);
        }
    }
    return ret;
}

From source file:eu.stratosphere.sopremo.query.PackageClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    for (final JarInfo jarInfo : this.jarInfos) {
        final Class<?> clazz = jarInfo.findClass(name);
        if (clazz != null)
            return clazz;
    }//from ww w  .  ja  v a2s.  c  om
    throw new ClassNotFoundException(name);
}