001 package railo.runtime.instrumentation; 002 003 import java.lang.instrument.ClassDefinition; 004 import java.lang.instrument.Instrumentation; 005 import java.lang.instrument.UnmodifiableClassException; 006 007 public class InstrumentationUtil { 008 009 /** 010 * redefine the class with the given byte array 011 * @param clazz 012 * @param barr 013 * @return 014 */ 015 public static boolean redefineClassEL(Class clazz, byte[] barr){ 016 Instrumentation inst = InstrumentationFactory.getInstance(); 017 if(inst!=null && inst.isRedefineClassesSupported()) { 018 try { 019 inst.redefineClasses(new ClassDefinition(clazz,barr)); 020 return true; 021 } 022 catch (Throwable t) {t.printStackTrace();} 023 } 024 return false; 025 } 026 027 public static void redefineClass(Class clazz, byte[] barr) throws ClassNotFoundException, UnmodifiableClassException{ 028 Instrumentation inst = InstrumentationFactory.getInstance(); 029 inst.redefineClasses(new ClassDefinition(clazz,barr)); 030 } 031 032 public static boolean isSupported() { 033 Instrumentation inst = InstrumentationFactory.getInstance(); 034 return (inst!=null && inst.isRedefineClassesSupported()); 035 } 036 }