2
|
1 |
/*
|
|
2 |
* Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package java.security.cert;
|
|
27 |
|
|
28 |
import java.io.Serializable;
|
|
29 |
import java.util.Collection;
|
|
30 |
import java.util.Collections;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Parameters used as input for the Collection <code>CertStore</code>
|
|
34 |
* algorithm.
|
|
35 |
* <p>
|
|
36 |
* This class is used to provide necessary configuration parameters
|
|
37 |
* to implementations of the Collection <code>CertStore</code>
|
|
38 |
* algorithm. The only parameter included in this class is the
|
|
39 |
* <code>Collection</code> from which the <code>CertStore</code> will
|
|
40 |
* retrieve certificates and CRLs.
|
|
41 |
* <p>
|
|
42 |
* <b>Concurrent Access</b>
|
|
43 |
* <p>
|
|
44 |
* Unless otherwise specified, the methods defined in this class are not
|
|
45 |
* thread-safe. Multiple threads that need to access a single
|
|
46 |
* object concurrently should synchronize amongst themselves and
|
|
47 |
* provide the necessary locking. Multiple threads each manipulating
|
|
48 |
* separate objects need not synchronize.
|
|
49 |
*
|
|
50 |
* @since 1.4
|
|
51 |
* @author Steve Hanna
|
|
52 |
* @see java.util.Collection
|
|
53 |
* @see CertStore
|
|
54 |
*/
|
|
55 |
public class CollectionCertStoreParameters
|
|
56 |
implements CertStoreParameters {
|
|
57 |
|
|
58 |
private Collection<?> coll;
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Creates an instance of <code>CollectionCertStoreParameters</code>
|
|
62 |
* which will allow certificates and CRLs to be retrieved from the
|
|
63 |
* specified <code>Collection</code>. If the specified
|
|
64 |
* <code>Collection</code> contains an object that is not a
|
|
65 |
* <code>Certificate</code> or <code>CRL</code>, that object will be
|
|
66 |
* ignored by the Collection <code>CertStore</code>.
|
|
67 |
* <p>
|
|
68 |
* The <code>Collection</code> is <b>not</b> copied. Instead, a
|
|
69 |
* reference is used. This allows the caller to subsequently add or
|
|
70 |
* remove <code>Certificates</code> or <code>CRL</code>s from the
|
|
71 |
* <code>Collection</code>, thus changing the set of
|
|
72 |
* <code>Certificates</code> or <code>CRL</code>s available to the
|
|
73 |
* Collection <code>CertStore</code>. The Collection <code>CertStore</code>
|
|
74 |
* will not modify the contents of the <code>Collection</code>.
|
|
75 |
* <p>
|
|
76 |
* If the <code>Collection</code> will be modified by one thread while
|
|
77 |
* another thread is calling a method of a Collection <code>CertStore</code>
|
|
78 |
* that has been initialized with this <code>Collection</code>, the
|
|
79 |
* <code>Collection</code> must have fail-fast iterators.
|
|
80 |
*
|
|
81 |
* @param collection a <code>Collection</code> of
|
|
82 |
* <code>Certificate</code>s and <code>CRL</code>s
|
|
83 |
* @exception NullPointerException if <code>collection</code> is
|
|
84 |
* <code>null</code>
|
|
85 |
*/
|
|
86 |
public CollectionCertStoreParameters(Collection<?> collection) {
|
|
87 |
if (collection == null)
|
|
88 |
throw new NullPointerException();
|
|
89 |
coll = collection;
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Creates an instance of <code>CollectionCertStoreParameters</code> with
|
|
94 |
* the default parameter values (an empty and immutable
|
|
95 |
* <code>Collection</code>).
|
|
96 |
*/
|
|
97 |
public CollectionCertStoreParameters() {
|
|
98 |
coll = Collections.EMPTY_SET;
|
|
99 |
}
|
|
100 |
|
|
101 |
/**
|
|
102 |
* Returns the <code>Collection</code> from which <code>Certificate</code>s
|
|
103 |
* and <code>CRL</code>s are retrieved. This is <b>not</b> a copy of the
|
|
104 |
* <code>Collection</code>, it is a reference. This allows the caller to
|
|
105 |
* subsequently add or remove <code>Certificates</code> or
|
|
106 |
* <code>CRL</code>s from the <code>Collection</code>.
|
|
107 |
*
|
|
108 |
* @return the <code>Collection</code> (never null)
|
|
109 |
*/
|
|
110 |
public Collection<?> getCollection() {
|
|
111 |
return coll;
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Returns a copy of this object. Note that only a reference to the
|
|
116 |
* <code>Collection</code> is copied, and not the contents.
|
|
117 |
*
|
|
118 |
* @return the copy
|
|
119 |
*/
|
|
120 |
public Object clone() {
|
|
121 |
try {
|
|
122 |
return super.clone();
|
|
123 |
} catch (CloneNotSupportedException e) {
|
|
124 |
/* Cannot happen */
|
|
125 |
throw new InternalError(e.toString());
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Returns a formatted string describing the parameters.
|
|
131 |
*
|
|
132 |
* @return a formatted string describing the parameters
|
|
133 |
*/
|
|
134 |
public String toString() {
|
|
135 |
StringBuffer sb = new StringBuffer();
|
|
136 |
sb.append("CollectionCertStoreParameters: [\n");
|
|
137 |
sb.append(" collection: " + coll + "\n");
|
|
138 |
sb.append("]");
|
|
139 |
return sb.toString();
|
|
140 |
}
|
|
141 |
}
|