1 45 package org.openejb.core.ivm; 46 47 import java.io.ObjectStreamException ; 48 import java.lang.reflect.Method ; 49 import java.rmi.RemoteException ; 50 51 import org.openejb.RpcContainer; 52 53 62 public abstract class EjbObjectProxyHandler extends BaseEjbProxyHandler { 63 64 protected final static org.apache.log4j.Category logger = org.apache.log4j.Category.getInstance("OpenEJB"); 65 static final java.util.HashMap dispatchTable; 66 67 static { 69 dispatchTable = new java.util.HashMap (); 70 dispatchTable.put("getHandle", new Integer (1)); 71 dispatchTable.put("getPrimaryKey", new Integer (2)); 72 dispatchTable.put("isIdentical", new Integer (3)); 73 dispatchTable.put("remove", new Integer (4)); 74 dispatchTable.put("getEJBHome", new Integer (5)); 75 } 76 77 public EjbObjectProxyHandler(RpcContainer container, Object pk, Object depID){ 78 super(container, pk, depID); 79 } 80 81 94 public abstract Object getRegistryId(); 95 96 public Object _invoke(Object p, Method m, Object [] a) throws Throwable { 105 java.lang.Object retValue=null; 106 java.lang.Throwable exc=null; 107 108 try{ 109 if (logger.isInfoEnabled()) { 110 logger.info("invoking method "+m.getName()+" on "+deploymentID+" with identity "+primaryKey); 111 } 112 Integer operation = (Integer )dispatchTable.get(m.getName()); 113 114 if(operation==null) { 115 retValue = businessMethod(m,a,p); 116 }else { 117 switch(operation.intValue()) { 118 case 1: retValue = getHandle(m,a,p); break; 119 case 2: retValue = getPrimaryKey(m,a,p); break; 120 case 3: retValue = isIdentical(m,a,p); break; 121 case 4: retValue = remove(m,a,p); break; 122 case 5: retValue = getEJBHome(m,a,p); break; 123 default: 124 throw new RuntimeException ("Inconsistent internal state"); 125 } 126 } 127 143 144 if(retValue instanceof SpecialProxyInfo) 145 retValue = ((SpecialProxyInfo)retValue).getProxy(); 146 147 return retValue; 148 149 153 }catch ( org.openejb.InvalidateReferenceException ire ) { 154 invalidateAllHandlers(getRegistryId()); 155 exc = (ire.getRootCause() != null )? ire.getRootCause(): ire; 156 throw exc; 157 161 } catch ( org.openejb.ApplicationException ae ) { 162 exc = (ae.getRootCause() != null )? ae.getRootCause(): ae; 163 throw exc; 164 165 169 } catch ( org.openejb.SystemException se ) { 170 invalidateReference(); 171 exc = (se.getRootCause() != null )? se.getRootCause(): se; 172 logger.error("The container received an unexpected exception: ", exc); 173 throw new RemoteException ("Container has suffered a SystemException", exc); 174 } catch ( org.openejb.OpenEJBException oe ) { 175 exc = (oe.getRootCause() != null )? oe.getRootCause(): oe; 176 logger.warn("The container received an unexpected exception: ", exc); 177 throw new RemoteException ("Unknown Container Exception",oe.getRootCause()); 178 }finally { 179 if(logger.isDebugEnabled()) { 180 if(exc==null) { 181 logger.debug("finished invoking method "+m.getName()+". Return value:"+retValue); 182 } else { 183 logger.debug("finished invoking method "+m.getName()+" with exception "+exc); 184 } 185 } else if (logger.isInfoEnabled()) { 186 if(exc==null) { 187 logger.debug("finished invoking method "+m.getName()); 188 } else { 189 logger.debug("finished invoking method "+m.getName()+" with exception "+exc); 190 } 191 } 192 } 193 } 194 195 196 protected Object getEJBHome(Method method, Object [] args, Object proxy) throws Throwable { 197 checkAuthorization(method); 198 return deploymentInfo.getEJBHome(); 199 } 200 201 protected Object getHandle(Method method, Object [] args, Object proxy) throws Throwable { 202 checkAuthorization(method); 203 return new IntraVmHandle(proxy); 204 } 205 public org.openejb.ProxyInfo getProxyInfo(){ 206 return new org.openejb.ProxyInfo(deploymentInfo, primaryKey, isLocal(), container); 207 } 208 209 231 protected Object _writeReplace(Object proxy) throws ObjectStreamException { 232 236 if(IntraVmCopyMonitor.isIntraVmCopyOperation()){ 237 return new IntraVmArtifact( proxy ); 238 242 }else if(IntraVmCopyMonitor.isStatefulPassivationOperation()){ 243 return proxy; 244 248 } else{ 249 return org.openejb.OpenEJB.getApplicationServer().getEJBObject(this.getProxyInfo()); 250 } 251 } 252 253 protected abstract Object getPrimaryKey(Method method, Object [] args, Object proxy) throws Throwable ; 254 255 protected abstract Object isIdentical(Method method, Object [] args, Object proxy) throws Throwable ; 256 257 protected abstract Object remove(Method method, Object [] args, Object proxy) throws Throwable ; 258 259 protected Object businessMethod(Method method, Object [] args, Object proxy) throws Throwable { 260 checkAuthorization(method); 261 return container.invoke(deploymentID, method, args, primaryKey, getThreadSpecificSecurityIdentity()); 262 } 263 } 264 | Popular Tags |