Java 类org.springframework.core.OverridingClassLoader 实例源码

项目:spring4-understanding    文件:CachedIntrospectionResultsTests.java   
@Test
public void acceptAndClearClassLoader() throws Exception {
    BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
    assertTrue(bw.isWritableProperty("name"));
    assertTrue(bw.isWritableProperty("age"));
    assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));

    ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
    Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
    assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
    CachedIntrospectionResults.acceptClassLoader(child);
    bw = new BeanWrapperImpl(tbClass);
    assertTrue(bw.isWritableProperty("name"));
    assertTrue(bw.isWritableProperty("age"));
    assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
    CachedIntrospectionResults.clearClassLoader(child);
    assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));

    assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
}
项目:class-guard    文件:CachedIntrospectionResultsTests.java   
@Test
public void acceptAndClearClassLoader() throws Exception {
    BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
    assertTrue(bw.isWritableProperty("name"));
    assertTrue(bw.isWritableProperty("age"));
    assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class));

    ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
    Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
    assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass));
    CachedIntrospectionResults.acceptClassLoader(child);
    bw = new BeanWrapperImpl(tbClass);
    assertTrue(bw.isWritableProperty("name"));
    assertTrue(bw.isWritableProperty("age"));
    assertTrue(CachedIntrospectionResults.classCache.containsKey(tbClass));
    CachedIntrospectionResults.clearClassLoader(child);
    assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass));

    assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class));
}
项目:spring    文件:ReflectiveLoadTimeWeaver.java   
@Override
public ClassLoader getThrowawayClassLoader() {
    if (this.getThrowawayClassLoaderMethod != null) {
        ClassLoader target = (ClassLoader)
                ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader);
        return (target instanceof DecoratingClassLoader ? target :
                new OverridingClassLoader(this.classLoader, target));
    }
    else {
        return new SimpleThrowawayClassLoader(this.classLoader);
    }
}
项目:spring    文件:WebLogicLoadTimeWeaver.java   
@Override
public ClassLoader getThrowawayClassLoader() {
    return new OverridingClassLoader(this.classLoader.getClassLoader(),
            this.classLoader.getThrowawayClassLoader());
}
项目:spring    文件:WebSphereLoadTimeWeaver.java   
@Override
public ClassLoader getThrowawayClassLoader() {
    return new OverridingClassLoader(this.classLoader.getClassLoader(),
            this.classLoader.getThrowawayClassLoader());
}