KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > keys > storage > StorageResolver


1
2 /*
3  * Copyright 1999-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package com.sun.org.apache.xml.internal.security.keys.storage;
19
20
21
22 import java.security.KeyStore JavaDoc;
23 import java.security.cert.X509Certificate JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
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 /**
33  * This class collects customized resolvers for Certificates.
34  *
35  * @author $Author: raul $
36  */

37 public class StorageResolver {
38
39    /** {@link java.util.logging} logging facility */
40     static java.util.logging.Logger JavaDoc log =
41         java.util.logging.Logger.getLogger(StorageResolver.class.getName());
42
43    /** Field _storageResolvers */
44    List JavaDoc _storageResolvers = new ArrayList JavaDoc();
45
46    /** Field _iterator */
47    Iterator JavaDoc _iterator = null;
48
49    /**
50     * Constructor StorageResolver
51     *
52     */

53    public StorageResolver() {}
54
55    /**
56     * Constructor StorageResolver
57     *
58     * @param resolver
59     */

60    public StorageResolver(StorageResolverSpi resolver) {
61       this.add(resolver);
62    }
63
64    /**
65     * Method addResolver
66     *
67     * @param resolver
68     */

69    public void add(StorageResolverSpi resolver) {
70
71       this._storageResolvers.add(resolver);
72
73       this._iterator = null;
74    }
75
76    /**
77     * Constructor StorageResolver
78     *
79     * @param keyStore
80     */

81    public StorageResolver(KeyStore JavaDoc keyStore) {
82       this.add(keyStore);
83    }
84
85    /**
86     * Method addKeyStore
87     *
88     * @param keyStore
89     */

90    public void add(KeyStore JavaDoc 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    /**
100     * Constructor StorageResolver
101     *
102     * @param x509certificate
103     */

104    public StorageResolver(X509Certificate JavaDoc x509certificate) {
105       this.add(x509certificate);
106    }
107
108    /**
109     * Method addCertificate
110     *
111     * @param x509certificate
112     */

113    public void add(X509Certificate JavaDoc x509certificate) {
114       this.add(new SingleCertificateResolver(x509certificate));
115    }
116
117    /**
118     * Method getIterator
119     * @return the iterator for the resolvers.
120     *
121     */

122    public Iterator JavaDoc getIterator() {
123
124       if (this._iterator == null) {
125          this._iterator = new StorageResolverIterator(this._storageResolvers.iterator());
126       }
127
128       return this._iterator;
129    }
130
131    /**
132     * Method hasNext
133     *
134     * @return true if there is more elements.
135     */

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    /**
146     * Method next
147     *
148     * @return the next element
149     */

150    public X509Certificate JavaDoc next() {
151       return (X509Certificate JavaDoc) this._iterator.next();
152    }
153
154    /**
155     * Class StorageResolverIterator
156     *
157     * @author $Author: raul $
158     * @version $Revision: 1.10 $
159     */

160    class StorageResolverIterator implements Iterator JavaDoc {
161
162       /** Field _resolvers */
163        Iterator JavaDoc _resolvers = null;
164
165       /** Field _currentResolver */
166       int _currentResolver = 0;
167
168       /**
169        * Constructor FilesystemIterator
170        *
171        * @param resolvers
172        */

173       public StorageResolverIterator(Iterator JavaDoc resolvers) {
174          this._resolvers = resolvers;
175       }
176
177       /** @inheritDoc */
178       public boolean hasNext() {
179           return _resolvers.hasNext();
180       }
181
182       /** @inheritDoc */
183       public Object JavaDoc next() {
184           return _resolvers.next();
185       }
186
187       /**
188        * Method remove
189        *
190        */

191       public void remove() {
192          throw new UnsupportedOperationException JavaDoc(
193             "Can't remove keys from KeyStore");
194       }
195    }
196 }
197
Popular Tags