001 /*
002 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security.cert;
027
028 import java.io.Serializable;
029 import java.util.Collection;
030 import java.util.Collections;
031
032 /**
033 * Parameters used as input for the Collection <code>CertStore</code>
034 * algorithm.
035 * <p>
036 * This class is used to provide necessary configuration parameters
037 * to implementations of the Collection <code>CertStore</code>
038 * algorithm. The only parameter included in this class is the
039 * <code>Collection</code> from which the <code>CertStore</code> will
040 * retrieve certificates and CRLs.
041 * <p>
042 * <b>Concurrent Access</b>
043 * <p>
044 * Unless otherwise specified, the methods defined in this class are not
045 * thread-safe. Multiple threads that need to access a single
046 * object concurrently should synchronize amongst themselves and
047 * provide the necessary locking. Multiple threads each manipulating
048 * separate objects need not synchronize.
049 *
050 * @version 1.16 05/05/07
051 * @since 1.4
052 * @author Steve Hanna
053 * @see java.util.Collection
054 * @see CertStore
055 */
056 public class CollectionCertStoreParameters implements
057 CertStoreParameters {
058
059 private Collection<?> coll;
060
061 /**
062 * Creates an instance of <code>CollectionCertStoreParameters</code>
063 * which will allow certificates and CRLs to be retrieved from the
064 * specified <code>Collection</code>. If the specified
065 * <code>Collection</code> contains an object that is not a
066 * <code>Certificate</code> or <code>CRL</code>, that object will be
067 * ignored by the Collection <code>CertStore</code>.
068 * <p>
069 * The <code>Collection</code> is <b>not</b> copied. Instead, a
070 * reference is used. This allows the caller to subsequently add or
071 * remove <code>Certificates</code> or <code>CRL</code>s from the
072 * <code>Collection</code>, thus changing the set of
073 * <code>Certificates</code> or <code>CRL</code>s available to the
074 * Collection <code>CertStore</code>. The Collection <code>CertStore</code>
075 * will not modify the contents of the <code>Collection</code>.
076 * <p>
077 * If the <code>Collection</code> will be modified by one thread while
078 * another thread is calling a method of a Collection <code>CertStore</code>
079 * that has been initialized with this <code>Collection</code>, the
080 * <code>Collection</code> must have fail-fast iterators.
081 *
082 * @param collection a <code>Collection</code> of
083 * <code>Certificate</code>s and <code>CRL</code>s
084 * @exception NullPointerException if <code>collection</code> is
085 * <code>null</code>
086 */
087 public CollectionCertStoreParameters(Collection<?> collection) {
088 if (collection == null)
089 throw new NullPointerException();
090 coll = collection;
091 }
092
093 /**
094 * Creates an instance of <code>CollectionCertStoreParameters</code> with
095 * the default parameter values (an empty and immutable
096 * <code>Collection</code>).
097 */
098 public CollectionCertStoreParameters() {
099 coll = Collections.EMPTY_SET;
100 }
101
102 /**
103 * Returns the <code>Collection</code> from which <code>Certificate</code>s
104 * and <code>CRL</code>s are retrieved. This is <b>not</b> a copy of the
105 * <code>Collection</code>, it is a reference. This allows the caller to
106 * subsequently add or remove <code>Certificates</code> or
107 * <code>CRL</code>s from the <code>Collection</code>.
108 *
109 * @return the <code>Collection</code> (never null)
110 */
111 public Collection<?> getCollection() {
112 return coll;
113 }
114
115 /**
116 * Returns a copy of this object. Note that only a reference to the
117 * <code>Collection</code> is copied, and not the contents.
118 *
119 * @return the copy
120 */
121 public Object clone() {
122 try {
123 return super .clone();
124 } catch (CloneNotSupportedException e) {
125 /* Cannot happen */
126 throw new InternalError(e.toString());
127 }
128 }
129
130 /**
131 * Returns a formatted string describing the parameters.
132 *
133 * @return a formatted string describing the parameters
134 */
135 public String toString() {
136 StringBuffer sb = new StringBuffer();
137 sb.append("CollectionCertStoreParameters: [\n");
138 sb.append(" collection: " + coll + "\n");
139 sb.append("]");
140 return sb.toString();
141 }
142 }
|