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