1. /*
  2. * @(#)CollectionCertStoreParameters.java 1.8 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.io.Serializable;
  9. import java.util.Collection;
  10. import java.util.Collections;
  11. /**
  12. * Parameters used as input for the Collection <code>CertStore</code>
  13. * algorithm.
  14. * <p>
  15. * This class is used to provide necessary configuration parameters
  16. * to implementations of the Collection <code>CertStore</code>
  17. * algorithm. The only parameter included in this class is the
  18. * <code>Collection</code> from which the <code>CertStore</code> will
  19. * retrieve certificates and CRLs.
  20. * <p>
  21. * <b>Concurrent Access</b>
  22. * <p>
  23. * Unless otherwise specified, the methods defined in this class are not
  24. * thread-safe. Multiple threads that need to access a single
  25. * object concurrently should synchronize amongst themselves and
  26. * provide the necessary locking. Multiple threads each manipulating
  27. * separate objects need not synchronize.
  28. *
  29. * @version 1.8 05/05/04
  30. * @since 1.4
  31. * @author Steve Hanna
  32. * @see java.util.Collection
  33. * @see CertStore
  34. */
  35. public class CollectionCertStoreParameters
  36. implements CertStoreParameters {
  37. private Collection coll;
  38. /**
  39. * Creates an instance of <code>CollectionCertStoreParameters</code>
  40. * which will allow certificates and CRLs to be retrieved from the
  41. * specified <code>Collection</code>. If the specified
  42. * <code>Collection</code> contains an object that is not a
  43. * <code>Certificate</code> or <code>CRL</code>, that object will be
  44. * ignored by the Collection <code>CertStore</code>.
  45. * <p>
  46. * The <code>Collection</code> is <b>not</b> copied. Instead, a
  47. * reference is used. This allows the caller to subsequently add or
  48. * remove <code>Certificates</code> or <code>CRL</code>s from the
  49. * <code>Collection</code>, thus changing the set of
  50. * <code>Certificates</code> or <code>CRL</code>s available to the
  51. * Collection <code>CertStore</code>. The Collection <code>CertStore</code>
  52. * will not modify the contents of the <code>Collection</code>.
  53. * <p>
  54. * If the <code>Collection</code> will be modified by one thread while
  55. * another thread is calling a method of a Collection <code>CertStore</code>
  56. * that has been initialized with this <code>Collection</code>, the
  57. * <code>Collection</code> must have fail-fast iterators.
  58. *
  59. * @param collection a <code>Collection</code> of
  60. * <code>Certificate</code>s and <code>CRL</code>s
  61. * @exception NullPointerException if <code>collection</code> is
  62. * <code>null</code>
  63. */
  64. public CollectionCertStoreParameters(Collection<?> collection) {
  65. if (collection == null)
  66. throw new NullPointerException();
  67. coll = collection;
  68. }
  69. /**
  70. * Creates an instance of <code>CollectionCertStoreParameters</code> with
  71. * the default parameter values (an empty and immutable
  72. * <code>Collection</code>).
  73. */
  74. public CollectionCertStoreParameters() {
  75. coll = Collections.EMPTY_SET;
  76. }
  77. /**
  78. * Returns the <code>Collection</code> from which <code>Certificate</code>s
  79. * and <code>CRL</code>s are retrieved. This is <b>not</b> a copy of the
  80. * <code>Collection</code>, it is a reference. This allows the caller to
  81. * subsequently add or remove <code>Certificates</code> or
  82. * <code>CRL</code>s from the <code>Collection</code>.
  83. *
  84. * @return the <code>Collection</code> (never null)
  85. */
  86. public Collection<?> getCollection() {
  87. return coll;
  88. }
  89. /**
  90. * Returns a copy of this object. Note that only a reference to the
  91. * <code>Collection</code> is copied, and not the contents.
  92. *
  93. * @return the copy
  94. */
  95. public Object clone() {
  96. try {
  97. return super.clone();
  98. } catch (CloneNotSupportedException e) {
  99. /* Cannot happen */
  100. throw new InternalError(e.toString());
  101. }
  102. }
  103. /**
  104. * Returns a formatted string describing the parameters.
  105. *
  106. * @return a formatted string describing the parameters
  107. */
  108. public String toString() {
  109. StringBuffer sb = new StringBuffer();
  110. sb.append("CollectionCertStoreParameters: [\n");
  111. sb.append(" collection: " + coll + "\n");
  112. sb.append("]");
  113. return sb.toString();
  114. }
  115. }