Example usage for java.lang.instrument ClassFileTransformer ClassFileTransformer

List of usage examples for java.lang.instrument ClassFileTransformer ClassFileTransformer

Introduction

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

Prototype

ClassFileTransformer

Source Link

Usage

From source file:org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxOsgiFrameworkTests.java

@Test
public void testAddClassFileTransformer() throws Exception {
    Bundle bundle = installSpringCore(this.framework);
    ClassLoader bundleClassLoader = this.framework.getBundleClassLoader(bundle);
    assertNotNull(bundleClassLoader);/*from w ww.  j  av  a  2s .  c  o m*/
    InstrumentableClassLoader icl = (InstrumentableClassLoader) bundleClassLoader;
    final AtomicInteger count = new AtomicInteger(0);
    icl.addClassFileTransformer(new ClassFileTransformer() {

        public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
            count.incrementAndGet();
            return null;
        }

    });
    bundle.loadClass("org.springframework.core.JdkVersion");
    assertEquals(1, count.get());
}