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