1 45 46 47 package org.openejb.util.proxy; 48 49 import java.util.HashMap ; 50 51 52 58 public class ProxyManager { 59 60 61 private static volatile ProxyFactory defaultFactory; 65 private static final HashMap factories = new HashMap (); 66 private static volatile String defaultFactoryName; 67 68 public static synchronized ProxyFactory registerFactory(String factoryName, ProxyFactory factory){ 69 return (ProxyFactory)factories.put( factoryName, factory ); 70 } 71 72 public static synchronized ProxyFactory unregisterFactory(String factoryName){ 73 return (ProxyFactory)factories.remove( factoryName ); 74 } 75 76 public static void checkDefaultFactory(){ 77 if (defaultFactory == null) throw new IllegalStateException ("[Proxy Manager] No default proxy factory specified."); 78 } 79 80 public static ProxyFactory getFactory(String factoryName){ 81 return (ProxyFactory)factories.get(factoryName); 82 } 83 84 91 public static synchronized ProxyFactory setDefaultFactory(String factoryName){ 92 ProxyFactory newFactory = getFactory(factoryName); 93 if (newFactory == null) return defaultFactory; 94 95 ProxyFactory oldFactory = defaultFactory; 96 defaultFactory = newFactory; 97 defaultFactoryName = factoryName; 98 99 return oldFactory; 100 } 101 102 public static ProxyFactory getDefaultFactory(){ 103 return defaultFactory; 104 } 105 106 public static String getDefaultFactoryName(){ 107 return defaultFactoryName; 108 } 109 118 public static InvocationHandler getInvocationHandler(Object proxy) { 119 checkDefaultFactory(); 120 return defaultFactory.getInvocationHandler(proxy); 121 } 122 123 130 public static Object setInvocationHandler(Object proxy, InvocationHandler handler) { 131 checkDefaultFactory(); 132 return defaultFactory.setInvocationHandler(proxy, handler); 133 } 134 135 147 public static Class getProxyClass(Class interfaceType) throws IllegalAccessException { 148 return getProxyClass(new Class []{interfaceType}); 149 } 150 public static Class getProxyClass(Class [] interfaces) throws IllegalAccessException { 151 checkDefaultFactory(); 152 return defaultFactory.getProxyClass( interfaces); 153 } 154 155 166 public static Object newProxyInstance(Class interfaceType, InvocationHandler h) throws IllegalAccessException { 167 return newProxyInstance(new Class []{interfaceType}, h); 168 } 169 public static Object newProxyInstance(Class [] interfaces, InvocationHandler h) throws IllegalAccessException { 170 checkDefaultFactory(); 171 return defaultFactory.newProxyInstance(interfaces, h); 172 } 173 174 179 public static boolean isProxyClass(Class cl) { 180 checkDefaultFactory(); 181 return defaultFactory.isProxyClass(cl); 182 } 183 184 187 public static Object newProxyInstance(Class proxyClass) throws IllegalAccessException { 188 checkDefaultFactory(); 189 return defaultFactory.newProxyInstance(proxyClass); 190 } 191 } 195 | Popular Tags |