KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > SlideTokenWrapper


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/SlideTokenWrapper.java,v 1.14.2.1 2004/08/23 13:53:49 luetzkendorf Exp $
3  * $Revision: 1.14.2.1 $
4  * $Date: 2004/08/23 13:53:49 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.List JavaDoc;
28 import org.apache.slide.authenticate.CredentialsToken;
29 import org.apache.slide.store.ResourceId;
30 import org.apache.slide.structure.ActionNode;
31 import org.apache.slide.structure.ObjectNode;
32 import org.apache.slide.structure.SubjectNode;
33
34 /**
35  * The SlideTokenWrapper wraps around an existing token.
36  * It delegated all work to that token, except that it
37  * may have a different policy for store enlistment,
38  * security and locking.
39  *
40  */

41 public final class SlideTokenWrapper implements SlideToken{
42     
43     
44     // ------------------------------------------------------------ Constructor
45

46     
47     /**
48      * Constructor.
49      * @param token The token to wrap.
50      */

51     public SlideTokenWrapper(SlideToken token) {
52         this.wrappedToken = token;
53         this.forceStoreEnlistment = token.isForceStoreEnlistment();
54         this.forceSecurity = token.isForceSecurity();
55         this.forceLock = token.isForceLock();
56         this.isExternalTransaction = token.isExternalTransaction();
57     }
58     
59     
60     
61     // ----------------------------------------------------- Instance Variables
62

63     
64     /**
65      * Credentials.
66      */

67     private SlideToken wrappedToken;
68     
69     private boolean forceStoreEnlistment = false;
70     private boolean forceSecurity = true;
71     private boolean forceLock = true;
72     private boolean isExternalTransaction = false;
73     
74     // ------------------------------------------------------------- Properties
75

76     
77     /**
78      * Returns the credentials token.
79      *
80      * @return String
81      */

82     public CredentialsToken getCredentialsToken() {
83         return wrappedToken.getCredentialsToken();
84     }
85     
86     
87     /**
88      * Credentials token mutator.
89      */

90     public void setCredentialsToken(CredentialsToken credentialsToken) {
91         wrappedToken.setCredentialsToken(credentialsToken);
92     }
93     
94     
95     /**
96      * Returns the CacheInfo token.
97      *
98      * @return CacheInfoToken
99      */

100     public CacheInfoToken getCacheInfoToken() {
101         return wrappedToken.getCacheInfoToken();
102     }
103     
104     
105     /**
106      * CacheInfo token mutator.
107      */

108     public void setCacheInfoToken(CacheInfoToken cacheInfoToken) {
109         wrappedToken.setCacheInfoToken(cacheInfoToken);
110     }
111     
112     
113     /**
114      * Use lock tokens in lock resolution ?
115      *
116      * @return boolean
117      */

118     public boolean isEnforceLockTokens() {
119         return wrappedToken.isEnforceLockTokens();
120     }
121     
122     
123     /**
124      * Enforce lock tokens flag mutator.
125      *
126      * @param enforceLockTokens New flag value
127      */

128     public void setEnforceLockTokens(boolean enforceLockTokens) {
129         wrappedToken.setEnforceLockTokens(enforceLockTokens);
130     }
131     
132     
133     /**
134      * Force store enlistment flag accessor. If true, that will cause Slide to
135      * enlist the store in the current transaction for all operations,
136      * to be able to prevent dirty reads when doing complex updates.
137      *
138      * @return boolean
139      */

140     public boolean isForceStoreEnlistment() {
141         return forceStoreEnlistment;
142     }
143     
144     
145     /**
146      * Force store enlistment flag mutator. If set to true, that will cause
147      * Slide to enlist the store in the current transaction for all
148      * operations, to be able to prevent dirty reads when doing complex
149      * updates. That value should be set to true only in some very specific
150      * critical sections of the code, as this would greatly decrease the
151      * ability of Slide to handle multiple concurrent requests.
152      *
153      * @param forceStoreEnlistment New flag value
154      */

155     public void setForceStoreEnlistment(boolean forceStoreEnlistment) {
156         this.forceStoreEnlistment = forceStoreEnlistment;
157     }
158     
159     
160     /**
161      * Add a new lock token to the lock token list.
162      *
163      * @param lockId Lock token to add
164      */

165     public void addLockToken(String JavaDoc lockId) {
166         wrappedToken.addLockToken(lockId);
167     }
168     
169     
170     /**
171      * Removes a lock token from the lock token list.
172      *
173      * @param lockId Lock token to remove
174      */

175     public void removeLockToken(String JavaDoc lockId) {
176         wrappedToken.removeLockToken(lockId);
177     }
178     
179     
180     /**
181      * Clears the lock token list.
182      */

183     public void clearLockTokens() {
184         wrappedToken.clearLockTokens();
185     }
186     
187     
188     /**
189      * Checks if the given lock token is present.
190      *
191      * @param lockToken Lock token to check
192      * @return boolean True if the given lock token is present
193      */

194     public boolean checkLockToken(String JavaDoc lockToken) {
195         return wrappedToken.checkLockToken(lockToken);
196     }
197     
198     
199     public List JavaDoc showLockTokens() {
200         return wrappedToken.showLockTokens();
201     }
202     
203     /**
204      * Add a new parameter to the parameter list.
205      *
206      * @param parameterName Parameter to add
207      * @param parameterValue Parameter value
208      */

209     public void addParameter(String JavaDoc parameterName, Object JavaDoc parameterValue) {
210         wrappedToken.addParameter(parameterName, parameterValue);
211     }
212     
213     
214     /**
215      * Removes a parameter from the parameter list.
216      *
217      * @param parameterName Parameter to remove
218      */

219     public void removeParameter(String JavaDoc parameterName) {
220         wrappedToken.removeParameter(parameterName);
221     }
222     
223     
224     /**
225      * Clears the parameter list.
226      */

227     public void clearParameters() {
228         wrappedToken.clearParameters();
229     }
230     
231     /**
232      * Returns a named parameter.
233      */

234     public Object JavaDoc getParameter(String JavaDoc name) {
235         return wrappedToken.getParameter(name);
236     }
237     
238     /**
239      * Return parameter list.
240      */

241     public Enumeration JavaDoc getParameterNames() {
242         return wrappedToken.getParameterNames();
243     }
244     
245     /**
246      * allows to cache the result of a permission check
247      *
248      * @return true if successful added to cache, false else
249      */

250     public void cachePermission(ObjectNode object, ActionNode action, boolean permission){
251         wrappedToken.cachePermission(object, action, permission);
252     }
253     
254     /**
255      * checks if the permission cache contains an entry for the ObjectNode and
256      * ActionNode combination.
257      *
258      * @return true if granted, false if denied, null if nothing in the cache.
259      */

260     public Boolean JavaDoc checkPermissionCache(ObjectNode object, ActionNode action){
261         return wrappedToken.checkPermissionCache(object, action);
262     }
263     
264     /**
265      * Force security check. If false, checkCredentials of SecurityImpl will
266      * return immediately.
267      *
268      * @return a boolean
269      */

270     public boolean isForceSecurity() {
271         return forceSecurity;
272     }
273     
274     public void setForceSecurity(boolean forceSecurity) {
275         this.forceSecurity = forceSecurity;
276     }
277
278     /**
279      * Force lock check. If false, checkLock of LockImpl will
280      * return immediately.
281      *
282      * @return a boolean
283      */

284     public boolean isForceLock() {
285         return forceLock;
286     }
287         
288     public void setForceLock(boolean forceLock) {
289         this.forceLock = forceLock;
290     }
291     
292     /**
293      * allows to cache the result of a lock check
294      */

295     public void cacheLock(ObjectNode object, ActionNode action, boolean lock) {
296         wrappedToken.cacheLock(object, action, lock);
297     }
298     
299     /**
300      * checks if the lock cache contains an entry for the ObjectNode and
301      * ActionNode combination.
302      *
303      * @return true if locked, false otherwise
304      */

305     public Boolean JavaDoc checkLockCache(ObjectNode object, ActionNode action) {
306         // TODO ??
307
return wrappedToken.checkLockCache(object, action);
308     }
309     
310     /**
311      * Allows to cache the result of a resolve operation
312      */

313     public void cacheResolve(Uri uri, ResourceId resourceId) {
314         wrappedToken.cacheResolve(uri, resourceId);
315     }
316     
317     /**
318      * Checks if the resolve cache contains an entry for the specified uri.
319      * @return the cached resourceId or null
320      */

321     public ResourceId checkResolveCache(Uri uri) {
322         return wrappedToken.checkResolveCache(uri);
323     }
324     
325     /**
326      * Allows to cache the result of a matchPrincipal operation
327      */

328     public void cacheMatchPrincipal(SubjectNode checkSubject, SubjectNode matchSubject, boolean match) {
329         wrappedToken.cacheMatchPrincipal(checkSubject, matchSubject, match);
330     }
331     
332     /**
333      * Checks if the matchPrincipal cache
334      * @return the cached Boolean or null
335      */

336     public Boolean JavaDoc checkMatchPrincipalCache(SubjectNode checkSubject, SubjectNode matchSubject) {
337         return wrappedToken.checkMatchPrincipalCache(checkSubject, matchSubject);
338     }
339
340     /**
341      * Checks if this request is part of an externally controlled transaction.
342      */

343     public boolean isExternalTransaction() {
344         return isExternalTransaction;
345     }
346
347     /**
348      * Sets if this request is part of an externally controlled transaction.
349      */

350     public void setExternalTx() {
351         isExternalTransaction = true;
352     }
353 }
354
Popular Tags