Source Code Cross Referenced for BMTStatefulBean.java in  » J2EE » openejb3 » org » apache » openejb » test » stateful » 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 » openejb3 » org.apache.openejb.test.stateful 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.test.stateful;
017:
018:        import java.rmi.RemoteException;
019:        import java.util.Hashtable;
020:        import java.util.Properties;
021:
022:        import javax.ejb.EJBException;
023:        import javax.ejb.SessionContext;
024:
025:        import org.apache.openejb.test.ApplicationException;
026:        import org.apache.openejb.test.object.OperationsPolicy;
027:
028:        /**
029:         * A Stateful SessionBean with bean-managed transaction demarcation
030:         * 
031:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
032:         * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
033:         */
034:        public class BMTStatefulBean implements  javax.ejb.SessionBean {
035:
036:            private String name;
037:            private SessionContext ejbContext;
038:            private Hashtable allowedOperationsTable = new Hashtable();
039:
040:            //=============================
041:            // Home interface methods
042:            //    
043:            /**
044:             * Maps to BasicStatefulHome.create
045:             * 
046:             * @param name
047:             * @exception javax.ejb.CreateException
048:             * @see BasicStatefulHome#createObject
049:             */
050:            public void ejbCreateObject(String name)
051:                    throws javax.ejb.CreateException {
052:                testAllowedOperations("ejbCreate");
053:                this .name = name;
054:            }
055:
056:            //    
057:            // Home interface methods
058:            //=============================
059:
060:            //=============================
061:            // Remote interface methods
062:            //    
063:
064:            /**
065:             * Maps to BasicStatefulObject.businessMethod
066:             * 
067:             * @return 
068:             * @see BasicStatefulObject#businessMethod
069:             */
070:            public String businessMethod(String text) {
071:                testAllowedOperations("businessMethod");
072:                StringBuffer b = new StringBuffer(text);
073:                return b.reverse().toString();
074:            }
075:
076:            /**
077:             * Throws an ApplicationException when invoked
078:             * 
079:             */
080:            public void throwApplicationException() throws ApplicationException {
081:                throw new ApplicationException("Don't Panic");
082:            }
083:
084:            /**
085:             * Throws a java.lang.NullPointerException when invoked
086:             * This is a system exception and should result in the 
087:             * destruction of the instance and invalidation of the
088:             * remote reference.
089:             * 
090:             */
091:            public void throwSystemException_NullPointer() {
092:                throw new NullPointerException("Panic");
093:            }
094:
095:            /**
096:             * Maps to BasicStatefulObject.getPermissionsReport
097:             * 
098:             * Returns a report of the bean's
099:             * runtime permissions
100:             * 
101:             * @return 
102:             * @see BasicStatefulObject#getPermissionsReport
103:             */
104:            public Properties getPermissionsReport() {
105:                /* TO DO: */
106:                return null;
107:            }
108:
109:            /**
110:             * Maps to BasicStatefulObject.getAllowedOperationsReport
111:             * 
112:             * Returns a report of the allowed opperations
113:             * for one of the bean's methods.
114:             * 
115:             * @param methodName The method for which to get the allowed opperations report
116:             * @return 
117:             * @see BasicStatefulObject#getAllowedOperationsReport
118:             */
119:            public OperationsPolicy getAllowedOperationsReport(String methodName) {
120:                return (OperationsPolicy) allowedOperationsTable
121:                        .get(methodName);
122:            }
123:
124:            public String remove(String arg) {
125:                return arg;
126:            }
127:
128:            //    
129:            // Remote interface methods
130:            //=============================
131:
132:            //=================================
133:            // SessionBean interface methods
134:            //    
135:            /**
136:             * Set the associated session context. The container calls this method
137:             * after the instance creation.
138:             */
139:            public void setSessionContext(SessionContext ctx)
140:                    throws EJBException, RemoteException {
141:                ejbContext = ctx;
142:                testAllowedOperations("setSessionContext");
143:            }
144:
145:            /**
146:             * A container invokes this method before it ends the life of the session
147:             * object. This happens as a result of a client's invoking a remove
148:             * operation, or when a container decides to terminate the session object
149:             * after a timeout.
150:             */
151:            public void ejbRemove() throws EJBException, RemoteException {
152:                testAllowedOperations("ejbRemove");
153:            }
154:
155:            /**
156:             * The activate method is called when the instance is activated
157:             * from its "passive" state. The instance should acquire any resource
158:             * that it has released earlier in the ejbPassivate() method.
159:             */
160:            public void ejbActivate() throws EJBException, RemoteException {
161:                testAllowedOperations("ejbActivate");
162:            }
163:
164:            /**
165:             * The passivate method is called before the instance enters
166:             * the "passive" state. The instance should release any resources that
167:             * it can re-acquire later in the ejbActivate() method.
168:             */
169:            public void ejbPassivate() throws EJBException, RemoteException {
170:                testAllowedOperations("ejbPassivate");
171:            }
172:
173:            //    
174:            // StatefulBean interface methods
175:            //==================================
176:
177:            protected void testAllowedOperations(String methodName) {
178:                OperationsPolicy policy = new OperationsPolicy();
179:
180:                /*[1] Test getEJBHome /////////////////*/
181:                try {
182:                    ejbContext.getEJBHome();
183:                    policy.allow(policy.Context_getEJBHome);
184:                } catch (IllegalStateException ise) {
185:                }
186:
187:                /*[2] Test getCallerPrincipal /////////*/
188:                try {
189:                    ejbContext.getCallerPrincipal();
190:                    policy.allow(policy.Context_getCallerPrincipal);
191:                } catch (IllegalStateException ise) {
192:                }
193:
194:                /*[3] Test isCallerInRole /////////////*/
195:                try {
196:                    ejbContext.isCallerInRole("TheMan");
197:                    policy.allow(policy.Context_isCallerInRole);
198:                } catch (IllegalStateException ise) {
199:                }
200:
201:                /*[4] Test getRollbackOnly ////////////*/
202:                try {
203:                    ejbContext.getRollbackOnly();
204:                    policy.allow(policy.Context_getRollbackOnly);
205:                } catch (IllegalStateException ise) {
206:                }
207:
208:                /*[5] Test setRollbackOnly ////////////*/
209:                try {
210:                    ejbContext.setRollbackOnly();
211:                    policy.allow(policy.Context_setRollbackOnly);
212:                } catch (IllegalStateException ise) {
213:                }
214:
215:                /*[6] Test getUserTransaction /////////*/
216:                try {
217:                    ejbContext.getUserTransaction();
218:                    policy.allow(policy.Context_getUserTransaction);
219:                } catch (IllegalStateException ise) {
220:                }
221:
222:                /*[7] Test getEJBObject ///////////////*/
223:                try {
224:                    ejbContext.getEJBObject();
225:                    policy.allow(policy.Context_getEJBObject);
226:                } catch (IllegalStateException ise) {
227:                }
228:
229:                /* TO DO:  
230:                 * Check for policy.Enterprise_bean_access       
231:                 * Check for policy.JNDI_access_to_java_comp_env 
232:                 * Check for policy.Resource_manager_access      
233:                 */
234:                allowedOperationsTable.put(methodName, policy);
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.