Source Code Cross Referenced for BasicCmpBean.java in  » J2EE » openejb3 » org » apache » openejb » test » entity » cmp » 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.entity.cmp 
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.entity.cmp;
017:
018:        import java.rmi.RemoteException;
019:        import java.util.Properties;
020:        import java.util.StringTokenizer;
021:        import java.util.Map;
022:        import java.util.HashMap;
023:
024:        import javax.ejb.EJBException;
025:        import javax.ejb.EntityContext;
026:        import javax.ejb.RemoveException;
027:
028:        import org.apache.openejb.test.ApplicationException;
029:        import org.apache.openejb.test.object.OperationsPolicy;
030:
031:        /**
032:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
033:         * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
034:         */
035:        public class BasicCmpBean implements  javax.ejb.EntityBean {
036:            private static int nextId;
037:            public Integer primaryKey;
038:            public String firstName;
039:            public String lastName;
040:            public EntityContext ejbContext;
041:            public Map<String, OperationsPolicy> allowedOperationsTable = new HashMap<String, OperationsPolicy>();
042:
043:            //=============================
044:            // Home interface methods
045:            //    
046:
047:            /**
048:             * Maps to BasicCmpHome.sum
049:             * 
050:             * Adds x and y and returns the result.
051:             * 
052:             * @param x
053:             * @param y
054:             * @return x + y
055:             * @see BasicCmpHome#sum
056:             */
057:            public int ejbHomeSum(int x, int y) {
058:                testAllowedOperations("ejbHome");
059:                return x + y;
060:            }
061:
062:            public void ejbHomeVoidSelect() {
063:            }
064:
065:            /**
066:             * Maps to BasicCmpHome.create
067:             * 
068:             * @param name
069:             * @return 
070:             * @exception javax.ejb.CreateException
071:             * @see BasicCmpHome#createObject
072:             */
073:            public Integer ejbCreateObject(String name)
074:                    throws javax.ejb.CreateException {
075:                primaryKey = nextId++;
076:                StringTokenizer st = new StringTokenizer(name, " ");
077:                firstName = st.nextToken();
078:                lastName = st.nextToken();
079:                return null;
080:            }
081:
082:            public void ejbPostCreateObject(String name)
083:                    throws javax.ejb.CreateException {
084:            }
085:
086:            public int getPrimaryKey() {
087:                return primaryKey;
088:            }
089:
090:            public String getFirstName() {
091:                return firstName;
092:            }
093:
094:            public String getLastName() {
095:                return lastName;
096:            }
097:
098:            //    
099:            // Home interface methods
100:            //=============================
101:
102:            //=============================
103:            // Remote interface methods
104:            //    
105:
106:            /**
107:             * Maps to BasicCmpObject.businessMethod
108:             * 
109:             * @return 
110:             * @see BasicCmpObject#businessMethod
111:             */
112:            public String businessMethod(String text) {
113:                testAllowedOperations("businessMethod");
114:                StringBuffer b = new StringBuffer(text);
115:                return b.reverse().toString();
116:            }
117:
118:            /**
119:             * Throws an ApplicationException when invoked
120:             * 
121:             */
122:            public void throwApplicationException() throws ApplicationException {
123:                throw new ApplicationException(
124:                        "Testing ability to throw Application Exceptions");
125:            }
126:
127:            /**
128:             * Throws a java.lang.NullPointerException when invoked
129:             * This is a system exception and should result in the 
130:             * destruction of the instance and invalidation of the
131:             * remote reference.
132:             * 
133:             */
134:            public void throwSystemException_NullPointer() {
135:                throw new NullPointerException(
136:                        "Testing ability to throw System Exceptions");
137:            }
138:
139:            /**
140:             * Maps to BasicCmpObject.getPermissionsReport
141:             * 
142:             * Returns a report of the bean's
143:             * runtime permissions
144:             * 
145:             * @return 
146:             * @see BasicCmpObject#getPermissionsReport
147:             */
148:            public Properties getPermissionsReport() {
149:                /* TO DO: */
150:                return null;
151:            }
152:
153:            /**
154:             * Maps to BasicCmpObject.getAllowedOperationsReport
155:             * 
156:             * Returns a report of the allowed opperations
157:             * for one of the bean's methods.
158:             * 
159:             * @param methodName The method for which to get the allowed opperations report
160:             * @return 
161:             * @see BasicCmpObject#getAllowedOperationsReport
162:             */
163:            public OperationsPolicy getAllowedOperationsReport(String methodName) {
164:                return allowedOperationsTable.get(methodName);
165:            }
166:
167:            //    
168:            // Remote interface methods
169:            //=============================
170:
171:            //================================
172:            // EntityBean interface methods
173:            //    
174:
175:            /**
176:             * A container invokes this method to instruct the
177:             * instance to synchronize its state by loading it state from the
178:             * underlying database.
179:             */
180:            public void ejbLoad() throws EJBException, RemoteException {
181:            }
182:
183:            /**
184:             * Set the associated entity context. The container invokes this method
185:             * on an instance after the instance has been created.
186:             */
187:            public void setEntityContext(EntityContext ctx)
188:                    throws EJBException, RemoteException {
189:                ejbContext = ctx;
190:                testAllowedOperations("setEntityContext");
191:            }
192:
193:            /**
194:             * Unset the associated entity context. The container calls this method
195:             * before removing the instance.
196:             */
197:            public void unsetEntityContext() throws EJBException,
198:                    RemoteException {
199:                testAllowedOperations("unsetEntityContext");
200:            }
201:
202:            /**
203:             * A container invokes this method to instruct the
204:             * instance to synchronize its state by storing it to the underlying
205:             * database.
206:             */
207:            public void ejbStore() throws EJBException, RemoteException {
208:            }
209:
210:            /**
211:             * A container invokes this method before it removes the EJB object
212:             * that is currently associated with the instance. This method
213:             * is invoked when a client invokes a remove operation on the
214:             * enterprise Bean's home interface or the EJB object's remote interface.
215:             * This method transitions the instance from the ready state to the pool
216:             * of available instances.
217:             */
218:            public void ejbRemove() throws RemoveException, EJBException,
219:                    RemoteException {
220:            }
221:
222:            /**
223:             * A container invokes this method when the instance
224:             * is taken out of the pool of available instances to become associated
225:             * with a specific EJB object. This method transitions the instance to
226:             * the ready state.
227:             */
228:            public void ejbActivate() throws EJBException, RemoteException {
229:                testAllowedOperations("ejbActivate");
230:            }
231:
232:            /**
233:             * A container invokes this method on an instance before the instance
234:             * becomes disassociated with a specific EJB object. After this method
235:             * completes, the container will place the instance into the pool of
236:             * available instances.
237:             */
238:            public void ejbPassivate() throws EJBException, RemoteException {
239:                testAllowedOperations("ejbPassivate");
240:            }
241:
242:            //    
243:            // EntityBean interface methods
244:            //================================
245:
246:            protected void testAllowedOperations(String methodName) {
247:                OperationsPolicy policy = new OperationsPolicy();
248:
249:                /*[1] Test getEJBHome /////////////////*/
250:                try {
251:                    ejbContext.getEJBHome();
252:                    policy.allow(OperationsPolicy.Context_getEJBHome);
253:                } catch (IllegalStateException ise) {
254:                }
255:
256:                /*[2] Test getCallerPrincipal /////////*/
257:                try {
258:                    ejbContext.getCallerPrincipal();
259:                    policy.allow(OperationsPolicy.Context_getCallerPrincipal);
260:                } catch (IllegalStateException ise) {
261:                }
262:
263:                /*[3] Test isCallerInRole /////////////*/
264:                try {
265:                    ejbContext.isCallerInRole("TheMan");
266:                    policy.allow(OperationsPolicy.Context_isCallerInRole);
267:                } catch (IllegalStateException ise) {
268:                }
269:
270:                /*[4] Test getRollbackOnly ////////////*/
271:                try {
272:                    ejbContext.getRollbackOnly();
273:                    policy.allow(OperationsPolicy.Context_getRollbackOnly);
274:                } catch (IllegalStateException ise) {
275:                }
276:
277:                /*[5] Test setRollbackOnly ////////////*/
278:                try {
279:                    ejbContext.setRollbackOnly();
280:                    policy.allow(OperationsPolicy.Context_setRollbackOnly);
281:                } catch (IllegalStateException ise) {
282:                }
283:
284:                /*[6] Test getUserTransaction /////////*/
285:                try {
286:                    ejbContext.getUserTransaction();
287:                    policy.allow(OperationsPolicy.Context_getUserTransaction);
288:                } catch (Exception e) {
289:                }
290:
291:                /*[7] Test getEJBObject ///////////////*/
292:                try {
293:                    ejbContext.getEJBObject();
294:                    policy.allow(OperationsPolicy.Context_getEJBObject);
295:                } catch (IllegalStateException ise) {
296:                }
297:
298:                /*[8] Test getPrimaryKey //////////////*/
299:                try {
300:                    ejbContext.getPrimaryKey();
301:                    policy.allow(OperationsPolicy.Context_getPrimaryKey);
302:                } catch (IllegalStateException ise) {
303:                }
304:
305:                /* TO DO:  
306:                 * Check for policy.Enterprise_bean_access       
307:                 * Check for policy.JNDI_access_to_java_comp_env 
308:                 * Check for policy.Resource_manager_access      
309:                 */
310:                allowedOperationsTable.put(methodName, policy);
311:            }
312:
313:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.