1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import java.lang.reflect.Constructor ; 15 import java.security.Permission ; 16 import java.security.PermissionCollection ; 17 import org.eclipse.osgi.framework.debug.Debug; 18 19 24 final class UnresolvedPermission extends Permission { 25 private static final long serialVersionUID = 3546358422783079475L; 26 29 private String type; 30 33 private String actions; 34 37 private String name; 38 39 private static Class [] constructorArgs; 40 41 static { 42 Class string = String .class; 43 constructorArgs = new Class [] {string, string}; 44 } 45 46 55 UnresolvedPermission(String type, String name, String actions) { 56 super(type); 57 this.name = name; 58 this.type = type; 59 this.actions = actions; 60 } 61 62 75 public boolean equals(Object obj) { 76 if (this == obj) { 77 return true; 78 } 79 if (!(obj instanceof UnresolvedPermission)) { 80 return false; 81 } 82 83 UnresolvedPermission perm = (UnresolvedPermission) obj; 84 85 return type.equals(perm.type) && name.equals(perm.name) && actions.equals(perm.actions); 86 } 87 88 97 public boolean implies(Permission p) { 98 return false; 99 } 100 101 109 public PermissionCollection newPermissionCollection() { 110 return new UnresolvedPermissionCollection(); 111 } 112 113 121 public String getActions() { 122 return ""; } 124 125 135 public int hashCode() { 136 return toString().hashCode(); 137 } 138 139 146 public String toString() { 147 return "(unresolved " + type + " " + name + " " + actions + ")"; } 149 150 Permission resolve(Class clazz) { 151 if (clazz.getName().equals(type)) { 152 try { 153 Constructor constructor = clazz.getConstructor(constructorArgs); 154 155 Permission permission = (Permission ) constructor.newInstance(new Object [] {name, actions}); 156 157 if (Debug.DEBUG && Debug.DEBUG_SECURITY) { 158 Debug.println("Resolved " + this); } 160 161 return permission; 162 } catch (Exception e) { 163 164 if (Debug.DEBUG && Debug.DEBUG_SECURITY) { 165 Debug.println("Exception trying to resolve permission"); Debug.printStackTrace(e); 167 } 168 } 169 } 170 171 return null; 172 } 173 } 174 | Popular Tags |