jdk/src/share/classes/sun/security/jca/Providers.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7973 dffe8439eb20
child 10336 0bb1999251f8
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7973
diff changeset
     2
 * Copyright (c) 2003, 2011, 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: 4152
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: 4152
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: 4152
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
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 sun.security.jca;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Collection of methods to get and set provider list. Also includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * special code for the provider list during JAR verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class Providers {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final ThreadLocal<ProviderList> threadLists =
7973
dffe8439eb20 7005608: diamond conversion of JCA and crypto providers
smarks
parents: 7668
diff changeset
    43
        new InheritableThreadLocal<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    // number of threads currently using thread-local provider lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // tracked to allow an optimization if == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static volatile int threadListsUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // current system-wide provider list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // Note volatile immutable object, so no synchronization needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static volatile ProviderList providerList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        // set providerList to empty list first in case initialization somehow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        // triggers a getInstance() call (although that should not happen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        providerList = ProviderList.EMPTY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        providerList = ProviderList.fromSecurityProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Providers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // we need special handling to resolve circularities when loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // signed JAR files during startup. The code below is part of that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Basically, before we load data from a signed JAR file, we parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // the PKCS#7 file and verify the signature. We need a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // CertificateFactory, Signatures, etc. to do that. We have to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // sure that we do not try to load the implementation from the JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // file we are just verifying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // To avoid that, we use different provider settings during JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // verification.  However, we do not want those provider settings to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // interfere with other parts of the system. Therefore, we make them local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // to the Thread executing the JAR verification code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // The code here is used by sun.security.util.SignatureFileVerifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // See there for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final String BACKUP_PROVIDER_CLASSNAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        "sun.security.provider.VerificationProvider";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Hardcoded classnames of providers to use for JAR verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // MUST NOT be on the bootclasspath and not in signed JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final String[] jarVerificationProviders = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        "sun.security.provider.Sun",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        "sun.security.rsa.SunRsaSign",
4152
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 2
diff changeset
    89
        // Note: SunEC *is* in a signed JAR file, but it's not signed
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 2
diff changeset
    90
        // by EC itself. So it's still safe to be listed here.
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 2
diff changeset
    91
        "sun.security.ec.SunEC",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        BACKUP_PROVIDER_CLASSNAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Return to Sun provider or its backup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // This method should only be called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // sun.security.util.ManifestEntryVerifier and java.security.SecureRandom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static Provider getSunProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            Class clazz = Class.forName(jarVerificationProviders[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return (Provider)clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                Class clazz = Class.forName(BACKUP_PROVIDER_CLASSNAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                return (Provider)clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                throw new RuntimeException("Sun provider not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Start JAR verification. This sets a special provider list for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * the current thread. You MUST save the return value from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * method and you MUST call stopJarVerification() with that object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * once you are done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static Object startJarVerification() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        ProviderList currentList = getProviderList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        ProviderList jarList = currentList.getJarList(jarVerificationProviders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // return the old thread-local provider list, usually null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return beginThreadProviderList(jarList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Stop JAR verification. Call once you have completed JAR verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static void stopJarVerification(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // restore old thread-local provider list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        endThreadProviderList((ProviderList)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Return the current ProviderList. If the thread-local list is set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * it is returned. Otherwise, the system wide list is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static ProviderList getProviderList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        ProviderList list = getThreadProviderList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            list = getSystemProviderList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Set the current ProviderList. Affects the thread-local list if set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * otherwise the system wide list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static void setProviderList(ProviderList newList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (getThreadProviderList() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            setSystemProviderList(newList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            changeThreadProviderList(newList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Get the full provider list with invalid providers (those that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * could not be loaded) removed. This is the list we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * present to applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
6895
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   162
    public static ProviderList getFullProviderList() {
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   163
        ProviderList list;
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   164
        synchronized (Providers.class) {
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   165
            list = getThreadProviderList();
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   166
            if (list != null) {
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   167
                ProviderList newList = list.removeInvalid();
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   168
                if (newList != list) {
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   169
                    changeThreadProviderList(newList);
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   170
                    list = newList;
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   171
                }
92894a4882e0 6850402: Deadlock on sun.security.jca.ProviderConfig starting from jdk7-b55
valeriep
parents: 5506
diff changeset
   172
                return list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        list = getSystemProviderList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        ProviderList newList = list.removeInvalid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (newList != list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            setSystemProviderList(newList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            list = newList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static ProviderList getSystemProviderList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return providerList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private static void setSystemProviderList(ProviderList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        providerList = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static ProviderList getThreadProviderList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // avoid accessing the threadlocal if none are currently in use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // (first use of ThreadLocal.get() for a Thread allocates a Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (threadListsUsed == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return threadLists.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // Change the thread local provider list. Use only if the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // is already using a thread local list and you want to change it in place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // In other cases, use the begin/endThreadProviderList() methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    private static void changeThreadProviderList(ProviderList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        threadLists.set(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Methods to manipulate the thread local provider list. It is for use by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * JAR verification (see above) and the SunJSSE FIPS mode only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * It should be used as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *   ProviderList list = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *   ProviderList oldList = Providers.beginThreadProviderList(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *   try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *     // code that needs thread local provider list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *   } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *     Providers.endThreadProviderList(oldList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static synchronized ProviderList beginThreadProviderList(ProviderList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (ProviderList.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            ProviderList.debug.println("ThreadLocal providers: " + list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        ProviderList oldList = threadLists.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        threadListsUsed++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        threadLists.set(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return oldList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public static synchronized void endThreadProviderList(ProviderList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (ProviderList.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                ProviderList.debug.println("Disabling ThreadLocal providers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            threadLists.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (ProviderList.debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                ProviderList.debug.println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    ("Restoring previous ThreadLocal providers: " + list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            threadLists.set(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        threadListsUsed--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}