Source Code Cross Referenced for ExtendEJBContext.java in  » J2EE » jfox » org » jfox » ejb3 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » jfox » org.jfox.ejb3 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JFox - The most lightweight Java EE Application Server!
003:         * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
004:         *
005:         * JFox is licenced and re-distributable under GNU LGPL.
006:         */
007:        package org.jfox.ejb3;
008:
009:        import java.rmi.RemoteException;
010:        import java.security.Identity;
011:        import java.security.Principal;
012:        import java.util.HashMap;
013:        import java.util.List;
014:        import java.util.Map;
015:        import java.util.Properties;
016:        import javax.ejb.EJBException;
017:        import javax.ejb.EJBHome;
018:        import javax.ejb.EJBLocalHome;
019:        import javax.ejb.EJBLocalObject;
020:        import javax.ejb.EJBObject;
021:        import javax.ejb.Handle;
022:        import javax.ejb.MessageDrivenContext;
023:        import javax.ejb.RemoveException;
024:        import javax.ejb.SessionContext;
025:        import javax.ejb.TimerService;
026:        import javax.naming.Context;
027:        import javax.naming.NameAlreadyBoundException;
028:        import javax.naming.NameNotFoundException;
029:        import javax.naming.NamingException;
030:        import javax.transaction.SystemException;
031:        import javax.transaction.UserTransaction;
032:        import javax.xml.rpc.handler.MessageContext;
033:
034:        import org.jfox.ejb3.naming.ContextAdapter;
035:
036:        /**
037:         * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
038:         */
039:        @SuppressWarnings({"deprecation"})
040:        public abstract class ExtendEJBContext implements  SessionContext,
041:                MessageDrivenContext, EJBObject, EJBLocalObject {
042:
043:            private EJBObjectId ejbObjectId;
044:            private Object ejbInstance;
045:
046:            /**
047:             * Component env Map, �存 java:comp/env 对象,��存 Class level 的注入
048:             * Field Level �� env �存
049:             */
050:            private Map<String, Object> envMap = new HashMap<String, Object>();
051:
052:            private ENContext envContext = new ENContext();
053:
054:            public ExtendEJBContext(EJBObjectId ejbObjectId, Object ejbInstance) {
055:                this .ejbObjectId = ejbObjectId;
056:                this .ejbInstance = ejbInstance;
057:            }
058:
059:            public Context getENContext() {
060:                return envContext;
061:            }
062:
063:            protected EJBObjectId getEJBObjectId() {
064:                return ejbObjectId;
065:            }
066:
067:            public Object getEJBInstance() {
068:                return ejbInstance;
069:            }
070:
071:            public Principal getCallerPrincipal() {
072:                EJBInvocation invocation = EJBInvocation.current();
073:                if (invocation != null) {
074:                    return invocation.getCallerGroup();
075:                } else {
076:                    return null;
077:                }
078:
079:            }
080:
081:            public EJBHome getEJBHome() {
082:                return null;
083:            }
084:
085:            public EJBLocalHome getEJBLocalHome() {
086:                return null;
087:            }
088:
089:            public UserTransaction getUserTransaction()
090:                    throws IllegalStateException {
091:                EJBInvocation invocation = EJBInvocation.current();
092:                if (invocation == null) {
093:                    throw new IllegalStateException(
094:                            "EJBContext.getUserTransactionCurrent() exception, thread not in a EJB invocation!");
095:                } else {
096:                    try {
097:                        return (UserTransaction) invocation
098:                                .getTransactionManager().getTransaction();
099:                    } catch (SystemException e) {
100:                        throw new IllegalStateException(e);
101:                    }
102:                }
103:            }
104:
105:            public boolean isCallerInRole(final String roleName) {
106:                EJBInvocation invocation = EJBInvocation.current();
107:                if (invocation == null) {
108:                    return false;
109:                }
110:                List<? extends Principal> principals = invocation
111:                        .getCallerRolesList();
112:                for (Principal p : principals) {
113:                    if (p.getName().equals(roleName)) {
114:                        return true;
115:                    }
116:                }
117:                return false;
118:            }
119:
120:            @Deprecated
121:            public Identity getCallerIdentity() {
122:                throw new UnsupportedOperationException("getCallerIdentity");
123:            }
124:
125:            @Deprecated
126:            public Properties getEnvironment() {
127:                throw new UnsupportedOperationException("getEnvironment");
128:            }
129:
130:            @Deprecated
131:            public boolean isCallerInRole(final Identity role) {
132:                throw new UnsupportedOperationException("isCallerInRole");
133:            }
134:
135:            // SessionContext
136:            public <T> T getBusinessObject(Class<T> businessInterface)
137:                    throws IllegalStateException {
138:                throw new IllegalStateException(
139:                        "Can not invoke getBusinessObject!");
140:            }
141:
142:            public EJBLocalObject getEJBLocalObject()
143:                    throws IllegalStateException {
144:                return this ;
145:            }
146:
147:            public EJBObject getEJBObject() throws IllegalStateException {
148:                return this ;
149:            }
150:
151:            public Class getInvokedBusinessInterface()
152:                    throws IllegalStateException {
153:                return EJBInvocation.current().getInterfaceMethod()
154:                        .getDeclaringClass();
155:            }
156:
157:            public MessageContext getMessageContext()
158:                    throws IllegalStateException {
159:                return null;
160:            }
161:
162:            public TimerService getTimerService() throws IllegalStateException {
163:                throw new IllegalStateException("Can not call getTimerService!");
164:            }
165:
166:            // EJBObject & EJBLocalObject
167:
168:            public Handle getHandle() throws RemoteException {
169:                return new EJBHandleImpl(getEJBObjectId());
170:            }
171:
172:            public Object getPrimaryKey() {
173:                return getEJBObjectId();
174:            }
175:
176:            public boolean isIdentical(EJBObject obj) throws RemoteException {
177:                return obj.getPrimaryKey().equals(getPrimaryKey());
178:            }
179:
180:            public void remove() throws RemoveException {
181:                throw new RemoveException("Can not invoke remove()!");
182:            }
183:
184:            public boolean isIdentical(EJBLocalObject obj) throws EJBException {
185:                return obj.getPrimaryKey().equals(getPrimaryKey());
186:            }
187:
188:            public boolean equals(Object obj) {
189:                if (obj == null || !(obj instanceof  EJBObjectId)) {
190:                    return false;
191:                } else {
192:                    try {
193:                        return isIdentical((EJBObject) obj);
194:                    } catch (Exception e) {
195:                        return false;
196:                    }
197:                }
198:            }
199:
200:            public int hashCode() {
201:                return getEJBObjectId().hashCode();
202:            }
203:
204:            protected Object clone() throws CloneNotSupportedException {
205:                throw new CloneNotSupportedException(getEJBObjectId()
206:                        .toString());
207:            }
208:
209:            /**
210:             * 获� Http Session 中的数�,需��� Web Server 和 EJB Container 在�一虚拟机中
211:             * @param attribute session key
212:             */
213:            public Object getSessionAttribute(String attribute) {
214:                return EJBInvocation.current().getSessionAttribute(attribute);
215:            }
216:
217:            public class ENContext extends ContextAdapter {
218:
219:                //--- java:comp/env naming container
220:                public void bind(String name, Object obj)
221:                        throws NamingException {
222:                    if (envMap.containsKey(name)) {
223:                        throw new NameAlreadyBoundException(name);
224:                    }
225:                    envMap.put(name, obj);
226:                }
227:
228:                public void rebind(String name, Object obj)
229:                        throws NamingException {
230:                    envMap.put(name, obj);
231:                }
232:
233:                public void unbind(String name) throws NamingException {
234:                    if (!envMap.containsKey(name)) {
235:                        throw new NameNotFoundException(name);
236:                    }
237:                    envMap.remove(name);
238:                }
239:
240:                public Object lookup(String name) throws NamingException {
241:                    if (!envMap.containsKey(name)) {
242:                        throw new NameNotFoundException(name);
243:                    }
244:                    return envMap.get(name);
245:                }
246:            }
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.