jdk/src/share/classes/java/security/Provider.java
author darcy
Wed, 05 Mar 2014 22:32:14 -0800
changeset 23062 ece6b5d8a71b
parent 22117 1efafbb25acb
child 23735 34d83df87817
permissions -rw-r--r--
8036747: Fix unchecked lint warnings in java.security.Provider Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22117
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21979
diff changeset
     2
 * Copyright (c) 1996, 2014, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import static java.util.Locale.ENGLISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    33
import java.util.function.BiConsumer;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    34
import java.util.function.BiFunction;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    35
import java.util.function.Function;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class represents a "provider" for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Java Security API, where a provider implements some or all parts of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Java Security. Services that a provider may implement include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <li>Algorithms (such as DSA, RSA, MD5 or SHA-1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <li>Key generation, conversion, and management facilities (such as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * algorithm-specific keys).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>Each provider has a name and a version number, and is configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * in each runtime it is installed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>See <a href =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * "../../../technotes/guides/security/crypto/CryptoSpec.html#Provider">The Provider Class</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * in the "Java Cryptography Architecture API Specification &amp; Reference"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * for information about how a particular type of provider, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * cryptographic service provider, works and is installed. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * please note that a provider can be used to implement any security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * service in Java that uses a pluggable architecture with a choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * of implementations that fit underneath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>Some provider implementations may encounter unrecoverable internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * errors during their operation, for example a failure to communicate with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * security token. A {@link ProviderException} should be used to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * such errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    68
 * <p>The service type {@code Provider} is reserved for use by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * security framework. Services of this type cannot be added, removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * or modified by applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The following attributes are automatically placed in each Provider object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <table cellspacing=4>
18592
80cdfecea074 8019539: Fix doclint errors in java.security and its subpackages
juh
parents: 18579
diff changeset
    73
 * <caption><b>Attributes Automatically Placed in a Provider Object</b></caption>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <tr><th>Name</th><th>Value</th>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    75
 * <tr><td>{@code Provider.id name}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    76
  *    <td>{@code String.valueOf(provider.getName())}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    77
 * <tr><td>{@code Provider.id version}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    78
 *     <td>{@code String.valueOf(provider.getVersion())}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    79
 * <tr><td>{@code Provider.id info}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    80
       <td>{@code String.valueOf(provider.getInfo())}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    81
 * <tr><td>{@code Provider.id className}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    82
 *     <td>{@code provider.getClass().getName()}</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
public abstract class Provider extends Properties {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // Declare serialVersionUID to be compatible with JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    static final long serialVersionUID = -4298000515446427739L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final sun.security.util.Debug debug =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        sun.security.util.Debug.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        ("provider", "Provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The provider name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * A description of the provider and its services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private String info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The provider version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private double version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private transient Set<Map.Entry<Object,Object>> entrySet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private transient int entrySetCallCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private transient boolean initialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Constructs a provider with the specified name, version number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * and information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param name the provider name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param version the provider version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param info a description of the provider and its services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected Provider(String name, double version, String info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.version = version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        putId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Returns the name of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the name of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns the version number for this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the version number for this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public double getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns a human-readable description of the provider and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * services.  This may return an HTML page, with relevant links.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return a description of the provider and its services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String getInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Returns a string with the name and the version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return the string with the name and the version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * for this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return name + " version " + version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * override the following methods to ensure that provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * information can only be changed if the caller has the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Clears this provider so that it no longer contains the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * used to look up facilities implemented by the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   191
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   192
     * method is called with the string {@code "clearProviderProperties."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   193
     * (where {@code name} is the provider name) to see if it's ok to clear
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   194
     * this provider.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   197
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   198
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          denies access to clear this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   203
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public synchronized void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        check("clearProviderProperties."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            debug.println("Remove " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        implClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Reads a property list (key and element pairs) from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param inStream   the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @exception  IOException  if an error occurred when reading from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *               input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see java.util.Properties#load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   220
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public synchronized void load(InputStream inStream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            debug.println("Load " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Properties tempProperties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        tempProperties.load(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        implPutAll(tempProperties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Copies all of the mappings from the specified Map to this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * These mappings will replace any properties that this provider had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * for any of the keys currently in the specified Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   238
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public synchronized void putAll(Map<?,?> t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            debug.println("Put all " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        implPutAll(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns an unmodifiable Set view of the property entries contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * in this Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see   java.util.Map.Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   254
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public synchronized Set<Map.Entry<Object,Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (entrySet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (entrySetCallCount++ == 0)  // Initial call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                entrySet = Collections.unmodifiableMap(this).entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                return super.entrySet();   // Recursive call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // This exception will be thrown if the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // Collections.unmodifiableMap.entrySet() is changed such that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // no longer calls entrySet() on the backing Map.  (Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // entrySet implementation depends on this "implementation detail",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // which is unlikely to change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (entrySetCallCount != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new RuntimeException("Internal error.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return entrySet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns an unmodifiable Set view of the property keys contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   281
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public Set<Object> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return Collections.unmodifiableSet(super.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns an unmodifiable Collection view of the property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * contained in this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   293
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public Collection<Object> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return Collections.unmodifiableCollection(super.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   300
     * Sets the {@code key} property to have the specified
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   301
     * {@code value}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   303
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   304
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   305
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   306
     * provider's property values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   309
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   310
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *          denies access to set property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   315
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public synchronized Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            debug.println("Set " + name + " provider property [" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                          key + "/" + value +"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return implPut(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   326
     * If the specified key is not already associated with a value (or is mapped
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   327
     * to {@code null}) associates it with the given value and returns
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   328
     * {@code null}, else returns the current value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   329
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   330
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   331
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   332
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   333
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   334
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   335
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   336
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   337
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   338
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   339
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   340
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   341
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   342
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   343
    public synchronized Object putIfAbsent(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   344
        check("putProviderProperty."+name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   345
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   346
            debug.println("Set " + name + " provider property [" +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   347
                          key + "/" + value +"]");
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   348
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   349
        return implPutIfAbsent(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   350
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   351
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   352
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   353
     * Removes the {@code key} property (and its corresponding
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   354
     * {@code value}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   356
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   357
     * method is called with the string {@code "removeProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   358
     * where {@code name} is the provider name, to see if it's ok to remove this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   359
     * provider's properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   362
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   363
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *          denies access to remove this provider's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   368
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public synchronized Object remove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        check("removeProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            debug.println("Remove " + name + " provider property " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return implRemove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   377
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   378
     * Removes the entry for the specified key only if it is currently
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   379
     * mapped to the specified value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   380
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   381
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   382
     * method is called with the string {@code "removeProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   383
     * where {@code name} is the provider name, to see if it's ok to remove this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   384
     * provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   385
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   386
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   387
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   388
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   389
     *          denies access to remove this provider's properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   390
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   391
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   392
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   393
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   394
    public synchronized boolean remove(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   395
        check("removeProviderProperty."+name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   396
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   397
            debug.println("Remove " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   398
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   399
        return implRemove(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   400
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   401
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   402
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   403
     * Replaces the entry for the specified key only if currently
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   404
     * mapped to the specified value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   405
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   406
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   407
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   408
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   409
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   410
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   411
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   412
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   413
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   414
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   415
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   416
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   417
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   418
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   419
    public synchronized boolean replace(Object key, Object oldValue,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   420
            Object newValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   421
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   422
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   423
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   424
            debug.println("Replace " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   425
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   426
        return implReplace(key, oldValue, newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   427
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   428
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   429
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   430
     * Replaces the entry for the specified key only if it is
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   431
     * currently mapped to some value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   432
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   433
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   434
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   435
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   436
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   437
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   438
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   439
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   440
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   441
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   442
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   443
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   444
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   445
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   446
    public synchronized Object replace(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   447
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   448
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   449
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   450
            debug.println("Replace " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   451
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   452
        return implReplace(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   453
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   454
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   455
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   456
     * Replaces each entry's value with the result of invoking the given
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   457
     * function on that entry, in the order entries are returned by an entry
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   458
     * set iterator, until all entries have been processed or the function
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   459
     * throws an exception.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   460
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   461
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   462
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   463
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   464
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   465
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   466
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   467
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   468
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   469
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   470
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   471
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   472
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   473
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   474
    public synchronized void replaceAll(BiFunction<? super Object, ? super Object, ? extends Object> function) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   475
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   476
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   477
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   478
            debug.println("ReplaceAll " + name + " provider property ");
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   479
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   480
        implReplaceAll(function);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   481
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   482
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   483
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   484
     * Attempts to compute a mapping for the specified key and its
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   485
     * current mapped value (or {@code null} if there is no current
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   486
     * mapping).
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   487
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   488
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   489
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   490
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   491
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   492
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   493
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   494
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   495
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   496
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   497
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   498
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   499
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   500
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   501
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   502
    public synchronized Object compute(Object key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   503
        BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   504
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   505
        check("removeProviderProperty" + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   506
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   507
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   508
            debug.println("Compute " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   509
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   510
        return implCompute(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   511
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   512
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   513
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   514
     * If the specified key is not already associated with a value (or
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   515
     * is mapped to {@code null}), attempts to compute its value using
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   516
     * the given mapping function and enters it into this map unless
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   517
     * {@code null}.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   518
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   519
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   520
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   521
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   522
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   523
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   524
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   525
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   526
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   527
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   528
     *          denies access to set property values and remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   529
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   530
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   531
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   532
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   533
    public synchronized Object computeIfAbsent(Object key, Function<? super Object, ? extends Object> mappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   534
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   535
        check("removeProviderProperty" + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   536
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   537
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   538
            debug.println("ComputeIfAbsent " + name + " provider property " +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   539
                    key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   540
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   541
        return implComputeIfAbsent(key, mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   542
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   543
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   544
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   545
     * If the value for the specified key is present and non-null, attempts to
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   546
     * compute a new mapping given the key and its current mapped value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   547
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   548
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   549
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   550
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   551
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   552
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   553
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   554
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   555
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   556
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   557
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   558
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   559
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   560
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   561
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   562
    public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   563
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   564
        check("removeProviderProperty" + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   565
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   566
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   567
            debug.println("ComputeIfPresent " + name + " provider property " +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   568
                    key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   569
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   570
        return implComputeIfPresent(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   571
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   572
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   573
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   574
     * If the specified key is not already associated with a value or is
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   575
     * associated with null, associates it with the given value. Otherwise,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   576
     * replaces the value with the results of the given remapping function,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   577
     * or removes if the result is null. This method may be of use when
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   578
     * combining multiple mapped values for a key.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   579
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   580
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   581
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   582
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   583
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   584
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   585
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   586
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   587
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   588
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   589
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   590
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   591
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   592
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   593
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   594
    public synchronized Object merge(Object key, Object value,  BiFunction<? super Object, ? super Object, ? extends Object>  remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   595
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   596
        check("removeProviderProperty" + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   597
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   598
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   599
            debug.println("Merge " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   600
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   601
        return implMerge(key, value, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   602
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   603
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   605
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   610
    /**
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   611
     * @since 1.8
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   612
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   613
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   614
    public synchronized Object getOrDefault(Object key, Object defaultValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   615
        checkInitialized();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   616
        return super.getOrDefault(key, defaultValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   617
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   618
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   619
    /**
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   620
     * @since 1.8
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   621
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   622
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   623
    public synchronized void forEach(BiConsumer<? super Object, ? super Object> action) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   624
        checkInitialized();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   625
        super.forEach(action);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   626
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   627
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   629
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public Enumeration<Object> keys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return super.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   636
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public Enumeration<Object> elements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        return super.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    // let javadoc show doc from superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public String getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        return super.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    private void checkInitialized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            throw new IllegalStateException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    private void check(String directive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            security.checkSecurityAccess(directive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    // legacy properties changed since last call to any services method?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    private transient boolean legacyChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    // serviceMap changed since last call to getServices()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    private transient boolean servicesChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    // Map<String,String>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    private transient Map<String,String> legacyStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    // Map<ServiceKey,Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    // used for services added via putService(), initialized on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    private transient Map<ServiceKey,Service> serviceMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    // Map<ServiceKey,Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    // used for services added via legacy methods, init on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    private transient Map<ServiceKey,Service> legacyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    // Set<Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    // Unmodifiable set of all services. Initialized on demand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    private transient Set<Service> serviceSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    // register the id attributes for this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    // this is to ensure that equals() and hashCode() do not incorrectly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    // report to different provider objects as the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    private void putId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        // note: name and info may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        super.put("Provider.id name", String.valueOf(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        super.put("Provider.id version", String.valueOf(version));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        super.put("Provider.id info", String.valueOf(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        super.put("Provider.id className", this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                throws IOException, ClassNotFoundException {
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   695
        Map<Object,Object> copy = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        for (Map.Entry<Object,Object> entry : super.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            copy.put(entry.getKey(), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        defaults = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        implClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        putAll(copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   706
    private boolean checkLegacy(Object key) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   707
        String keyString = (String)key;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   708
        if (keyString.startsWith("Provider.")) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   709
            return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   710
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   711
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   712
        legacyChanged = true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   713
        if (legacyStrings == null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   714
            legacyStrings = new LinkedHashMap<String,String>();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   715
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   716
        return true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   717
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   718
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Copies all of the mappings from the specified Map to this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Internal method to be called AFTER the security check has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   724
    private void implPutAll(Map<?,?> t) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   725
        for (Map.Entry<?,?> e : t.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            implPut(e.getKey(), e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    private Object implRemove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (key instanceof String) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   732
            if (!checkLegacy(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   735
            legacyStrings.remove((String)key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return super.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   740
    private boolean implRemove(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   741
        if (key instanceof String && value instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   742
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   743
                return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   744
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   745
            legacyStrings.remove((String)key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   746
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   747
        return super.remove(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   748
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   749
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   750
    private boolean implReplace(Object key, Object oldValue, Object newValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   751
        if ((key instanceof String) && (oldValue instanceof String) &&
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   752
                (newValue instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   753
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   754
                return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   755
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   756
            legacyStrings.replace((String)key, (String)oldValue,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   757
                    (String)newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   758
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   759
        return super.replace(key, oldValue, newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   760
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   761
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   762
    private Object implReplace(Object key, Object value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if ((key instanceof String) && (value instanceof String)) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   764
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   765
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   766
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   767
            legacyStrings.replace((String)key, (String)value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   768
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   769
        return super.replace(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   770
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   771
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   772
    @SuppressWarnings("unchecked") // Function must actually operate over strings
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   773
    private void implReplaceAll(BiFunction<? super Object, ? super Object, ? extends Object> function) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   774
        legacyChanged = true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   775
        if (legacyStrings == null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   776
            legacyStrings = new LinkedHashMap<String,String>();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   777
        } else {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   778
            legacyStrings.replaceAll((BiFunction<? super String, ? super String, ? extends String>) function);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   779
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   780
        super.replaceAll(function);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   781
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   782
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   783
    @SuppressWarnings("unchecked") // Function must actually operate over strings
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   784
    private Object implMerge(Object key, Object value, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   785
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   786
            if (!checkLegacy(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   789
            legacyStrings.merge((String)key, (String)value,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   790
                    (BiFunction<? super String, ? super String, ? extends String>) remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   791
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   792
        return super.merge(key, value, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   793
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   794
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   795
    @SuppressWarnings("unchecked") // Function must actually operate over strings
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   796
    private Object implCompute(Object key, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   797
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   798
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   799
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   800
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   801
            legacyStrings.computeIfAbsent((String) key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   802
                    (Function<? super String, ? extends String>) remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   803
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   804
        return super.compute(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   805
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   806
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   807
    @SuppressWarnings("unchecked") // Function must actually operate over strings
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   808
    private Object implComputeIfAbsent(Object key, Function<? super Object, ? extends Object> mappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   809
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   810
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   811
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   813
            legacyStrings.computeIfAbsent((String) key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   814
                    (Function<? super String, ? extends String>) mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   815
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   816
        return super.computeIfAbsent(key, mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   817
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   818
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   819
    @SuppressWarnings("unchecked") // Function must actually operate over strings
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   820
    private Object implComputeIfPresent(Object key, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   821
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   822
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   823
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   824
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   825
            legacyStrings.computeIfPresent((String) key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   826
                    (BiFunction<? super String, ? super String, ? extends String>) remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   827
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   828
        return super.computeIfPresent(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   829
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   830
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   831
    private Object implPut(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   832
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   833
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   834
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   835
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   836
            legacyStrings.put((String)key, (String)value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        return super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   841
    private Object implPutIfAbsent(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   842
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   843
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   844
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   845
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   846
            legacyStrings.putIfAbsent((String)key, (String)value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   847
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   848
        return super.putIfAbsent(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   849
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   850
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    private void implClear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (legacyStrings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            legacyStrings.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (legacyMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            legacyMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            serviceMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        legacyChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        servicesChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        super.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        putId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    // used as key in the serviceMap and legacyMap HashMaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    private static class ServiceKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        private final String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        private final String originalAlgorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        private ServiceKey(String type, String algorithm, boolean intern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            this.originalAlgorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            algorithm = algorithm.toUpperCase(ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            this.algorithm = intern ? algorithm.intern() : algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            return type.hashCode() + algorithm.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            if (obj instanceof ServiceKey == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            ServiceKey other = (ServiceKey)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            return this.type.equals(other.type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                && this.algorithm.equals(other.algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        boolean matches(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            return (this.type == type) && (this.originalAlgorithm == algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * Ensure all the legacy String properties are fully parsed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * service objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    private void ensureLegacyParsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        if ((legacyChanged == false) || (legacyStrings == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (legacyMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            legacyMap = new LinkedHashMap<ServiceKey,Service>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            legacyMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        for (Map.Entry<String,String> entry : legacyStrings.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            parseLegacyPut(entry.getKey(), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        removeInvalidServices(legacyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        legacyChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Remove all invalid services from the Map. Invalid services can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * occur if the legacy properties are inconsistent or incomplete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    private void removeInvalidServices(Map<ServiceKey,Service> map) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   924
        for (Iterator<Map.Entry<ServiceKey, Service>> t =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   925
                map.entrySet().iterator(); t.hasNext(); ) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   926
            Service s = t.next().getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            if (s.isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                t.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    private String[] getTypeAndAlgorithm(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int i = key.indexOf(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (i < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                debug.println("Ignoring invalid entry in provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                        + name + ":" + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        String type = key.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        String alg = key.substring(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        return new String[] {type, alg};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    private final static String ALIAS_PREFIX = "Alg.Alias.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    private final static String ALIAS_PREFIX_LOWER = "alg.alias.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    private final static int ALIAS_LENGTH = ALIAS_PREFIX.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    private void parseLegacyPut(String name, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (name.toLowerCase(ENGLISH).startsWith(ALIAS_PREFIX_LOWER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            // e.g. put("Alg.Alias.MessageDigest.SHA", "SHA-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            // aliasKey ~ MessageDigest.SHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            String stdAlg = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            String aliasKey = name.substring(ALIAS_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            String[] typeAndAlg = getTypeAndAlgorithm(aliasKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (typeAndAlg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            String aliasAlg = typeAndAlg[1].intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            legacyMap.put(new ServiceKey(type, aliasAlg, true), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            s.addAlias(aliasAlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            String[] typeAndAlg = getTypeAndAlgorithm(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (typeAndAlg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            int i = typeAndAlg[1].indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                // e.g. put("MessageDigest.SHA-1", "sun.security.provider.SHA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                String stdAlg = typeAndAlg[1].intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                String className = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                s.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            } else { // attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                // e.g. put("MessageDigest.SHA-1 ImplementedIn", "Software");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                String attributeValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                String attributeString = typeAndAlg[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                String stdAlg = attributeString.substring(0, i).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                String attributeName = attributeString.substring(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                // kill additional spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                while (attributeName.startsWith(" ")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    attributeName = attributeName.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                attributeName = attributeName.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                s.addAttribute(attributeName, attributeValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * Get the service describing this Provider's implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * specified type of this algorithm or alias. If no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * implementation exists, this method returns null. If there are two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * matching services, one added to this provider using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * {@link #putService putService()} and one added via {@link #put put()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * the service added via {@link #putService putService()} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @param type the type of {@link Service service} requested
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1027
     * (for example, {@code MessageDigest})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @param algorithm the case insensitive algorithm name (or alternate
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1029
     * alias) of the service requested (for example, {@code SHA-1})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @return the service describing this Provider's matching service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * or null if no such service exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @throws NullPointerException if type or algorithm is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    public synchronized Service getService(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        // avoid allocating a new key object if possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        ServiceKey key = previousKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        if (key.matches(type, algorithm) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            key = new ServiceKey(type, algorithm, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            previousKey = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            Service service = serviceMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                return service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        ensureLegacyParsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        return (legacyMap != null) ? legacyMap.get(key) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    // ServiceKey from previous getService() call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    // by re-using it if possible we avoid allocating a new object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    // and the toUpperCase() call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    // re-use will occur e.g. as the framework traverses the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    // list and queries each provider with the same values until it finds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    // a matching service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    private static volatile ServiceKey previousKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                            new ServiceKey("", "", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * Get an unmodifiable Set of all services supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * this Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @return an unmodifiable Set of all services supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * this Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    public synchronized Set<Service> getServices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        if (legacyChanged || servicesChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (serviceSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            ensureLegacyParsed();
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
  1081
            Set<Service> set = new LinkedHashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                set.addAll(serviceMap.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if (legacyMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                set.addAll(legacyMap.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            serviceSet = Collections.unmodifiableSet(set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            servicesChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        return serviceSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * Add a service. If a service of the same type with the same algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * name exists and it was added using {@link #putService putService()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * it is replaced by the new service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * This method also places information about this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * in the provider's Hashtable values in the format described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Java Cryptography Architecture API Specification &amp; Reference </a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * <p>Also, if there is a security manager, its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1104
     * {@code checkSecurityAccess} method is called with the string
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1105
     * {@code "putProviderProperty."+name}, where {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * the provider name, to see if it's ok to set this provider's property
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1107
     * values. If the default implementation of {@code checkSecurityAccess}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * is used (that is, that method is not overriden), then this results in
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1109
     * a call to the security manager's {@code checkPermission} method with
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1110
     * a {@code SecurityPermission("putProviderProperty."+name)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @param s the Service to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @throws SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1116
     *      if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1117
     *      java.lang.SecurityManager#checkSecurityAccess} method denies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *      access to set property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @throws NullPointerException if s is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    protected synchronized void putService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        check("putProviderProperty." + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            debug.println(name + ".putService(): " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        if (s.getProvider() != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                    ("service.getProvider() must match this Provider object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        if (serviceMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            serviceMap = new LinkedHashMap<ServiceKey,Service>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        servicesChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        ServiceKey key = new ServiceKey(type, algorithm, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        // remove existing service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        implRemoveService(serviceMap.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        serviceMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            serviceMap.put(new ServiceKey(type, alias, true), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        putPropertyStrings(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * Put the string properties for this Service in this Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    private void putPropertyStrings(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        // use super() to avoid permission check and other processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        super.put(type + "." + algorithm, s.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            super.put(ALIAS_PREFIX + type + "." + alias, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        for (Map.Entry<UString,String> entry : s.attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            String key = type + "." + algorithm + " " + entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            super.put(key, entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * Remove the string properties for this Service from this Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    private void removePropertyStrings(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        // use super() to avoid permission check and other processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        super.remove(type + "." + algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            super.remove(ALIAS_PREFIX + type + "." + alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        for (Map.Entry<UString,String> entry : s.attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            String key = type + "." + algorithm + " " + entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            super.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * Remove a service previously added using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * {@link #putService putService()}. The specified service is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * this provider. It will no longer be returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * {@link #getService getService()} and its information will be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * from this provider's Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * <p>Also, if there is a security manager, its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1195
     * {@code checkSecurityAccess} method is called with the string
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1196
     * {@code "removeProviderProperty."+name}, where {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * the provider name, to see if it's ok to remove this provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * properties. If the default implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1199
     * {@code checkSecurityAccess} is used (that is, that method is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * overriden), then this results in a call to the security manager's
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1201
     * {@code checkPermission} method with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1202
     * {@code SecurityPermission("removeProviderProperty."+name)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @param s the Service to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1208
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1209
     *          java.lang.SecurityManager#checkSecurityAccess} method denies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *          access to remove this provider's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @throws NullPointerException if s is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    protected synchronized void removeService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        check("removeProviderProperty." + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            debug.println(name + ".removeService(): " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        implRemoveService(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    private void implRemoveService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        if ((s == null) || (serviceMap == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        ServiceKey key = new ServiceKey(type, algorithm, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        Service oldService = serviceMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        if (s != oldService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        servicesChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        serviceMap.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            serviceMap.remove(new ServiceKey(type, alias, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        removePropertyStrings(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    // Wrapped String that behaves in a case insensitive way for equals/hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    private static class UString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        final String string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        final String lowerString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        UString(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            this.string = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            this.lowerString = s.toLowerCase(ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            return lowerString.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            if (obj instanceof UString == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            UString other = (UString)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            return lowerString.equals(other.lowerString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    // describe relevant properties of a type of engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    private static class EngineDescription {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        final boolean supportsParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        final String constructorParameterClassName;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1280
        private volatile Class<?> constructorParameterClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        EngineDescription(String name, boolean sp, String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            this.supportsParameter = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            this.constructorParameterClassName = paramName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1287
        Class<?> getConstructorParameterClass() throws ClassNotFoundException {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1288
            Class<?> clazz = constructorParameterClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                clazz = Class.forName(constructorParameterClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                constructorParameterClass = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    // built in knowledge of the engine types shipped as part of the JDK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    private static final Map<String,EngineDescription> knownEngines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    private static void addEngine(String name, boolean sp, String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        EngineDescription ed = new EngineDescription(name, sp, paramName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        // also index by canonical name to avoid toLowerCase() for some lookups
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        knownEngines.put(name.toLowerCase(ENGLISH), ed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        knownEngines.put(name, ed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        knownEngines = new HashMap<String,EngineDescription>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        // JCA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        addEngine("AlgorithmParameterGenerator",        false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        addEngine("AlgorithmParameters",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        addEngine("KeyFactory",                         false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        addEngine("KeyPairGenerator",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        addEngine("KeyStore",                           false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        addEngine("MessageDigest",                      false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        addEngine("SecureRandom",                       false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        addEngine("Signature",                          true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        addEngine("CertificateFactory",                 false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        addEngine("CertPathBuilder",                    false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        addEngine("CertPathValidator",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        addEngine("CertStore",                          false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                            "java.security.cert.CertStoreParameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        // JCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        addEngine("Cipher",                             true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        addEngine("ExemptionMechanism",                 false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        addEngine("Mac",                                true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        addEngine("KeyAgreement",                       true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        addEngine("KeyGenerator",                       false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        addEngine("SecretKeyFactory",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        // JSSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        addEngine("KeyManagerFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        addEngine("SSLContext",                         false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        addEngine("TrustManagerFactory",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        // JGSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        addEngine("GssApiMechanism",                    false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        // SASL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        addEngine("SaslClientFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        addEngine("SaslServerFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        // POLICY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        addEngine("Policy",                             false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                            "java.security.Policy$Parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        // CONFIGURATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        addEngine("Configuration",                      false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                            "javax.security.auth.login.Configuration$Parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        // XML DSig
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        addEngine("XMLSignatureFactory",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        addEngine("KeyInfoFactory",                     false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        addEngine("TransformService",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        // Smart Card I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        addEngine("TerminalFactory",                    false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                            "java.lang.Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    // get the "standard" (mixed-case) engine name for arbitary case engine name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    // if there is no known engine by that name, return s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    private static String getEngineName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        // try original case first, usually correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        EngineDescription e = knownEngines.get(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            e = knownEngines.get(s.toLowerCase(ENGLISH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        return (e == null) ? s : e.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * The description of a security service. It encapsulates the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * of a service and contains a factory method to obtain new implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * instances of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * <p>Each service has a provider that offers the service, a type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * an algorithm name, and the name of the class that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * service. Optionally, it also includes a list of alternate algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * names for this service (aliases) and attributes, which are a map of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * (name, value) String pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * <p>This class defines the methods {@link #supportsParameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * supportsParameter()} and {@link #newInstance newInstance()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * which are used by the Java security framework when it searches for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * suitable services and instantes them. The valid arguments to those
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * methods depend on the type of service. For the service types defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * within Java SE, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * for the valid values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * Note that components outside of Java SE can define additional types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * services and their behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * <p>Instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    public static class Service {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        private String type, algorithm, className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        private final Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        private List<String> aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        private Map<UString,String> attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        // Reference to the cached implementation Class object
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1400
        private volatile Reference<Class<?>> classRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        // flag indicating whether this service has its attributes for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        // supportedKeyFormats or supportedKeyClasses set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        // if null, the values have not been initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        // if TRUE, at least one of supportedFormats/Classes is non null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        private volatile Boolean hasKeyAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        // supported encoding formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        private String[] supportedFormats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        // names of the supported key (super) classes
22117
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21979
diff changeset
  1412
        private Class<?>[] supportedClasses;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        // whether this service has been registered with the Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        private boolean registered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1417
        private static final Class<?>[] CLASS0 = new Class<?>[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        // this constructor and these methods are used for parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        // the legacy string properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        private Service(Provider provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            aliases = Collections.<String>emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            attributes = Collections.<UString,String>emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        private boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            return (type != null) && (algorithm != null) && (className != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        private void addAlias(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            if (aliases.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                aliases = new ArrayList<String>(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            aliases.add(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        void addAttribute(String type, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            if (attributes.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                attributes = new HashMap<UString,String>(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            attributes.put(new UString(type), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
         * Construct a new service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
         * @param provider the provider that offers this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
         * @param type the type of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
         * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
         * @param className the name of the class implementing this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * @param aliases List of aliases or null if algorithm has no aliases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         * @param attributes Map of attributes or null if this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
         *                   has no attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
         * @throws NullPointerException if provider, type, algorithm, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
         * className is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        public Service(Provider provider, String type, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                String className, List<String> aliases,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                Map<String,String> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            if ((provider == null) || (type == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                    (algorithm == null) || (className == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            this.type = getEngineName(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            if (aliases == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                this.aliases = Collections.<String>emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                this.aliases = new ArrayList<String>(aliases);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                this.attributes = Collections.<UString,String>emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                this.attributes = new HashMap<UString,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                for (Map.Entry<String,String> entry : attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                    this.attributes.put(new UString(entry.getKey()), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1487
         * Get the type of this service. For example, {@code MessageDigest}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
         * @return the type of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
         * Return the name of the algorithm of this service. For example,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1497
         * {@code SHA-1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
         * @return the algorithm of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            return algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         * Return the Provider of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         * @return the Provider of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         * Return the name of the class implementing this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
         * @return the name of the class implementing this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        public final String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        // internal only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        private final List<String> getAliases() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            return aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         * Return the value of the specified attribute or null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         * attribute is not set for this Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         * @param name the name of the requested attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * @return the value of the specified attribute or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         *         attribute is not present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
         * @throws NullPointerException if name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        public final String getAttribute(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            return attributes.get(new UString(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * Return a new instance of the implementation described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         * service. The security provider framework uses this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         * construct implementations. Applications will typically not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
         * to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
         * <p>The default implementation uses reflection to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
         * standard constructor for this type of service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
         * Security providers can override this method to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
         * instantiation in a different way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
         * For details and the values of constructorParameter that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
         * valid for the various types of services see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         * Java Cryptography Architecture API Specification &amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         * Reference</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         * @param constructorParameter the value to pass to the constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
         * or null if this type of service does not use a constructorParameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
         * @return a new implementation of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
         * @throws InvalidParameterException if the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * constructorParameter is invalid for this type of service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * @throws NoSuchAlgorithmException if instantation failed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         * any other reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        public Object newInstance(Object constructorParameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            if (registered == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                if (provider.getService(type, algorithm) != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                        ("Service not registered with Provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                        + provider.getName() + ": " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                registered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                EngineDescription cap = knownEngines.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                if (cap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    // unknown engine type, use generic code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                    // this is the code path future for non-core
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    // optional packages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                    return newInstanceGeneric(constructorParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                if (cap.constructorParameterClassName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                    if (constructorParameter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                        throw new InvalidParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                            ("constructorParameter not used with " + type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                            + " engines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                    }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1596
                    Class<?> clazz = getImplClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    return clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1599
                    Class<?> paramClass = cap.getConstructorParameterClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    if (constructorParameter != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1601
                        Class<?> argClass = constructorParameter.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                        if (paramClass.isAssignableFrom(argClass) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                            throw new InvalidParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                            ("constructorParameter must be instanceof "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                            + cap.constructorParameterClassName.replace('$', '.')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                            + " for engine type " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                    }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1609
                    Class<?> clazz = getImplClass();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1610
                    Constructor<?> cons = clazz.getConstructor(paramClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                    return cons.newInstance(constructorParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    ("Error constructing implementation (algorithm: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                    + algorithm + ", provider: " + provider.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                    + ", class: " + className + ")", e.getCause());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                    ("Error constructing implementation (algorithm: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    + algorithm + ", provider: " + provider.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    + ", class: " + className + ")", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        // return the implementation Class object for this service
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1629
        private Class<?> getImplClass() throws NoSuchAlgorithmException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1631
                Reference<Class<?>> ref = classRef;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1632
                Class<?> clazz = (ref == null) ? null : ref.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                    ClassLoader cl = provider.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                    if (cl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                        clazz = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                        clazz = cl.loadClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1640
                    classRef = new WeakReference<Class<?>>(clazz);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                    ("class configured for " + type + "(provider: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                    provider.getName() + ")" + "cannot be found.", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
         * Generic code path for unknown engine types. Call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
         * no-args constructor if constructorParameter is null, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
         * use the first matching constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        private Object newInstanceGeneric(Object constructorParameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                throws Exception {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1657
            Class<?> clazz = getImplClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            if (constructorParameter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                Object o = clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1662
            Class<?> argClass = constructorParameter.getClass();
22117
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21979
diff changeset
  1663
            Constructor<?>[] cons = clazz.getConstructors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            // find first public constructor that can take the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            // argument as parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            for (int i = 0; i < cons.length; i++) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1667
                Constructor<?> con = cons[i];
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1668
                Class<?>[] paramTypes = con.getParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                if (paramTypes.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                if (paramTypes[0].isAssignableFrom(argClass) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                Object o = con.newInstance(new Object[] {constructorParameter});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            throw new NoSuchAlgorithmException("No constructor matching "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                + argClass.getName() + " found in class " + className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
         * Test whether this Service can use the specified parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
         * Returns false if this service cannot use the parameter. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
         * true if this service can use the parameter, if a fast test is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
         * infeasible, or if the status is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
         * <p>The security provider framework uses this method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
         * some types of services to quickly exclude non-matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
         * implementations for consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
         * Applications will typically not need to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
         * <p>For details and the values of parameter that are valid for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
         * various types of services see the top of this class and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
         * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
         * Java Cryptography Architecture API Specification &amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
         * Reference</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
         * Security providers can override it to implement their own test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
         * @param parameter the parameter to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
         * @return false if this this service cannot use the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
         * parameter; true if it can possibly use the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
         * @throws InvalidParameterException if the value of parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
         * invalid for this type of service or if this method cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
         * used with this type of service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        public boolean supportsParameter(Object parameter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            EngineDescription cap = knownEngines.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            if (cap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                // unknown engine type, return true by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            if (cap.supportsParameter == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                throw new InvalidParameterException("supportsParameter() not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                    + "used with " + type + " engines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            // allow null for keys without attributes for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            if ((parameter != null) && (parameter instanceof Key == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                throw new InvalidParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                    ("Parameter must be instanceof Key for engine " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            if (hasKeyAttributes() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            if (parameter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            Key key = (Key)parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            if (supportsKeyFormat(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            if (supportsKeyClass(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
         * Return whether this service has its Supported* properties for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
         * keys defined. Parses the attributes if not yet initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        private boolean hasKeyAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            Boolean b = hasKeyAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                    String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                    s = getAttribute("SupportedKeyFormats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                    if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                        supportedFormats = s.split("\\|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                    s = getAttribute("SupportedKeyClasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                    if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                        String[] classNames = s.split("\\|");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1756
                        List<Class<?>> classList =
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
  1757
                            new ArrayList<>(classNames.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                        for (String className : classNames) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1759
                            Class<?> clazz = getKeyClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                            if (clazz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                                classList.add(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                        supportedClasses = classList.toArray(CLASS0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                    boolean bool = (supportedFormats != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                        || (supportedClasses != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    b = Boolean.valueOf(bool);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                    hasKeyAttributes = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            return b.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        // get the key class object of the specified name
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1776
        private Class<?> getKeyClass(String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                return Class.forName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                ClassLoader cl = provider.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    return cl.loadClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        private boolean supportsKeyFormat(Key key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            if (supportedFormats == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            String format = key.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            for (String supportedFormat : supportedFormats) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                if (supportedFormat.equals(format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        private boolean supportsKeyClass(Key key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            if (supportedClasses == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1813
            Class<?> keyClass = key.getClass();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1814
            for (Class<?> clazz : supportedClasses) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                if (clazz.isAssignableFrom(keyClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
         * Return a String representation of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
         * @return a String representation of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            String aString = aliases.isEmpty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                ? "" : "\r\n  aliases: " + aliases.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            String attrs = attributes.isEmpty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                ? "" : "\r\n  attributes: " + attributes.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            return provider.getName() + ": " + type + "." + algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                + " -> " + className + aString + attrs + "\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
}