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