1 6 7 package org.jfox.ejb; 8 9 import java.lang.reflect.Proxy ; 10 import javax.ejb.EJBException ; 11 import javax.ejb.EJBLocalObject ; 12 import javax.ejb.EJBObject ; 13 import javax.ejb.SessionContext ; 14 import javax.transaction.Status ; 15 import javax.transaction.SystemException ; 16 import javax.transaction.UserTransaction ; 17 18 import org.jfox.ejb.connector.EJBConnectorInvoker; 19 import org.jfox.ejb.meta.SessionDescriptor; 20 import org.jfox.ioc.connector.local.LOCALConnectorRemote; 21 import org.jfox.tm.ServerUserTransaction; 22 import org.jfox.tm.TxManager; 23 24 27 28 public class SessionContextImpl extends EJBContextSupport implements SessionContext { 29 private UserTransaction ut = null; 30 31 public SessionContextImpl(EJBObjectId objectId, BucketMeta bucketMeta) { 32 super(objectId, bucketMeta); 33 } 34 35 public EJBLocalObject getEJBLocalObject() throws IllegalStateException { 36 throw new IllegalStateException ("do not need EJBLocalObject as to jfox!"); 37 } 38 39 public EJBObject getEJBObject() throws IllegalStateException { 41 ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); 42 String remoteInterfaceName = objectId.getRemoteInterfaceName(); 44 try { 45 Class remoteInterface = ctxLoader.loadClass(remoteInterfaceName); 46 return (EJBObject ) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 47 new Class []{remoteInterface}, 48 new EJBConnectorInvoker(objectId, LOCALConnectorRemote.getInstance())); 49 } 50 catch(Exception e) { 51 throw new EJBException (e); 52 } 53 } 54 55 public UserTransaction getUserTransaction() throws IllegalStateException { 56 if(ut == null) { 57 if(!((SessionDescriptor) bucketMeta.getEJBDescriptor()).isBeanManagedTransaction()) { 58 throw new IllegalStateException ("EJBContext.getUserTransaction() not allowed for CMT beans"); 59 } 60 else { 61 ut = ServerUserTransaction.getInstance(); 62 } 63 } 64 return ut; 65 } 66 67 68 public void setRollbackOnly() throws IllegalStateException { 69 if(((SessionDescriptor) bucketMeta.getEJBDescriptor()).isBeanManagedTransaction()) { 70 throw new IllegalStateException ("EJBContext.setRollbackOnly() not allowed for BMT beans."); 71 } 72 73 try { 74 TxManager.getInstance().setRollbackOnly(); 75 } 76 catch(IllegalStateException e) { 77 logger.warn(e.getMessage(), e); 78 } 79 catch(SystemException e) { 80 logger.warn("failed to set rollback only", e); 81 } 82 } 83 84 public boolean getRollbackOnly() throws IllegalStateException { 85 if(((SessionDescriptor) bucketMeta.getEJBDescriptor()).isBeanManagedTransaction()) { 86 throw new IllegalStateException ("EJBContext.setRollbackOnly() not allowed for BMT beans."); 87 } 88 try { 89 return TxManager.getInstance().getStatus() == Status.STATUS_MARKED_ROLLBACK; 90 } 91 catch(SystemException e) { 92 logger.warn("failed to set get tx manager status", e); 93 return true; 94 } 95 } 96 97 public javax.xml.rpc.handler.MessageContext getMessageContext() throws IllegalStateException { 98 throw new EJBException ("not implement yet!"); 99 } 100 101 } 102 | Popular Tags |