135 |
{ |
{ |
136 |
return new AllPermissionCollection(); |
return new AllPermissionCollection(); |
137 |
} |
} |
|
} // class AllPermission |
|
|
|
|
|
/** |
|
|
* Implements AllPermission.newPermissionCollection, and obeys serialization |
|
|
* of JDK. |
|
|
* |
|
|
* @author Eric Blake <ebb9@email.byu.edu> |
|
|
*/ |
|
|
final class AllPermissionCollection extends PermissionCollection |
|
|
{ |
|
|
/** |
|
|
* Compatible with JDK 1.1+. |
|
|
*/ |
|
|
private static final long serialVersionUID = -4023755556366636806L; |
|
138 |
|
|
139 |
/** |
/** |
140 |
* Whether an AllPermission has been added to the collection. |
* Implements AllPermission.newPermissionCollection, and obeys serialization |
141 |
|
* of JDK. |
142 |
* |
* |
143 |
* @serial if all permission is in the collection yet |
* @author Eric Blake <ebb9@email.byu.edu> |
144 |
*/ |
*/ |
145 |
private boolean all_allowed; |
private static final class AllPermissionCollection extends PermissionCollection |
|
|
|
|
/** |
|
|
* Add an AllPermission. |
|
|
* |
|
|
* @param perm the permission to add |
|
|
* @throws IllegalArgumentException if perm is not an AllPermission |
|
|
* @throws SecurityException if the collection is read-only |
|
|
*/ |
|
|
public void add(Permission perm) |
|
146 |
{ |
{ |
147 |
if (isReadOnly()) |
/** |
148 |
throw new SecurityException(); |
* Compatible with JDK 1.1+. |
149 |
if (! (perm instanceof AllPermission)) |
*/ |
150 |
throw new IllegalArgumentException(); |
private static final long serialVersionUID = -4023755556366636806L; |
|
all_allowed = true; |
|
|
} |
|
151 |
|
|
152 |
/** |
/** |
153 |
* Returns true if this collection implies a permission. |
* Whether an AllPermission has been added to the collection. |
154 |
* |
* |
155 |
* @param perm the permission to check |
* @serial if all permission is in the collection yet |
156 |
* @return true if this collection contains an AllPermission |
*/ |
157 |
*/ |
private boolean all_allowed; |
|
public boolean implies(Permission perm) |
|
|
{ |
|
|
return all_allowed; |
|
|
} |
|
158 |
|
|
159 |
/** |
/** |
160 |
* Returns an enumeration of the elements in the collection. |
* Add an AllPermission. |
161 |
* |
* |
162 |
* @return the elements in the collection |
* @param perm the permission to add |
163 |
*/ |
* @throws IllegalArgumentException if perm is not an AllPermission |
164 |
public Enumeration elements() |
* @throws SecurityException if the collection is read-only |
165 |
{ |
*/ |
166 |
return all_allowed |
public void add(Permission perm) |
167 |
? Collections.enumeration(Collections.singleton(new AllPermission())) |
{ |
168 |
: EmptyEnumeration.getInstance(); |
if (isReadOnly()) |
169 |
} |
throw new SecurityException(); |
170 |
} // class AllPermissionCollection |
if (! (perm instanceof AllPermission)) |
171 |
|
throw new IllegalArgumentException(); |
172 |
|
all_allowed = true; |
173 |
|
} |
174 |
|
|
175 |
|
/** |
176 |
|
* Returns true if this collection implies a permission. |
177 |
|
* |
178 |
|
* @param perm the permission to check |
179 |
|
* @return true if this collection contains an AllPermission |
180 |
|
*/ |
181 |
|
public boolean implies(Permission perm) |
182 |
|
{ |
183 |
|
return all_allowed; |
184 |
|
} |
185 |
|
|
186 |
|
/** |
187 |
|
* Returns an enumeration of the elements in the collection. |
188 |
|
* |
189 |
|
* @return the elements in the collection |
190 |
|
*/ |
191 |
|
public Enumeration elements() |
192 |
|
{ |
193 |
|
return all_allowed |
194 |
|
? Collections.enumeration(Collections.singleton(new AllPermission())) |
195 |
|
: EmptyEnumeration.getInstance(); |
196 |
|
} |
197 |
|
} // class AllPermissionCollection |
198 |
|
} // class AllPermission |