1 16 17 package org.springframework.instrument.classloading; 18 19 import java.lang.instrument.ClassFileTransformer ; 20 import java.lang.instrument.Instrumentation ; 21 22 import org.springframework.instrument.InstrumentationSavingAgent; 23 import org.springframework.util.Assert; 24 import org.springframework.util.ClassUtils; 25 26 45 public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { 46 47 public void addTransformer(ClassFileTransformer transformer) { 48 Assert.notNull(transformer, "Transformer must not be null"); 49 Instrumentation instrumentation = InstrumentationSavingAgent.getInstrumentation(); 50 if (instrumentation == null) { 51 throw new IllegalStateException ( 52 "Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation."); 53 } 54 instrumentation.addTransformer(transformer); 55 } 56 57 62 public ClassLoader getInstrumentableClassLoader() { 63 return ClassUtils.getDefaultClassLoader(); 64 } 65 66 70 public ClassLoader getThrowawayClassLoader() { 71 return new SimpleThrowawayClassLoader(getInstrumentableClassLoader()); 72 } 73 74 } 75 | Popular Tags |