KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > entity > EntityContext


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: EntityContext.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.core.entity;
46
47 import org.openejb.RpcContainer;
48 import org.openejb.core.Operations;
49 import org.openejb.core.ThreadContext;
50 import org.openejb.core.ivm.EjbObjectProxyHandler;
51
52 /**
53  * This class imposes restrictions on what Entity methods can access which EntityContext
54  * methods. This class manages restrictions related to the position of the bean
55  * in its life-cycle to the EntityContext operation being performed. Restrictions are specified
56  * in the EJB specification. The CoreContext actually fulfills the request, this class just
57  * applies restrictions on access.
58  */

59 public class EntityContext
60 extends org.openejb.core.CoreContext implements javax.ejb.EntityContext JavaDoc{
61
62     public void checkBeanState(byte methodCategory) throws IllegalStateException JavaDoc{
63         /*
64         The methodCategory will be one of the following constants.
65         
66         SECURITY_METHOD:
67         ROLLBACK_METHOD:
68         EJBOBJECT_METHOD:
69         EJBHOME_METHOD
70         
71         The super class, CoreContext determines if Context.getUserTransaction( ) method
72         maybe called before invoking this.checkBeanState( ). Only "bean managed" transaction
73         beans may access this method.
74         
75         The USER_TRANSACTION_METHOD constant will never be a methodCategory
76         because entity beans are not allowed to have "bean managed" transactions.
77         
78         USER_TRANSACTION_METHOD:
79         */

80         
81         ThreadContext callContext = ThreadContext.getThreadContext();
82         org.openejb.DeploymentInfo di = callContext.getDeploymentInfo();
83         
84         
85         switch(callContext.getCurrentOperation()){
86             case Operations.OP_SET_CONTEXT:
87             case Operations.OP_UNSET_CONTEXT:
88                 /*
89                 Allowed Operations:
90                     getEJBHome
91                 Prohibited Operations:
92                     getCallerPrincipal
93                     getRollbackOnly,
94                     isCallerInRole
95                     setRollbackOnly
96                     getEJBObject
97                     getPrimaryKey
98                     getUserTransaction
99                 */

100                 if(methodCategory != EJBHOME_METHOD)
101                     throw new IllegalStateException JavaDoc("Invalid operation attempted");
102                 break;
103             case Operations.OP_CREATE:
104             case Operations.OP_FIND:
105             case Operations.OP_HOME:
106                 /*
107                 Allowed Operations:
108                     getEJBHome
109                     getCallerPrincipal
110                     getRollbackOnly,
111                     isCallerInRole
112                     setRollbackOnly
113                 Prohibited Operations:
114                     getEJBObject
115                     getPrimaryKey
116                     getUserTransaction
117                 */

118                 if(methodCategory == EJBOBJECT_METHOD)
119                     throw new IllegalStateException JavaDoc("Invalid operation attempted");
120                 break;
121             case Operations.OP_ACTIVATE:
122             case Operations.OP_PASSIVATE:
123                 /*
124                 Allowed Operations:
125                     getEJBHome
126                     getEJBObject
127                     getPrimaryKey
128                 Prohibited Operations:
129                     getCallerPrincipal
130                     getRollbackOnly,
131                     isCallerInRole
132                     setRollbackOnly
133                     getUserTransaction
134                 */

135                 if(methodCategory != EJBOBJECT_METHOD && methodCategory != EJBHOME_METHOD)
136                     throw new IllegalStateException JavaDoc("Invalid operation attempted");
137                 break;
138                     
139             case Operations.OP_POST_CREATE:
140             case Operations.OP_REMOVE:
141             case Operations.OP_LOAD:
142             case Operations.OP_STORE:
143                 /*
144                 Allowed Operations:
145                     getEJBHome
146                     getCallerPrincipal
147                     getRollbackOnly,
148                     isCallerInRole
149                     setRollbackOnly
150                     getEJBObject
151                     getPrimaryKey
152                 Prohibited Operations:
153                     getUserTransaction
154                 */

155                 break;
156             
157         }
158         
159     }
160     
161     protected EjbObjectProxyHandler newEjbObjectHandler(RpcContainer container, Object JavaDoc pk, Object JavaDoc depID){
162         return new EntityEjbObjectHandler(container, pk, depID);
163     }
164     
165 }
Popular Tags