1 2 18 package com.sun.org.apache.xml.internal.security.keys.storage; 19 20 21 22 import java.security.KeyStore ; 23 import java.security.cert.X509Certificate ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver; 29 import com.sun.org.apache.xml.internal.security.keys.storage.implementations.SingleCertificateResolver; 30 31 32 37 public class StorageResolver { 38 39 40 static java.util.logging.Logger log = 41 java.util.logging.Logger.getLogger(StorageResolver.class.getName()); 42 43 44 List _storageResolvers = new ArrayList (); 45 46 47 Iterator _iterator = null; 48 49 53 public StorageResolver() {} 54 55 60 public StorageResolver(StorageResolverSpi resolver) { 61 this.add(resolver); 62 } 63 64 69 public void add(StorageResolverSpi resolver) { 70 71 this._storageResolvers.add(resolver); 72 73 this._iterator = null; 74 } 75 76 81 public StorageResolver(KeyStore keyStore) { 82 this.add(keyStore); 83 } 84 85 90 public void add(KeyStore keyStore) { 91 92 try { 93 this.add(new KeyStoreResolver(keyStore)); 94 } catch (StorageResolverException ex) { 95 log.log(java.util.logging.Level.SEVERE, "Could not add KeyStore because of: ", ex); 96 } 97 } 98 99 104 public StorageResolver(X509Certificate x509certificate) { 105 this.add(x509certificate); 106 } 107 108 113 public void add(X509Certificate x509certificate) { 114 this.add(new SingleCertificateResolver(x509certificate)); 115 } 116 117 122 public Iterator getIterator() { 123 124 if (this._iterator == null) { 125 this._iterator = new StorageResolverIterator(this._storageResolvers.iterator()); 126 } 127 128 return this._iterator; 129 } 130 131 136 public boolean hasNext() { 137 138 if (this._iterator == null) { 139 this._iterator = new StorageResolverIterator(this._storageResolvers.iterator()); 140 } 141 142 return this._iterator.hasNext(); 143 } 144 145 150 public X509Certificate next() { 151 return (X509Certificate ) this._iterator.next(); 152 } 153 154 160 class StorageResolverIterator implements Iterator { 161 162 163 Iterator _resolvers = null; 164 165 166 int _currentResolver = 0; 167 168 173 public StorageResolverIterator(Iterator resolvers) { 174 this._resolvers = resolvers; 175 } 176 177 178 public boolean hasNext() { 179 return _resolvers.hasNext(); 180 } 181 182 183 public Object next() { 184 return _resolvers.next(); 185 } 186 187 191 public void remove() { 192 throw new UnsupportedOperationException ( 193 "Can't remove keys from KeyStore"); 194 } 195 } 196 } 197 | Popular Tags |