1 7 8 package java.security; 9 10 import java.util.*; 11 import java.io.ObjectStreamField ; 12 import java.io.ObjectOutputStream ; 13 import java.io.ObjectInputStream ; 14 import java.io.IOException ; 15 16 30 31 final class UnresolvedPermissionCollection 32 extends PermissionCollection 33 implements java.io.Serializable 34 { 35 40 private transient Map perms; 41 42 46 public UnresolvedPermissionCollection() { 47 perms = new HashMap(11); 48 } 49 50 56 57 public void add(Permission permission) 58 { 59 if (! (permission instanceof UnresolvedPermission )) 60 throw new IllegalArgumentException ("invalid permission: "+ 61 permission); 62 UnresolvedPermission up = (UnresolvedPermission ) permission; 63 64 List v; 65 synchronized (this) { 66 v = (List) perms.get(up.getName()); 67 if (v == null) { 68 v = new ArrayList(); 69 perms.put(up.getName(), v); 70 } 71 } 72 synchronized (v) { 73 v.add(up); 74 } 75 } 76 77 81 List getUnresolvedPermissions(Permission p) { 82 synchronized (this) { 83 return (List) perms.get(p.getClass().getName()); 84 } 85 } 86 87 91 public boolean implies(Permission permission) 92 { 93 return false; 94 } 95 96 102 103 public Enumeration elements() { 104 List results = new ArrayList(); 106 synchronized (this) { 108 for (Iterator iter = perms.values().iterator(); iter.hasNext();) { 109 List l = (List) iter.next(); 110 synchronized (l) { 111 results.addAll(l); 112 } 113 } 114 } 115 116 return Collections.enumeration(results); 117 } 118 119 private static final long serialVersionUID = -7176153071733132400L; 120 121 125 130 private static final ObjectStreamField [] serialPersistentFields = { 131 new ObjectStreamField ("permissions", Hashtable.class), 132 }; 133 134 137 142 private void writeObject(ObjectOutputStream out) throws IOException { 143 145 Hashtable permissions = new Hashtable(perms.size()*2); 147 148 synchronized (this) { 150 Set set = perms.entrySet(); 151 for (Iterator iter = set.iterator(); iter.hasNext(); ) { 152 Map.Entry e = (Map.Entry)iter.next(); 153 154 List list = (List) e.getValue(); 156 Vector vec = new Vector(list.size()); 157 synchronized (list) { 158 vec.addAll(list); 159 } 160 161 permissions.put(e.getKey(), vec); 163 } 164 } 165 166 ObjectOutputStream.PutField pfields = out.putFields(); 168 pfields.put("permissions", permissions); 169 out.writeFields(); 170 } 171 172 176 private void readObject(ObjectInputStream in) throws IOException , 177 ClassNotFoundException { 178 180 ObjectInputStream.GetField gfields = in.readFields(); 182 183 Hashtable permissions = (Hashtable)gfields.get("permissions", null); 185 perms = new HashMap(permissions.size()*2); 186 187 Set set = permissions.entrySet(); 189 for (Iterator iter = set.iterator(); iter.hasNext(); ) { 190 Map.Entry e = (Map.Entry)iter.next(); 191 192 Vector vec = (Vector) e.getValue(); 194 List list = new ArrayList(vec.size()); 195 list.addAll(vec); 196 197 perms.put(e.getKey(), list); 199 } 200 } 201 } 202 | Popular Tags |