Source Code Cross Referenced for BasicMdbBean.java in  » J2EE » openejb3 » org » apache » openejb » test » mdb » 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.mdb 
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.mdb;
017:
018:        import org.apache.openejb.test.ApplicationException;
019:        import org.apache.openejb.test.object.OperationsPolicy;
020:
021:        import javax.ejb.EJBException;
022:        import javax.ejb.MessageDrivenBean;
023:        import javax.ejb.MessageDrivenContext;
024:        import javax.jms.ConnectionFactory;
025:        import javax.jms.JMSException;
026:        import javax.jms.Message;
027:        import javax.jms.MessageListener;
028:        import javax.naming.InitialContext;
029:        import java.util.Hashtable;
030:        import java.util.Properties;
031:
032:        /**
033:         *
034:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
035:         * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
036:         */
037:        public class BasicMdbBean implements  BasicMdbObject, MessageDrivenBean,
038:                MessageListener {
039:            private MessageDrivenContext mdbContext = null;
040:            private static Hashtable allowedOperationsTable = new Hashtable();
041:            protected MdbInvoker mdbInvoker;
042:
043:            public void setMessageDrivenContext(MessageDrivenContext ctx)
044:                    throws EJBException {
045:                this .mdbContext = ctx;
046:                testAllowedOperations("setMessageDrivenContext");
047:                try {
048:                    ConnectionFactory connectionFactory = (ConnectionFactory) new InitialContext()
049:                            .lookup("java:comp/env/jms");
050:                    mdbInvoker = new MdbInvoker(connectionFactory, this );
051:                } catch (Exception e) {
052:                    throw new EJBException(e);
053:                }
054:            }
055:
056:            public void onMessage(Message message) {
057:                try {
058:                    //            System.out.println("\n" +
059:                    //                    "***************************************\n" +
060:                    //                    "Got message: " + message + "\n" +
061:                    //                    "***************************************\n\n");
062:                    try {
063:                        message.acknowledge();
064:                    } catch (JMSException e) {
065:                        e.printStackTrace();
066:                    }
067:                    mdbInvoker.onMessage(message);
068:                } catch (Throwable e) {
069:                    e.printStackTrace();
070:                }
071:            }
072:
073:            //=============================
074:            // Home interface methods
075:            //
076:            //
077:            // Home interface methods
078:            //=============================
079:
080:            //=============================
081:            // Remote interface methods
082:            //
083:
084:            /**
085:             * Maps to BasicStatelessObject.businessMethod
086:             */
087:            public String businessMethod(String text) {
088:                testAllowedOperations("businessMethod");
089:                StringBuffer b = new StringBuffer(text);
090:                return b.reverse().toString();
091:            }
092:
093:            /**
094:             * Throws an ApplicationException when invoked
095:             *
096:             */
097:            public void throwApplicationException() throws ApplicationException {
098:                throw new ApplicationException(
099:                        "Testing ability to throw Application Exceptions");
100:            }
101:
102:            /**
103:             * Throws a java.lang.NullPointerException when invoked
104:             * This is a system exception and should result in the
105:             * destruction of the instance and invalidation of the
106:             * remote reference.
107:             *
108:             */
109:            public void throwSystemException_NullPointer() {
110:                throw new NullPointerException(
111:                        "Testing ability to throw System Exceptions");
112:            }
113:
114:            /**
115:             * Maps to BasicStatelessObject.getPermissionsReport
116:             *
117:             * Returns a report of the bean's
118:             * runtime permissions
119:             *
120:             * @return
121:             */
122:            public Properties getPermissionsReport() {
123:                /* TO DO: */
124:                return null;
125:            }
126:
127:            /**
128:             * Maps to BasicStatelessObject.getAllowedOperationsReport
129:             *
130:             * Returns a report of the allowed opperations
131:             * for one of the bean's methods.
132:             *
133:             * @param methodName The method for which to get the allowed opperations report
134:             * @return
135:             */
136:            public OperationsPolicy getAllowedOperationsReport(String methodName) {
137:                return (OperationsPolicy) allowedOperationsTable
138:                        .get(methodName);
139:            }
140:
141:            //
142:            // Remote interface methods
143:            //=============================
144:
145:            //================================
146:            // MessageDrivenBean interface methods
147:            //
148:
149:            public void ejbCreate() throws javax.ejb.CreateException {
150:                testAllowedOperations("ejbCreate");
151:            }
152:
153:            public void ejbRemove() throws EJBException {
154:                testAllowedOperations("ejbRemove");
155:            }
156:
157:            //
158:            // SessionBean interface methods
159:            //================================
160:
161:            protected void testAllowedOperations(String methodName) {
162:                OperationsPolicy policy = new OperationsPolicy();
163:
164:                /*[0] Test getEJBHome /////////////////*/
165:                try {
166:                    mdbContext.getEJBHome();
167:                    policy.allow(policy.Context_getEJBHome);
168:                } catch (IllegalStateException ise) {
169:                }
170:
171:                /*[1] Test getCallerPrincipal /////////*/
172:                try {
173:                    mdbContext.getCallerPrincipal();
174:                    policy.allow(policy.Context_getCallerPrincipal);
175:                } catch (IllegalStateException ise) {
176:                }
177:
178:                /*[2] Test isCallerInRole /////////////*/
179:                try {
180:                    mdbContext.isCallerInRole("TheMan");
181:                    policy.allow(policy.Context_isCallerInRole);
182:                } catch (IllegalStateException ise) {
183:                }
184:
185:                /*[3] Test getRollbackOnly ////////////*/
186:                try {
187:                    mdbContext.getRollbackOnly();
188:                    policy.allow(policy.Context_getRollbackOnly);
189:                } catch (IllegalStateException ise) {
190:                }
191:
192:                /*[4] Test setRollbackOnly ////////////*/
193:                // Rollback causes message redelivery
194:                /*[5] Test getUserTransaction /////////*/
195:                try {
196:                    mdbContext.getUserTransaction();
197:                    policy.allow(policy.Context_getUserTransaction);
198:                } catch (IllegalStateException ise) {
199:                }
200:
201:                /*[6] Test getEJBObject ///////////////
202:                 *
203:                 * MDBs don't have an ejbObject
204:                 */
205:
206:                /*[7] Test Context_getPrimaryKey ///////////////
207:                 *
208:                 * Can't really do this
209:                 */
210:
211:                /*[8] Test JNDI_access_to_java_comp_env ///////////////*/
212:                try {
213:                    InitialContext jndiContext = new InitialContext();
214:
215:                    String actual = (String) jndiContext
216:                            .lookup("java:comp/env/stateless/references/JNDI_access_to_java_comp_env");
217:
218:                    policy.allow(policy.JNDI_access_to_java_comp_env);
219:                } catch (IllegalStateException ise) {
220:                } catch (javax.naming.NamingException ne) {
221:                }
222:
223:                /*[11] Test lookup /////////*/
224:                try {
225:                    mdbContext
226:                            .lookup("stateless/references/JNDI_access_to_java_comp_env");
227:                    policy.allow(policy.Context_lookup);
228:                } catch (IllegalArgumentException ise) {
229:                }
230:
231:                allowedOperationsTable.put(methodName, policy);
232:
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.