1 6 7 package org.jfox.ejb; 8 9 import java.lang.reflect.Proxy ; 10 import java.security.Identity ; 11 import java.security.Principal ; 12 import java.util.Properties ; 13 import javax.ejb.EJBContext ; 14 import javax.ejb.EJBException ; 15 import javax.ejb.EJBHome ; 16 import javax.ejb.EJBLocalHome ; 17 import javax.ejb.TimerService ; 18 19 import org.jfox.ejb.connector.EJBConnectorInvoker; 20 import org.jfox.ejb.connector.EJBContainerImpl; 21 import org.jfox.ioc.ComponentName; 22 import org.jfox.ioc.Registry; 23 import org.jfox.ioc.connector.Container; 24 import org.jfox.ioc.connector.local.LOCALConnectorRemote; 25 import org.jfox.ioc.logger.Logger; 26 27 30 31 public abstract class EJBContextSupport implements EJBContext { 32 protected Logger logger = Logger.getLogger(getClass().getName()); 33 protected EJBObjectId objectId = null; 34 protected BucketMeta bucketMeta = null; 35 36 public EJBContextSupport(EJBObjectId objectId, BucketMeta bucketMeta) { 37 this.objectId = objectId; 38 this.bucketMeta = bucketMeta; 39 } 40 41 public EJBHome getEJBHome() { 43 ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); 44 String ejbHomeInterfaceName = objectId.getHomeInterfName(); 46 try { 47 Class remoteInterface = ctxLoader.loadClass(ejbHomeInterfaceName); 48 return (EJBHome ) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 49 new Class []{remoteInterface}, 50 new EJBConnectorInvoker(objectId, LOCALConnectorRemote.getInstance())); 52 } 53 catch(Exception e) { 54 throw new EJBException (e); 55 } 56 57 } 58 59 public EJBLocalHome getEJBLocalHome() { 60 throw new IllegalStateException ("current not support local ejb"); 61 } 62 63 public Properties getEnvironment() { 64 throw new EJBException ("Deprecated"); 65 } 66 67 public Identity getCallerIdentity() { 68 throw new EJBException ("Deprecated"); 69 } 70 71 public Principal getCallerPrincipal() { 72 throw new IllegalStateException ("current not support security context"); 73 } 74 75 public boolean isCallerInRole(Identity identity) { 76 throw new EJBException ("Deprecated"); 77 } 78 79 public boolean isCallerInRole(String string) { 80 throw new IllegalStateException ("current not support security context"); 81 } 82 83 public TimerService getTimerService() throws IllegalStateException { 85 try { 86 return ((EJBContainerImpl)Registry.getInstance().getComponentInstance(ComponentName.parseString(Container.class.getName() + "@EJB"))).getBucket(bucketMeta.getEJBDescriptor().getEjbName()).getTimerService(); 87 } 88 catch(Exception e){ 89 e.printStackTrace(); 90 return null; 91 } 92 } 93 94 } 95 | Popular Tags |