KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > osgi > service > condpermadmin > Condition


1 /*
2  * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/Condition.java,v 1.13 2006/06/16 16:31:37 hargrave Exp $
3  *
4  * Copyright (c) OSGi Alliance (2004, 2006). All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.osgi.service.condpermadmin;
20
21 import java.util.Dictionary JavaDoc;
22
23 /**
24  * The interface implemented by a Condition. Conditions are bound to Permissions
25  * using Conditional Permission Info. The Permissions of a ConditionalPermission
26  * Info can only be used if the associated Conditions are satisfied.
27  *
28  * @version $Revision: 1.13 $
29  */

30 public interface Condition {
31     /**
32      * A Condition object that will always evaluate to true and that is never
33      * postponed.
34      */

35     public final static Condition TRUE = new BooleanCondition(true);
36
37     /**
38      * A Condition object that will always evaluate to false and that is never
39      * postponed.
40      */

41     public final static Condition FALSE = new BooleanCondition(false);
42
43     /**
44      * Returns whether the evaluation must be postponed until the end of the
45      * permission check. This method returns <code>true</code> if the
46      * evaluation of the Condition must be postponed until the end of the
47      * permission check. If this method returns <code>false</code>, this
48      * Condition must be able to directly answer the {@link #isSatisfied()}
49      * method. In other words, isSatisfied() will return very quickly since no
50      * external sources, such as for example users, need to be consulted.
51      *
52      * @return <code>true</code> to indicate the evaluation must be postponed.
53      * Otherwise, <code>false</code> if the evaluation can be
54      * immediately performed.
55      */

56     boolean isPostponed();
57
58     /**
59      * Returns whether the Condition is satisfied.
60      *
61      * @return <code>true</code> to indicate the Conditions is satisfied.
62      * Otherwise, <code>false</code> if the Condition is not satisfied.
63      */

64     boolean isSatisfied();
65
66     /**
67      * Returns whether the Condition is mutable.
68      *
69      * @return <code>true</code> to indicate the value returned by
70      * {@link #isSatisfied()} can change. Otherwise, <code>false</code>
71      * if the value returned by {@link #isSatisfied()} will not change.
72      */

73     boolean isMutable();
74
75     /**
76      * Returns whether a the set of Conditions are satisfied. Although this
77      * method is not static, it must be implemented as if it were static. All of
78      * the passed Conditions will be of the same type and will correspond to the
79      * class type of the object on which this method is invoked.
80      *
81      * @param conditions The array of Conditions.
82      * @param context A Dictionary object that implementors can use to track
83      * state. If this method is invoked multiple times in the same
84      * permission evaluation, the same Dictionary will be passed multiple
85      * times. The SecurityManager treats this Dictionary as an opaque
86      * object and simply creates an empty dictionary and passes it to
87      * subsequent invocations if multiple invocatios are needed.
88      * @return <code>true</code> if all the Conditions are satisfied.
89      * Otherwise, <code>false</code> if one of the Conditions is not
90      * satisfied.
91      */

92     boolean isSatisfied(Condition conditions[], Dictionary JavaDoc context);
93
94 }
95
96 /**
97  * Package internal class used to define the {@link Condition#FALSE} and
98  * {@link Condition#TRUE} constants.
99  */

100 final class BooleanCondition implements Condition {
101     final boolean satisfied;
102
103     BooleanCondition(boolean satisfied) {
104         this.satisfied = satisfied;
105     }
106
107     public boolean isPostponed() {
108         return false;
109     }
110
111     public boolean isSatisfied() {
112         return satisfied;
113     }
114
115     public boolean isMutable() {
116         return false;
117     }
118
119     public boolean isSatisfied(Condition[] conds, Dictionary JavaDoc context) {
120         for (int i = 0; i < conds.length; i++) {
121             if (!conds[i].isSatisfied())
122                 return false;
123         }
124         return true;
125     }
126
127 }
128
Popular Tags