KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > UnresolvedPermissionCollection


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.framework.internal.core;
13
14 import java.security.Permission JavaDoc;
15 import java.security.PermissionCollection JavaDoc;
16 import java.util.*;
17
18 /**
19  * Holds permissions which are of an unknown type when a
20  * policy file is read
21  *
22  */

23 final class UnresolvedPermissionCollection extends PermissionCollection JavaDoc {
24     private static final long serialVersionUID = 3618703006602703161L;
25     /** hash of permission class names => Vectors of UnresolvedPermissions for that class */
26     Hashtable permissions = new Hashtable(8);
27
28     UnresolvedPermissionCollection() {
29         super();
30     }
31
32     public void add(Permission JavaDoc permission) {
33         if (isReadOnly()) {
34             throw new IllegalStateException JavaDoc();
35         }
36
37         String JavaDoc name = permission.getName();
38
39         Vector elements;
40
41         synchronized (permissions) {
42             elements = (Vector) permissions.get(name);
43
44             if (elements == null) {
45                 elements = new Vector(10, 10);
46
47                 permissions.put(name, elements);
48             }
49         }
50
51         elements.addElement(permission);
52     }
53
54     public Enumeration elements() {
55         return (new Enumeration() {
56             Enumeration vEnum, pEnum = permissions.elements();
57             Object JavaDoc next = findNext();
58
59             private Object JavaDoc findNext() {
60                 if (vEnum != null) {
61                     if (vEnum.hasMoreElements())
62                         return (vEnum.nextElement());
63                 }
64                 if (!pEnum.hasMoreElements())
65                     return (null);
66                 vEnum = ((Vector) pEnum.nextElement()).elements();
67                 return (vEnum.nextElement());
68             }
69
70             public boolean hasMoreElements() {
71                 return (next != null);
72             }
73
74             public Object JavaDoc nextElement() {
75                 Object JavaDoc result = next;
76                 next = findNext();
77                 return (result);
78             }
79         });
80     }
81
82     public boolean implies(Permission JavaDoc permission) {
83         return false;
84     }
85
86     Vector getPermissions(String JavaDoc name) {
87         return (Vector) permissions.get(name);
88     }
89 }
90
Popular Tags