1 16 package org.mortbay.j2ee.session; 17 18 20 import java.rmi.RemoteException ; 21 22 import org.jfox.ioc.logger.Logger; 23 24 28 34 36 public 37 class TypeCheckingInterceptor 38 extends StateInterceptor 39 { 40 protected static final Logger _log=Logger.getLogger(TypeCheckingInterceptor.class); 41 42 public Object 43 setAttribute(String name, Object value, boolean returnValue) 44 throws IllegalArgumentException , RemoteException 45 { 46 48 Object tmp=value; 49 50 if (tmp!=null) 51 { 52 56 if (tmp instanceof javax.ejb.EJBObject ) 57 tmp=new SerializableEJBObject((javax.ejb.EJBObject )tmp); 58 else if (tmp instanceof javax.ejb.EJBHome ) 59 tmp=new SerializableEJBHome((javax.ejb.EJBHome )tmp); 60 else if (tmp instanceof javax.naming.Context ) 61 tmp=new SerializableContext((javax.naming.Context )tmp); 62 else if (tmp instanceof javax.transaction.UserTransaction ) 63 tmp=new SerializableUserTransaction((javax.transaction.UserTransaction )tmp); 64 } 65 66 if (tmp instanceof java.io.Serializable ) 69 { 70 try 71 { 72 return super.setAttribute(name, tmp, returnValue); 73 } 74 catch (RemoteException e) 75 { 76 _log.error("could not set attribute", e); 77 return null; 78 } 79 } 80 else 81 { 82 throw new IllegalArgumentException ("distributed attribute value must be Serializable,EJBObject,EJBHome,UserTransaction or Context: "+tmp); 87 } 88 } 89 90 public Object 91 getAttribute(String name) 92 throws IllegalArgumentException , RemoteException 93 { 94 Object tmp=super.getAttribute(name); 95 96 if (tmp!=null) 97 { 98 if (tmp instanceof org.mortbay.j2ee.session.SerializableEJBObject) 99 return ((SerializableEJBObject)tmp).toEJBObject(); 100 else if (tmp instanceof org.mortbay.j2ee.session.SerializableEJBHome) 101 return ((SerializableEJBHome)tmp).toEJBHome(); 102 else if (tmp instanceof org.mortbay.j2ee.session.SerializableContext) 103 return ((SerializableContext)tmp).toContext(); 104 else if (tmp instanceof org.mortbay.j2ee.session.SerializableUserTransaction) 105 return ((SerializableUserTransaction)tmp).toUserTransaction(); 106 } 107 108 return tmp; 109 } 110 111 } 113 | Popular Tags |