KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > entity > bmp > AllowedOperationsBmpBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: AllowedOperationsBmpBean.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45 package org.openejb.test.entity.bmp;
46
47 import java.rmi.RemoteException JavaDoc;
48 import java.util.Hashtable JavaDoc;
49 import java.util.Properties JavaDoc;
50
51 import javax.ejb.EJBException JavaDoc;
52 import javax.ejb.EntityContext JavaDoc;
53 import javax.ejb.RemoveException JavaDoc;
54 import javax.naming.InitialContext JavaDoc;
55 import javax.sql.DataSource JavaDoc;
56
57 import org.openejb.test.object.OperationsPolicy;
58
59 /**
60  *
61  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
62  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
63  */

64 public class AllowedOperationsBmpBean implements javax.ejb.EntityBean JavaDoc{
65     
66     private int primaryKey;
67     private String JavaDoc firstName;
68     private String JavaDoc lastName;
69     private EntityContext JavaDoc ejbContext;
70     private Hashtable JavaDoc allowedOperationsTable = new Hashtable JavaDoc();
71     
72     
73     //=============================
74
// Home interface methods
75
//
76

77     /**
78      * Maps to BasicBmpHome.sum
79      *
80      * Adds x and y and returns the result.
81      *
82      * @param one
83      * @param two
84      * @return x + y
85      * @see BasicBmpHome.sum
86      */

87     public int ejbHomeSum(int x, int y) {
88         testAllowedOperations("ejbHome");
89         return x+y;
90     }
91     
92     /**
93      * Maps to BasicBmpHome.findEmptyCollection
94      *
95      * @return Collection
96      * @exception javax.ejb.FinderException
97      */

98     public java.util.Collection JavaDoc ejbFindEmptyCollection()
99     throws javax.ejb.FinderException JavaDoc, java.rmi.RemoteException JavaDoc {
100         return new java.util.Vector JavaDoc();
101     }
102
103     public java.util.Enumeration JavaDoc ejbFindEmptyEnumeration()
104     throws javax.ejb.FinderException JavaDoc
105     {
106         return (new java.util.Vector JavaDoc()).elements();
107     }
108
109     public java.util.Collection JavaDoc ejbFindByLastName(String JavaDoc lastName)
110     throws javax.ejb.FinderException JavaDoc{
111         return new java.util.Vector JavaDoc();
112     }
113
114     /**
115      * Maps to BasicBmpHome.findByPrimaryKey
116      *
117      * @param primaryKey
118      * @return Integer
119      * @exception javax.ejb.FinderException
120      */

121     public Integer JavaDoc ejbFindByPrimaryKey(Integer JavaDoc primaryKey)
122     throws javax.ejb.FinderException JavaDoc{
123         testAllowedOperations("ejbFind");
124         return new Integer JavaDoc(-1);
125     }
126
127     /**
128      * Maps to BasicBmpHome.create
129      *
130      * @param name
131      * @return Integer
132      * @exception javax.ejb.CreateException
133      */

134     public Integer JavaDoc ejbCreate(String JavaDoc name)
135     throws javax.ejb.CreateException JavaDoc{
136         testAllowedOperations("ejbCreate");
137                 
138         return new Integer JavaDoc(-1);
139     }
140     
141     public void ejbPostCreate(String JavaDoc name)
142     throws javax.ejb.CreateException JavaDoc{
143     }
144
145     //
146
// Home interface methods
147
//=============================
148

149
150     //=============================
151
// Remote interface methods
152
//
153

154     /**
155      * Maps to BasicBmpObject.businessMethod
156      *
157      * @return String
158      */

159     public String JavaDoc businessMethod(String JavaDoc text){
160         testAllowedOperations("businessMethod");
161         StringBuffer JavaDoc b = new StringBuffer JavaDoc(text);
162         return b.reverse().toString();
163     }
164
165     /**
166      * Throws an ApplicationException when invoked
167      *
168      */

169     public void throwApplicationException() throws org.openejb.test.ApplicationException{
170         throw new org.openejb.test.ApplicationException("Don't Panic");
171     }
172     
173     /**
174      * Throws a java.lang.NullPointerException when invoked
175      * This is a system exception and should result in the
176      * destruction of the instance and invalidation of the
177      * remote reference.
178      *
179      */

180     public void throwSystemException_NullPointer() {
181         throw new NullPointerException JavaDoc("Panic");
182     }
183     
184     
185     /**
186      * Maps to BasicBmpObject.getPermissionsReport
187      *
188      * Returns a report of the bean's
189      * runtime permissions
190      *
191      * @return null
192      */

193     public Properties JavaDoc getPermissionsReport(){
194         /* TO DO: */
195         return null;
196     }
197     
198     /**
199      * Maps to BasicBmpObject.getAllowedOperationsReport
200      *
201      * Returns a report of the allowed opperations
202      * for one of the bean's methods.
203      *
204      * @param methodName The method for which to get the allowed opperations report
205      * @return OperationsPolicy
206      */

207     public OperationsPolicy getAllowedOperationsReport(String JavaDoc methodName){
208         return (OperationsPolicy) allowedOperationsTable.get(methodName);
209     }
210     
211     //
212
// Remote interface methods
213
//=============================
214

215
216     //================================
217
// EntityBean interface methods
218
//
219

220     /**
221      * A container invokes this method to instruct the
222      * instance to synchronize its state by loading it state from the
223      * underlying database.
224      */

225     public void ejbLoad() throws EJBException JavaDoc,RemoteException JavaDoc {
226         testAllowedOperations("ejbLoad");
227     }
228     
229     /**
230      * Set the associated entity context. The container invokes this method
231      * on an instance after the instance has been created.
232      */

233     public void setEntityContext(EntityContext JavaDoc ctx) throws EJBException JavaDoc,RemoteException JavaDoc {
234         ejbContext = ctx;
235         testAllowedOperations("setEntityContext");
236     }
237     
238     /**
239      * Unset the associated entity context. The container calls this method
240      * before removing the instance.
241      */

242     public void unsetEntityContext() throws EJBException JavaDoc,RemoteException JavaDoc {
243         testAllowedOperations("unsetEntityContext");
244     }
245     
246     /**
247      * A container invokes this method to instruct the
248      * instance to synchronize its state by storing it to the underlying
249      * database.
250      */

251     public void ejbStore() throws EJBException JavaDoc,RemoteException JavaDoc {
252         testAllowedOperations("ejbStore");
253     }
254     
255     /**
256      * A container invokes this method before it removes the EJB object
257      * that is currently associated with the instance. This method
258      * is invoked when a client invokes a remove operation on the
259      * enterprise Bean's home interface or the EJB object's remote interface.
260      * This method transitions the instance from the ready state to the pool
261      * of available instances.
262      */

263     public void ejbRemove() throws RemoveException JavaDoc,EJBException JavaDoc,RemoteException JavaDoc {
264         testAllowedOperations("ejbRemove");
265     }
266     
267     /**
268      * A container invokes this method when the instance
269      * is taken out of the pool of available instances to become associated
270      * with a specific EJB object. This method transitions the instance to
271      * the ready state.
272      */

273     public void ejbActivate() throws EJBException JavaDoc,RemoteException JavaDoc {
274         testAllowedOperations("ejbActivate");
275     }
276     
277     /**
278      * A container invokes this method on an instance before the instance
279      * becomes disassociated with a specific EJB object. After this method
280      * completes, the container will place the instance into the pool of
281      * available instances.
282      */

283     public void ejbPassivate() throws EJBException JavaDoc,RemoteException JavaDoc {
284
285         testAllowedOperations("ejbPassivate");
286     }
287     //
288
// EntityBean interface methods
289
//================================
290

291     protected void testAllowedOperations(String JavaDoc methodName) {
292         OperationsPolicy policy = new OperationsPolicy();
293     
294         /*[0] Test getEJBHome /////////////////*/
295         try {
296             ejbContext.getEJBHome();
297             policy.allow(policy.Context_getEJBHome);
298         } catch (IllegalStateException JavaDoc ise) {
299         }
300     
301         /*[1] Test getCallerPrincipal /////////*/
302         try {
303             ejbContext.getCallerPrincipal();
304             policy.allow( policy.Context_getCallerPrincipal );
305         } catch (IllegalStateException JavaDoc ise) {
306         }
307     
308         /*[2] Test isCallerInRole /////////////*/
309         try {
310             ejbContext.isCallerInRole("ROLE");
311             policy.allow( policy.Context_isCallerInRole );
312         } catch (IllegalStateException JavaDoc ise) {
313         }
314     
315         /*[3] Test getRollbackOnly ////////////*/
316         try {
317             ejbContext.getRollbackOnly();
318             policy.allow( policy.Context_getRollbackOnly );
319         } catch (IllegalStateException JavaDoc ise) {
320         }
321     
322         /*[4] Test setRollbackOnly ////////////*/
323         try {
324             ejbContext.setRollbackOnly();
325             policy.allow( policy.Context_setRollbackOnly );
326         } catch (IllegalStateException JavaDoc ise) {
327         }
328     
329         /*[5] Test getUserTransaction /////////*/
330         try {
331             ejbContext.getUserTransaction();
332             policy.allow( policy.Context_getUserTransaction );
333         } catch (IllegalStateException JavaDoc ise) {
334         }
335     
336         /*[6] Test getEJBObject ///////////////*/
337         try {
338             ejbContext.getEJBObject();
339             policy.allow( policy.Context_getEJBObject );
340         } catch (IllegalStateException JavaDoc ise) {
341         }
342     
343         /*[7] Test Context_getPrimaryKey ///////////////
344          *
345          * TODO: Write this test.
346          */

347         try {
348             ejbContext.getPrimaryKey();
349             policy.allow( policy.Context_getPrimaryKey );
350         } catch (IllegalStateException JavaDoc ise) {
351         }
352
353         /*[8] Test JNDI_access_to_java_comp_env ///////////////*/
354         try {
355             InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
356     
357             String JavaDoc actual = (String JavaDoc)jndiContext.lookup("java:comp/env/stateless/references/JNDI_access_to_java_comp_env");
358     
359             policy.allow( policy.JNDI_access_to_java_comp_env );
360         } catch (IllegalStateException JavaDoc ise) {
361         } catch (javax.naming.NamingException JavaDoc ne) {
362         }
363     
364         /*[9] Test Resource_manager_access ///////////////*/
365         try {
366             InitialContext JavaDoc jndiContext = new InitialContext JavaDoc( );
367     
368             DataSource JavaDoc ds = (DataSource JavaDoc)jndiContext.lookup("java:comp/env/stateless/references/Resource_manager_access");
369     
370             policy.allow( policy.Resource_manager_access );
371         } catch (IllegalStateException JavaDoc ise) {
372         } catch (javax.naming.NamingException JavaDoc ne) {
373         }
374     
375         /*[10] Test Enterprise_bean_access ///////////////*/
376         try {
377             InitialContext JavaDoc jndiContext = new InitialContext JavaDoc( );
378     
379             Object JavaDoc obj = jndiContext.lookup("java:comp/env/stateless/beanReferences/Enterprise_bean_access");
380     
381             policy.allow( policy.Enterprise_bean_access );
382         } catch (IllegalStateException JavaDoc ise) {
383         } catch (javax.naming.NamingException JavaDoc ne) {
384         }
385     
386         allowedOperationsTable.put(methodName, policy);
387     }
388
389 }
390
Popular Tags