1 23 24 28 29 package com.sun.enterprise.admin.util.proxy; 30 31 import java.lang.reflect.Proxy ; 32 33 36 public class ProxyFactory { 37 38 39 private ProxyFactory() { 40 } 41 42 public static Object createProxy(Class intfc, Object handler, 43 Interceptor interceptor) { 44 if (!intfc.isInterface()) { 45 throw new IllegalArgumentException (intfc.getClass() 46 + " is not an interface"); 47 } 48 if (!isImplementing(intfc, handler)) { 49 throw new IllegalArgumentException ("Handler object " + handler 50 + " is not an instance of " + intfc.getName()); 51 } 52 Object obj = Proxy.newProxyInstance( 53 handler.getClass().getClassLoader(), 54 new Class [] {intfc}, 55 new ProxyClass(handler, interceptor)); 56 return obj; 57 } 58 59 private static boolean isImplementing(Class intfc, Object obj) { 60 return intfc.isInstance(obj); 61 } 62 } 63 | Popular Tags |