List of usage examples for java.lang ClassLoader loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
From source file:de.micromata.genome.gwiki.plugin.CombinedClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { for (ClassLoader cl : parents) { try {/* w w w . j av a 2 s .c o m*/ Class<?> ret = cl.loadClass(name); if (ret != null) { return ret; } } catch (ClassNotFoundException cnf) { // ignore } } // the parent will do it. return super.findClass(name); }
From source file:javadz.beanutils.converters.ClassConverter.java
/** * <p>Convert the input object into a java.lang.Class.</p> * * @param type Data type to which this value should be converted. * @param value The input value to be converted. * @return The converted value.// w ww . j a v a 2 s . c o m * @throws Throwable if an error occurs converting to the specified type * @since 1.8.0 */ protected Object convertToType(Class type, Object value) throws Throwable { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { try { return (classLoader.loadClass(value.toString())); } catch (ClassNotFoundException ex) { // Don't fail, carry on and try this class's class loader // (see issue# BEANUTILS-263) } } // Try this class's class loader classLoader = ClassConverter.class.getClassLoader(); return (classLoader.loadClass(value.toString())); }
From source file:com.acciente.induction.init.RequestInterceptorInitializer.java
public static RequestInterceptor[] getRequestInterceptor(Config.RequestInterceptors oRequestInterceptorsConfig, ModelPool oModelPool, ClassLoader oClassLoader, ServletConfig oServletConfig) throws ClassNotFoundException, InvocationTargetException, ConstructorNotFoundException, ParameterProviderException, IllegalAccessException, InstantiationException { RequestInterceptor[] oRequestInterceptorArray; String sRequestInterceptorClassName; Log oLog;/*from ww w . j av a 2s. c om*/ oLog = LogFactory.getLog(RequestInterceptorInitializer.class); oRequestInterceptorArray = new RequestInterceptor[oRequestInterceptorsConfig.getRequestInterceptorList() .size()]; for (int i = 0; i < oRequestInterceptorsConfig.getRequestInterceptorList().size(); i++) { Config.RequestInterceptors.RequestInterceptor oRequestInterceptorConfig; oRequestInterceptorConfig = (Config.RequestInterceptors.RequestInterceptor) oRequestInterceptorsConfig .getRequestInterceptorList().get(i); sRequestInterceptorClassName = oRequestInterceptorConfig.getClassName(); oLog.info("loading user-defined request interceptor: " + sRequestInterceptorClassName); Class oRequestInterceptorClass = oClassLoader.loadClass(sRequestInterceptorClassName); // attempt to find and call the single public constructor oRequestInterceptorArray[i] = (RequestInterceptor) ObjectFactory.createObject(oRequestInterceptorClass, new Object[] { oServletConfig, oRequestInterceptorConfig, oClassLoader }, new InitializerParameterProvider(oModelPool, "request-interceptor-init")); } return oRequestInterceptorArray; }
From source file:org.jsonschema2pojo.integration.config.PrefixSuffixIT.java
@Test(expected = ClassNotFoundException.class) public void SuffixWithDefaultPackageName() throws ClassNotFoundException { ClassLoader resultsClassLoader = generateAndCompile("/schema/properties/primitiveProperties.json", "", config("classNameSuffix", "Dao")); resultsClassLoader.loadClass("com.example.NotExistingPrimitiveProperties"); }
From source file:com.wingnest.blueprints.impls.jpa.internal.wrappers.EntityManagerFactoryWrapper.java
public EntityManagerFactoryWrapper(String persistanceUnitName, @SuppressWarnings("rawtypes") Map props) { super();/*from w ww . j ava 2 s .c om*/ String pPersistanceUnitName = persistanceUnitName != null ? persistanceUnitName : System.getProperty("jpagraph.unit-name"); if (pPersistanceUnitName == null) { ClassLoader cl = this.getClass().getClassLoader(); try { cl.loadClass("com.objectdb.jpa.EMF"); pPersistanceUnitName = "ObjectDbUnit"; } catch (ClassNotFoundException e) { } try { cl.loadClass("org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl"); pPersistanceUnitName = "EclipseLinkUnit"; } catch (ClassNotFoundException e) { } try { cl.loadClass("org.hibernate.jpa.internal.EntityManagerFactoryImpl"); pPersistanceUnitName = "HibernateUnit"; } catch (ClassNotFoundException e) { } } if (pPersistanceUnitName == null) throw BpJpaExceptionFactory.cannotBeNull("pPersistanceUnitName"); if (pPersistanceUnitName.length() == 0) throw BpJpaExceptionFactory.cannotBeEmpty("pPersistanceUnitName"); logger.debug(String.format("persistanceUnitName = %s", pPersistanceUnitName)); try { this.entityManagerFactory = Persistence.createEntityManagerFactory(pPersistanceUnitName, props); logger.debug("EntityManagerFactory class : " + entityManagerFactory.getClass().getName()); this.damper = DamperFactory.create(this.entityManagerFactory); } catch (RuntimeException e) { logger.error(String.format("Called Persistence.createEntityManagerFactory: persistanceUnitName = '%s'", pPersistanceUnitName), e); throw e; } }
From source file:com.googlecode.jsonschema2pojo.integration.config.AnnotationStyleIT.java
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void annotationStyleJackson2ProducesJackson2Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException { File generatedOutputDirectory = generate("/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "jackson2")); assertThat(generatedOutputDirectory, not(containsText("org.codehaus.jackson"))); assertThat(generatedOutputDirectory, containsText("com.fasterxml.jackson")); ClassLoader resultsClassLoader = compile(generatedOutputDirectory); Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(notNullValue())); assertThat(generatedType.getAnnotation(JsonInclude.class), is(notNullValue())); assertThat(getter.getAnnotation(JsonProperty.class), is(notNullValue())); }
From source file:com.googlecode.jsonschema2pojo.integration.config.AnnotationStyleIT.java
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void annotationStyleJackson1ProducesJackson1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException { File generatedOutputDirectory = generate("/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "jackson1")); assertThat(generatedOutputDirectory, not(containsText("com.fasterxml.jackson"))); assertThat(generatedOutputDirectory, containsText("org.codehaus.jackson")); ClassLoader resultsClassLoader = compile(generatedOutputDirectory); Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotation(org.codehaus.jackson.annotate.JsonPropertyOrder.class), is(notNullValue()));/*from ww w .j a v a 2s. c o m*/ assertThat(generatedType.getAnnotation(org.codehaus.jackson.map.annotate.JsonSerialize.class), is(notNullValue())); assertThat(getter.getAnnotation(org.codehaus.jackson.annotate.JsonProperty.class), is(notNullValue())); }
From source file:com.googlecode.jsonschema2pojo.integration.json.RealJsonExamplesIT.java
@Test public void getUserDataProducesValidTypes() throws Exception { ClassLoader resultsClassLoader = generateAndCompile("/json/examples/GetUserData.json", "com.example", config("sourceType", "json")); Class<?> userDataType = resultsClassLoader.loadClass("com.example.GetUserData"); Object userData = OBJECT_MAPPER .readValue(this.getClass().getResourceAsStream("/json/examples/GetUserData.json"), userDataType); Object result = userDataType.getMethod("getResult").invoke(userData); Object data = result.getClass().getMethod("getData").invoke(result); Object userUIPref = data.getClass().getMethod("getUserUIPref").invoke(data); assertThat(userUIPref.getClass().getMethod("getPimColor").invoke(userUIPref).toString(), is("blue")); Object externalAccounts = data.getClass().getMethod("getExternalAccounts").invoke(data); Object extAccount = externalAccounts.getClass().getMethod("getExtAccount").invoke(externalAccounts); Object extAccount0 = ((List<?>) extAccount).get(0); assertThat(extAccount0.getClass().getMethod("getFolder").invoke(extAccount0).toString(), is("Inbox")); }
From source file:org.jsonschema2pojo.integration.config.PrefixSuffixIT.java
@Test(expected = ClassNotFoundException.class) public void PrefixWithDefaultPackageName() throws ClassNotFoundException { ClassLoader resultsClassLoader = generateAndCompile("/schema/properties/primitiveProperties.json", "", config("classNamePrefix", "Abstract")); resultsClassLoader.loadClass("com.example.NotExistingPrimitiveProperties"); }
From source file:org.jsonschema2pojo.integration.config.GsonIT.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void assertJsonRoundTrip(ClassLoader resultsClassLoader, String className, String jsonResource) throws ClassNotFoundException, IOException { Class generatedType = resultsClassLoader.loadClass(className); String expectedJson = IOUtils.toString(getClass().getResource(jsonResource)); Object javaInstance = new Gson().fromJson(expectedJson, generatedType); String actualJson = new Gson().toJson(javaInstance); assertEqualsJson(expectedJson, actualJson); }