1 2 18 package com.sun.org.apache.xml.internal.security.keys.keyresolver; 19 20 21 22 import java.security.PublicKey ; 23 import java.security.cert.X509Certificate ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.crypto.SecretKey; 28 29 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 33 34 41 public class KeyResolver { 42 43 44 static java.util.logging.Logger log = 45 java.util.logging.Logger.getLogger(KeyResolver.class.getName()); 46 47 48 static boolean _alreadyInitialized = false; 49 50 51 static List _resolverVector = null; 52 53 54 protected KeyResolverSpi _resolverSpi = null; 55 56 57 protected StorageResolver _storage = null; 58 59 67 private KeyResolver(String className) 68 throws ClassNotFoundException , IllegalAccessException , 69 InstantiationException { 70 this._resolverSpi = 71 (KeyResolverSpi) Class.forName(className).newInstance(); 72 } 73 74 79 public static int length() { 80 return KeyResolver._resolverVector.size(); 81 } 82 83 90 public static KeyResolver item(int i) throws KeyResolverException { 91 92 KeyResolver resolver = (KeyResolver) KeyResolver._resolverVector.get(i); 93 if (resolver==null) { 94 throw new KeyResolverException("utils.resolver.noClass"); 95 } 96 97 return resolver; 98 } 99 100 110 public static final KeyResolver getInstance( 111 Element element, String BaseURI, StorageResolver storage) 112 throws KeyResolverException { 113 114 for (int i = 0; i < KeyResolver._resolverVector.size(); i++) { 115 KeyResolver resolver= 116 (KeyResolver) KeyResolver._resolverVector.get(i); 117 118 if (resolver==null) { 119 Object exArgs[] = { 120 (((element != null) 121 && (element.getNodeType() == Node.ELEMENT_NODE)) 122 ? element.getTagName() 123 : "null") }; 124 125 throw new KeyResolverException("utils.resolver.noClass", exArgs); 126 } 127 if (true) 128 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "check resolvability by class " + resolver.getClass()); 129 130 if (resolver.canResolve(element, BaseURI, storage)) { 131 return resolver; 132 } 133 } 134 135 Object exArgs[] = { 136 (((element != null) && (element.getNodeType() == Node.ELEMENT_NODE)) 137 ? element.getTagName() 138 : "null") }; 139 140 throw new KeyResolverException("utils.resolver.noClass", exArgs); 141 } 142 143 146 public static void init() { 147 148 if (!KeyResolver._alreadyInitialized) { 149 KeyResolver._resolverVector = new ArrayList (10); 150 _alreadyInitialized = true; 151 } 152 } 153 154 166 public static void register(String className) throws ClassNotFoundException , IllegalAccessException , InstantiationException { 167 KeyResolver._resolverVector.add(new KeyResolver(className)); 168 } 169 170 178 public static void registerAtStart(String className) { 179 KeyResolver._resolverVector.add(0, className); 180 } 181 182 189 190 200 public static PublicKey resolveStatic( 201 Element element, String BaseURI, StorageResolver storage) 202 throws KeyResolverException { 203 204 KeyResolver myResolver = KeyResolver.getInstance(element, BaseURI, 205 storage); 206 207 return myResolver.resolvePublicKey(element, BaseURI, storage); 208 } 209 210 220 public PublicKey resolvePublicKey( 221 Element element, String BaseURI, StorageResolver storage) 222 throws KeyResolverException { 223 return this._resolverSpi.engineResolvePublicKey(element, BaseURI, storage); 224 } 225 226 236 public X509Certificate resolveX509Certificate( 237 Element element, String BaseURI, StorageResolver storage) 238 throws KeyResolverException { 239 return this._resolverSpi.engineResolveX509Certificate(element, BaseURI, 240 storage); 241 } 242 243 250 public SecretKey resolveSecretKey( 251 Element element, String BaseURI, StorageResolver storage) 252 throws KeyResolverException { 253 return this._resolverSpi.engineResolveSecretKey(element, BaseURI, 254 storage); 255 } 256 257 263 public void setProperty(String key, String value) { 264 this._resolverSpi.engineSetProperty(key, value); 265 } 266 267 273 public String getProperty(String key) { 274 return this._resolverSpi.engineGetProperty(key); 275 } 276 277 282 public String [] getPropertyKeys() { 283 return this._resolverSpi.engineGetPropertyKeys(); 284 } 285 286 292 public boolean understandsProperty(String propertyToTest) { 293 return this._resolverSpi.understandsProperty(propertyToTest); 294 } 295 296 304 public boolean canResolve(Element element, String BaseURI, 305 StorageResolver storage) { 306 return this._resolverSpi.engineCanResolve(element, BaseURI, storage); 307 } 308 309 314 public String resolverClassName() { 315 return this._resolverSpi.getClass().getName(); 316 } 317 } 318 | Popular Tags |