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