Example usage for java.lang ClassLoader loadClass

List of usage examples for java.lang ClassLoader loadClass

Introduction

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

Prototype

public Class<?> loadClass(String name) throws ClassNotFoundException 

Source Link

Document

Loads the class with the specified binary name.

Usage

From source file:com.jolbox.bonecp.spring.BoneCPNativeJdbcExtractor.java

/**
 * Default constructor./*  ww w  .j  a  va2 s  .  co m*/
 */
public BoneCPNativeJdbcExtractor() {
    final ClassLoader cl = getClass().getClassLoader();
    try {
        this.connectionHandleClass = cl.loadClass("com.jolbox.bonecp.ConnectionHandle");
        this.statementHandleClass = cl.loadClass("com.jolbox.bonecp.StatementHandle");
        this.getInternalConnectionMethod = this.connectionHandleClass.getMethod("getInternalConnection");
        this.getInternalStatementMethod = this.statementHandleClass.getMethod("getInternalStatement");
    } catch (Exception e) {
        throw new IllegalStateException("Failed to initialize because BoneCP API classes are not available", e);
    }
}

From source file:com.mulesoft.mql.impl.SelectEvaluator.java

private Object transformToPojo(String clsName, Map<String, Object> vars) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {/*from w ww  . j  a v  a  2  s . com*/
        Class<?> cls = cl.loadClass(clsName);
        Constructor<?> constructor;
        try {
            constructor = cls.getConstructor();
        } catch (NoSuchMethodException e) {
            throw new QueryException(
                    MessageFormat.format("Class {0} did not have an empty constructor.", clsName), e);
        }

        Object t = constructor.newInstance();
        for (Map.Entry<String, Serializable> e : compiledExpressions.entrySet()) {
            PropertyUtils.setProperty(t, e.getKey(), MVEL.executeExpression(e.getValue(), vars));
        }
        return t;
    } catch (ClassNotFoundException e1) {
        throw new QueryException(MessageFormat.format("Select class {0} was not found.", clsName), e1);
    } catch (Exception e) {
        throw new QueryException(e);
    }
}

From source file:framework.ResourceStoreClassLoader.java

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);//  w  ww .j a v 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: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 w w  w  .j a v  a2  s .c  o m

        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:net.kuujo.vertigo.io.selector.CustomSelector.java

private void init() {
    if (!initialized) {
        String className = (String) properties.get("selector");
        if (className != null) {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try {
                Class<?> clazz = loader.loadClass(className);
                selector = (Selector) SerializerFactory.getSerializer(clazz)
                        .deserializeObject(new JsonObject(properties), clazz);
            } catch (Exception e) {
                throw new IllegalArgumentException("Error instantiating serializer factory.");
            }/*from  w  w  w.j  av a  2 s  .  c  o  m*/
        } else {
            throw new IllegalStateException("Not a valid custom serializer.");
        }
    }
}

From source file:org.jsonschema2pojo.integration.PolymorphicIT.java

@Test
public void extendsWithPolymorphicDeserialization() throws ClassNotFoundException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/polymorphic/extendsSchema.json",
            "com.example");

    Class<?> subtype = resultsClassLoader.loadClass("com.example.ExtendsSchema");
    Class<?> supertype = subtype.getSuperclass();

    assertNotNull(supertype.getAnnotation(JsonTypeInfo.class));

}

From source file:com.googlecode.psiprobe.tools.logging.jdk.Jdk14ManagerAccessor.java

public Jdk14ManagerAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException {
    Class clazz = cl.loadClass("java.util.logging.LogManager");
    Method getManager = MethodUtils.getAccessibleMethod(clazz, "getLogManager", new Class[] {});
    Object manager = getManager.invoke(null, null);
    if (manager == null) {
        throw new NullPointerException(clazz.getName() + ".getLogManager() returned null");
    }//from  ww  w .j a v  a  2s .  c  om
    setTarget(manager);
}

From source file:com.vaadin.server.AbstractClientConnectorTest.java

private WeakReference<Class<?>> loadClass(String name) throws ClassNotFoundException {
    ClassLoader loader = new TestClassLoader();
    Class<?> loaded = loader.loadClass(name);
    return new WeakReference<>(loaded);
}

From source file:com.inetpsa.seed.plugin.CmdMojoDelegate.java

@Override
@SuppressWarnings("unchecked")
public String call() throws Exception {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    Class<?> nuunCoreClass = contextClassLoader.loadClass("io.nuun.kernel.core.NuunCore");
    Class<?> kernelConfigurationClass = contextClassLoader
            .loadClass("io.nuun.kernel.api.config.KernelConfiguration");
    Class<?> injectorClass = contextClassLoader.loadClass("com.google.inject.Injector");

    Object kernelConfiguration = nuunCoreClass.getMethod("newKernelConfiguration").invoke(null);
    Kernel kernel = (Kernel) nuunCoreClass.getMethod("createKernel", kernelConfigurationClass).invoke(null,
            kernelConfiguration);//from ww  w  . j a  v a2s .  c o m

    try {
        kernel.init();
        kernel.start();

        Object injector = kernel.objectGraph().as(injectorClass);
        CommandRegistry commandRegistry = (CommandRegistry) injectorClass.getMethod("getInstance", Class.class)
                .invoke(injector, CommandRegistry.class);
        Command command = createCommand(commandRegistry, "help", new String[] {});

        if (command instanceof PrettyCommand) {
            return ((PrettyCommand) command).prettify(command.execute(null));
        } else {
            return String.valueOf(command.execute(null));
        }
    } finally {
        kernel.stop();
    }
}

From source file:org.jsonschema2pojo.integration.config.PrefixSuffixIT.java

@Test
public void defaultClassPrefix() throws ClassNotFoundException {

    ClassLoader resultsClassLoader = generateAndCompile("/schema/properties/primitiveProperties.json",
            "com.example");
    resultsClassLoader.loadClass("com.example.PrimitiveProperties");
}