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:org.ebayopensource.turmeric.tools.codegen.util.CodeGenClassLoader.java

public Class<?> loadClass(String className) throws ClassNotFoundException {
    Class<?> clazz = null;//  ww  w. j a  v a2 s . c  o  m
    try {
        if (startsWithPrefix(m_exclClasses, className) || startsWithPrefix(m_exclPackagePrefixes, className)) {
            // we need to load those classes parent class loader
            // by delegation.
            clazz = super.loadClass(className);
        } else if (startsWithPrefix(m_inclPackagePrefixes, className)) {
            // we need to load those classes in this class loader
            // without delegation.
            clazz = findClass(className);

        } else {
            // Deletage class loading to parent classloader

            clazz = super.loadClass(className);
        }
    } catch (ClassNotFoundException classNotFoundException) {

    }

    if (clazz == null) {
        String msg = "Codegen Failed to resolve it, peerClassLoader is " + peerClassLoader
                + " and parent classLoader is " + parentClassLoader;
        throw new ClassNotFoundException(className + " \n " + msg);
    }
    return clazz;
}

From source file:com.ottogroup.bi.spqr.repository.CachedComponentClassLoader.java

/**
 * Loads referenced class:/*w  w w. ja  v a  2 s. c o  m*/
 * <ul>
 *   <li>find in already loaded classes</li>
 *   <li>look it up in previously loaded and thus cached classes</li>
 *   <li>find it in jar files</li>
 *   <li>ask parent class loader</li>
 * </ul>
 * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
 */
public Class<?> loadClass(String name) throws ClassNotFoundException {

    synchronized (getClassLoadingLock(name)) {

        //check if package exists
        String packageName = name.replaceAll(".[^.]*$", "");
        if (super.getPackage(packageName) == null) {
            //create non existing Package      
            super.definePackage(packageName, null, null, null, null, null, null, null);
        }

        // check if class has already been loaded
        Class<?> clazz = findLoadedClass(name);
        if (clazz != null)
            return clazz;

        // check internal cache for already loaded classes
        clazz = cachedClasses.get(name);
        if (clazz != null) {
            return clazz;
        }

        // check if the managed jars contain the class
        if (byteCode.containsKey(name))
            clazz = findClass(name);
        if (clazz != null) {
            return clazz;
        }

        // otherwise hand over the request to the parent class loader
        clazz = super.loadClass(name);
        //check if package exists

        if (clazz == null)
            throw new ClassNotFoundException("Class '" + name + "' not found");

        return clazz;
    }
}

From source file:com.griddynamics.banshun.StrictContextParentBean.java

private void checkClassExist(String location, String beanName, String beanClassName)
        throws ClassNotFoundException {
    try {// ww  w .  ja v a 2  s.  c  om
        Class.forName(beanClassName);
    } catch (ClassNotFoundException e) {
        throw new ClassNotFoundException(MessageFormat.format(
                "Class not found {0} in location: {1} for bean: {2}", beanClassName, location, beanName));
    }
}

From source file:com.vaadin.terminal.gwt.server.SpringApplicationOSGiServlet.java

/**
 * @return//from ww  w. j  a  va 2  s .c  o  m
 * @throws ClassNotFoundException
 */
private ApplicationContext getApplicationContext() throws ClassNotFoundException {
    BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();

    ServiceReference[] refs = null;
    try {
        refs = context.getServiceReferences(ApplicationContext.class.getName(),
                "(org.springframework.context.service.name="
                        + getSymbolicName(this.applicationParam, this.versionParam) + ")");
    } catch (InvalidSyntaxException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    ApplicationContext springContext = null;
    if (refs != null && refs.length > 0) {
        springContext = (ApplicationContext) context.getService(refs[0]);
    }

    if (springContext == null) {
        throw new ClassNotFoundException("Spring ApplicationContext has not been registered");
    }
    return springContext;
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    String path = name.replace('.', '/').concat(".class");
    ClassLoaderFile file = this.updatedFiles.getFile(path);
    if (file != null && file.getKind() == Kind.DELETED) {
        throw new ClassNotFoundException(name);
    }//from  w  w w .j a  v  a  2 s. c  om
    Class<?> loadedClass = findLoadedClass(name);
    if (loadedClass == null) {
        try {
            loadedClass = findClass(name);
        } catch (ClassNotFoundException ex) {
            loadedClass = getParent().loadClass(name);
        }
    }
    if (resolve) {
        resolveClass(loadedClass);
    }
    return loadedClass;
}

From source file:org.seamless_ip.services.dao.EnumDaoImpl.java

@SuppressWarnings("unchecked")
private EnumTO createTO(Object dbItem) throws ClassNotFoundException {
    if (dbItem == null)
        return null;
    if (dbItem instanceof SpatialScale)
        return createTO((SpatialScale) dbItem);
    if (dbItem instanceof TemporalScale)
        return createTO((TemporalScale) dbItem);
    if (dbItem instanceof Domain)
        return createTO((Domain) dbItem);
    if (dbItem instanceof Dimension)
        return createTO((Dimension) dbItem);
    if (dbItem instanceof GenericTheme)
        return createTO((GenericTheme) dbItem);
    if (dbItem instanceof Theme)
        return createTO((Theme) dbItem);
    if (dbItem instanceof Subtheme)
        return createTO((Subtheme) dbItem);
    if (dbItem instanceof Model)
        return createTO((Model) dbItem);
    if (dbItem instanceof ModelChain)
        return createTO((ModelChain) dbItem);
    if (dbItem instanceof NUTSregion)
        return createTO((NUTSregion) dbItem);

    throw new ClassNotFoundException(dbItem.getClass().getName() + " is not a recognized enumeration class!");
}

From source file:org.commoncrawl.server.DynamicClassLoader.java

@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
    Class<?> clazz = null;//from   w  w  w.j a  v  a  2 s. c  o  m

    // (0) Check our previously loaded local class cache
    clazz = findLoadedClass(name);
    if (clazz != null) {
        ServletRegistry.LOG.info("Returning Class:" + name + " from cache");
        if (resolve)
            resolveClass(clazz);
        return (clazz);
    }

    // Next, try loading the class with the system class loader, to prevent
    // the webapp from overriding J2SE classes

    boolean useSystemLoader = true;

    if (dynamicClass != null) {
        if (name.startsWith(dynamicClass)) {
            useSystemLoader = false;
            LOG.info("**********USING DYNAMIC LOAD FOR CLASS:" + name);
        }
    } else if (name.startsWith("org.commoncrawl")) {
        LOG.info("**********USING DYNAMIC LOAD FOR CLASS:" + name);
        useSystemLoader = false;
    }

    if (useSystemLoader) {
        try {
            clazz = system.loadClass(name);
            if (clazz != null) {
                if (resolve)
                    resolveClass(clazz);
                ServletRegistry.LOG.info("Loaded Class:" + name + " From System Loader");
                return (clazz);
            }
        } catch (ClassNotFoundException e) {
            // Ignore
        }
    } else {
        // (2) Search local repositories
        try {
            clazz = findClass(name);
            if (clazz != null) {
                ServletRegistry.LOG.info("Loading Class:" + name + " from local repository");
                if (resolve)
                    resolveClass(clazz);
                return (clazz);
            }
        } catch (ClassNotFoundException e) {
            ;
        }
    }

    // (3) Delegate to parent unconditionally
    ClassLoader loader = parent;
    if (loader == null)
        loader = system;
    try {
        clazz = parent.loadClass(name);
        if (clazz != null) {
            ServletRegistry.LOG.info("Loading Class:" + name + "from parent");
            if (resolve)
                resolveClass(clazz);
            return (clazz);
        }
    } catch (ClassNotFoundException e) {
        ;
    }

    ServletRegistry.LOG.info("Class:" + name + " not found");
    throw new ClassNotFoundException(name);

}

From source file:info.magnolia.content2bean.impl.Content2BeanTransformerImpl.java

/**
 * Resolves the <code>TypeDescriptor</code> from current transformation state. Resolving happens in the following
 * order://from   w  w w . j  ava 2  s  .  co m
 * <ul>
 * <li>checks the class property of the current node
 * <li>calls onResolve subclasses should override
 * <li>reflection on the parent bean
 * <li>in case of a collection/map type call getClassForCollectionProperty
 * <li>otherwise use a Map
 * </ul>
 */
@Override
public TypeDescriptor resolveType(TypeMapping typeMapping, TransformationState state,
        ComponentProvider componentProvider) throws ClassNotFoundException {
    TypeDescriptor typeDscr = null;
    Content node = state.getCurrentContent();

    try {
        if (node.hasNodeData("class")) {
            String className = node.getNodeData("class").getString();
            if (StringUtils.isBlank(className)) {
                throw new ClassNotFoundException("(no value for class property)");
            }
            Class<?> clazz = Classes.getClassFactory().forName(className);
            typeDscr = typeMapping.getTypeDescriptor(clazz);
        }
    } catch (RepositoryException e) {
        // ignore
        log.warn("can't read class property", e);
    }

    if (typeDscr == null && state.getLevel() > 1) {
        TypeDescriptor parentTypeDscr = state.getCurrentType();
        PropertyTypeDescriptor propDscr;

        if (parentTypeDscr.isMap() || parentTypeDscr.isCollection()) {
            if (state.getLevel() > 2) {
                // this is not necessarily the parent node of the current
                String mapProperyName = state.peekContent(1).getName();
                propDscr = state.peekType(1).getPropertyTypeDescriptor(mapProperyName, typeMapping);
                if (propDscr != null) {
                    typeDscr = propDscr.getCollectionEntryType();
                }
            }
        } else {
            propDscr = state.getCurrentType().getPropertyTypeDescriptor(node.getName(), typeMapping);
            if (propDscr != null) {
                typeDscr = propDscr.getType();
            }
        }
    }

    typeDscr = onResolveType(typeMapping, state, typeDscr, componentProvider);

    if (typeDscr != null) {
        // might be that the factory util defines a default implementation for interfaces
        final Class<?> type = typeDscr.getType();
        typeDscr = typeMapping.getTypeDescriptor(componentProvider.getImplementation(type));

        // now that we know the property type we should delegate to the custom transformer if any defined
        Content2BeanTransformer customTransformer = typeDscr.getTransformer();
        if (customTransformer != null && customTransformer != this) {
            TypeDescriptor typeFoundByCustomTransformer = customTransformer.resolveType(typeMapping, state,
                    componentProvider);
            // if no specific type has been provided by the
            // TODO - is this comparison working ?
            if (typeFoundByCustomTransformer != TypeMapping.MAP_TYPE) {
                // might be that the factory util defines a default implementation for interfaces
                Class<?> implementation = componentProvider
                        .getImplementation(typeFoundByCustomTransformer.getType());
                typeDscr = typeMapping.getTypeDescriptor(implementation);
            }
        }
    }

    if (typeDscr == null || typeDscr.needsDefaultMapping()) {
        if (typeDscr == null) {
            log.debug("was not able to resolve type for node [{}] will use a map", node);
        }
        typeDscr = TypeMapping.MAP_TYPE;
    }

    log.debug("{} --> {}", node.getHandle(), typeDscr.getType());

    return typeDscr;
}

From source file:org.objectweb.proactive.examples.masterworker.AbstractExample.java

/**
 * Initializing the example with command line arguments
 * @param args command line arguments//from   w  w  w  .  j a v  a  2 s .co m
 * @throws MalformedURLException
 */
protected static void init(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();

    try {
        cmd = parser.parse(command_options, args);
    } catch (ParseException e) {
        System.err.println("Parsing failed, reason, " + e.getMessage());
        System.exit(1);
    }

    // get descriptor option value
    String descPath = cmd.getOptionValue("d");

    if (descPath == null) {
        descriptor_url = AbstractExample.class.getResource(DEFAULT_DESCRIPTOR);
        if (descriptor_url == null) {
            System.err.println("Couldn't find internal ressource: " + DEFAULT_DESCRIPTOR);
            System.exit(1);
        }
    } else {
        // check provided descriptor
        File descriptorFile = new File(descPath);
        if (!descriptorFile.exists()) {
            System.err.println("" + descriptorFile + " does not exist");
            System.exit(1);
        } else if (!descriptorFile.canRead()) {
            System.err.println("" + descriptorFile + " can't be read");
            System.exit(1);
        } else if (!descriptorFile.isFile()) {
            System.err.println("" + descriptorFile + " is not a regular file");
            System.exit(1);
        }
        descriptor_url = descriptorFile.toURI().toURL();
    }

    // get vn option value
    vn_name = cmd.getOptionValue("w");

    master_vn_name = cmd.getOptionValue("m");

    schedulerURL = cmd.getOptionValue("s");

    // testing if scheduler jar is in classpath
    if (schedulerURL != null) {
        try {
            Class.forName("org.ow2.proactive.scheduler.ext.masterworker.AOSchedulerWorker");
        } catch (ClassNotFoundException e) {
            throw new ClassNotFoundException(
                    "Scheduler jars cannot be found in current classpath, they need to be added in order to run this example in the Scheduler");

        }
    }
    login = cmd.getOptionValue("l");
    password = cmd.getOptionValue("pw");
}

From source file:hotbeans.support.JarFileHotBeanModuleLoader.java

/**
 * Overridden to replace the super class implementation with an implementation that simply throws a
 * ClassNotFoundException.//from ww w .  j  av  a2  s.c  o m
 */
protected Class findClass(String name) throws ClassNotFoundException {
    // Override super class implementation with empty implementation...
    throw new ClassNotFoundException(name);
}