1 45 package org.openejb.client.proxy; 46 47 import java.util.Properties ; 48 49 50 55 public class ProxyManager { 56 57 58 private static ProxyFactory defaultFactory; 62 private static String defaultFactoryName; 63 64 static { 65 String version = null; 66 Class factory = null; 67 try { 68 version = System.getProperty("java.vm.version"); 69 } catch ( Exception e ) { 70 throw new RuntimeException ("Unable to determine the version of your VM. No ProxyFactory Can be installed"); 72 } 73 ClassLoader cl = getContextClassLoader(); 74 75 if ( version.startsWith("1.1") ) { 76 throw new RuntimeException ("This VM version is not supported: "+version); 77 } else if ( version.startsWith("1.2") ) { 78 defaultFactoryName = "JDK 1.2 ProxyFactory"; 79 80 try { 81 Class.forName("org.opentools.proxies.Proxy", true, cl); 82 } catch ( Exception e ) { 83 throw new RuntimeException ("No ProxyFactory Can be installed. Unable to load the class org.opentools.proxies.Proxy. This class is needed for generating proxies in JDK 1.2 VMs."); 85 } 86 87 try { 88 factory = Class.forName("org.openejb.client.proxy.Jdk12ProxyFactory", true, cl); 89 } catch ( Exception e ) { 90 throw new RuntimeException ("No ProxyFactory Can be installed. Unable to load the class org.openejb.client.proxy.Jdk12ProxyFactory."); 92 } 93 } else { 94 defaultFactoryName = "JDK 1.3 ProxyFactory"; 95 96 try { 97 factory = Class.forName("org.openejb.client.proxy.Jdk13ProxyFactory", true, cl); 98 } catch ( Exception e ) { 99 throw new RuntimeException ("No ProxyFactory Can be installed. Unable to load the class org.openejb.client.proxy.Jdk13ProxyFactory."); 101 } 102 } 103 104 try { 105 106 defaultFactory = (ProxyFactory)factory.newInstance(); 107 defaultFactory.init( new Properties () ); 108 109 } catch ( Exception e ) { 110 throw new RuntimeException ("No ProxyFactory Can be installed. Unable to load the class org.openejb.client.proxy.Jdk13ProxyFactory."); 112 } 113 114 } 115 116 public static ProxyFactory getDefaultFactory() { 117 return defaultFactory; 118 } 119 120 public static String getDefaultFactoryName() { 121 return defaultFactoryName; 122 } 123 132 public static InvocationHandler getInvocationHandler(Object proxy) { 133 return defaultFactory.getInvocationHandler(proxy); 134 } 135 136 143 public static Object setInvocationHandler(Object proxy, InvocationHandler handler) { 144 return defaultFactory.setInvocationHandler(proxy, handler); 145 } 146 147 154 public static Class getProxyClass(Class interfaceType) throws IllegalAccessException { 155 return getProxyClass(new Class []{interfaceType}); 156 } 157 158 public static Class getProxyClass(Class [] interfaces) throws IllegalAccessException { 159 return defaultFactory.getProxyClass( interfaces); 160 } 161 162 173 public static Object newProxyInstance(Class interfaceType, InvocationHandler h) throws IllegalAccessException { 174 return newProxyInstance(new Class []{interfaceType}, h); 175 } 176 177 public static Object newProxyInstance(Class [] interfaces, InvocationHandler h) throws IllegalAccessException { 178 return defaultFactory.newProxyInstance(interfaces, h); 179 } 180 181 186 public static boolean isProxyClass(Class cl) { 187 return defaultFactory.isProxyClass(cl); 188 } 189 190 193 public static Object newProxyInstance(Class proxyClass) throws IllegalAccessException { 194 return defaultFactory.newProxyInstance(proxyClass); 195 } 196 200 public static ClassLoader getContextClassLoader() { 201 return (ClassLoader ) java.security.AccessController.doPrivileged( 202 new java.security.PrivilegedAction () { 203 public Object run() { 204 return Thread.currentThread().getContextClassLoader(); 205 } 206 } 207 ); 208 } 209 } 210 | Popular Tags |