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