1 23 24 package com.rift.coad.lib.bean; 26 27 import java.lang.reflect.Proxy ; 29 import java.lang.reflect.Constructor ; 30 31 import org.apache.log4j.Logger; 33 34 import com.rift.coad.lib.deployment.DeploymentLoader; 36 import com.rift.coad.lib.deployment.BeanInfo; 37 import com.rift.coad.lib.security.ThreadsPermissionContainer; 38 39 44 public class BeanWrapper { 45 46 protected Logger log = 48 Logger.getLogger(BeanWrapper.class.getName()); 49 50 private DeploymentLoader loader = null; 52 private ThreadsPermissionContainer permissions = null; 53 private String bindName = null; 54 private BeanHandler handler = null; 55 private Object proxy = null; 56 private java.rmi.Remote tie = null; 57 private Object subObject = null; 58 private Class interfaceRef = null; 59 60 61 68 public BeanWrapper(DeploymentLoader deploymentLoader, BeanInfo beanInfo, 69 ThreadsPermissionContainer permissions) 70 throws BeanException { 71 try { 72 this.loader = deploymentLoader; 73 this.permissions = permissions; 74 bindName = beanInfo.getBindName(); 75 subObject = deploymentLoader.getClassLoader(). 76 loadClass(beanInfo.getClassName()).newInstance(); 77 interfaceRef = deploymentLoader.getClassLoader(). 78 loadClass(beanInfo.getInterfaceName()); 79 handler = new BeanHandler(beanInfo, subObject, 80 beanInfo.getRole(),permissions, 81 deploymentLoader.getClassLoader()); 82 proxy = (Object )Proxy.newProxyInstance( 83 deploymentLoader.getClassLoader(), 84 new Class [] {deploymentLoader.getClass( 85 beanInfo.getInterfaceName())},handler); 86 tie = loadTie(beanInfo, subObject); 87 } catch (Exception ex) { 88 log.error("Failed to instanciate the bean wrapper : " 89 + ex.getMessage(),ex); 90 throw new BeanException("Failed to instanciate the bean wrapper : " 91 + ex.getMessage(), ex); 92 } 93 } 94 95 96 102 public String getBindName() { 103 return bindName; 104 } 105 106 107 112 public Object getProxy() { 113 return proxy; 114 } 115 116 117 122 public java.rmi.Remote getTie() { 123 return tie; 124 } 125 126 127 132 public Object getSubObject() { 133 return subObject; 134 } 135 136 137 142 public Class getInterface() { 143 return interfaceRef; 144 } 145 146 147 155 private java.rmi.Remote loadTie(BeanInfo beanInfo, Object subObject) 156 throws BeanException { 157 if (!(subObject instanceof java.rmi.Remote )) { 158 return null; 159 } 160 String className = subObject.getClass().getName() + 161 BeanPattern.TIE_SUFFIX; 162 try { 163 Class classRef = loader.getClassLoader().loadClass(className); 164 Class [] parameterTypes = new Class [] { 167 ClassLoader .class, 168 subObject.getClass(), String .class, 169 ThreadsPermissionContainer.class, 170 BeanInfo.class}; 171 Constructor constructor = classRef.getConstructor(parameterTypes); 172 return (java.rmi.Remote )constructor.newInstance( 173 loader.getClassLoader(),subObject,beanInfo.getRole(), 174 permissions,beanInfo); 175 } catch (Exception ex) { 176 throw new BeanException("Failed to load the class [" + className 177 + "] because : " + ex.getMessage(),ex); 178 } 179 } 180 } 181 | Popular Tags |