KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ejb > EJBContextSupport


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ejb;
8
9 import java.lang.reflect.Proxy JavaDoc;
10 import java.security.Identity JavaDoc;
11 import java.security.Principal JavaDoc;
12 import java.util.Properties JavaDoc;
13 import javax.ejb.EJBContext JavaDoc;
14 import javax.ejb.EJBException JavaDoc;
15 import javax.ejb.EJBHome JavaDoc;
16 import javax.ejb.EJBLocalHome JavaDoc;
17 import javax.ejb.TimerService JavaDoc;
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 /**
28  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
29  */

30
31 public abstract class EJBContextSupport implements EJBContext JavaDoc {
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     // use LOCALContainerInvoker & LOCALContainerService
42
public EJBHome JavaDoc getEJBHome() {
43         ClassLoader JavaDoc ctxLoader = Thread.currentThread().getContextClassLoader();
44         // get the EJBObject class name
45
String JavaDoc ejbHomeInterfaceName = objectId.getHomeInterfName();
46         try {
47             Class JavaDoc remoteInterface = ctxLoader.loadClass(ejbHomeInterfaceName);
48             return (EJBHome JavaDoc) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
49                     new Class JavaDoc[]{remoteInterface},
50 // new LOCALContainerInvoker(objectId,LOCALContainerService.getInstance()));
51
new EJBConnectorInvoker(objectId, LOCALConnectorRemote.getInstance()));
52         }
53         catch(Exception JavaDoc e) {
54             throw new EJBException JavaDoc(e);
55         }
56
57     }
58
59     public EJBLocalHome JavaDoc getEJBLocalHome() {
60         throw new IllegalStateException JavaDoc("current not support local ejb");
61     }
62
63     public Properties JavaDoc getEnvironment() {
64         throw new EJBException JavaDoc("Deprecated");
65     }
66
67     public Identity JavaDoc getCallerIdentity() {
68         throw new EJBException JavaDoc("Deprecated");
69     }
70
71     public Principal JavaDoc getCallerPrincipal() {
72         throw new IllegalStateException JavaDoc("current not support security context");
73     }
74
75     public boolean isCallerInRole(Identity JavaDoc identity) {
76         throw new EJBException JavaDoc("Deprecated");
77     }
78
79     public boolean isCallerInRole(String JavaDoc string) {
80         throw new IllegalStateException JavaDoc("current not support security context");
81     }
82
83     //TODO: implement Timer Service
84
public TimerService JavaDoc getTimerService() throws IllegalStateException JavaDoc {
85         try {
86             return ((EJBContainerImpl)Registry.getInstance().getComponentInstance(ComponentName.parseString(Container.class.getName() + "@EJB"))).getBucket(bucketMeta.getEJBDescriptor().getEjbName()).getTimerService();
87         }
88         catch(Exception JavaDoc e){
89             e.printStackTrace();
90             return null;
91         }
92     }
93
94 }
95
Popular Tags