src/java.xml.bind/share/classes/javax/xml/bind/ServiceLoaderUtil.java
author lana
Fri, 15 Dec 2017 16:38:40 +0000
changeset 48369 8647aa05d094
parent 47216 71c04702a3d5
permissions -rw-r--r--
Added tag jdk-10+36 for changeset cb54a299aa91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     1
/*
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     4
 *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    10
 *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    15
 * accompanied this code).
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    16
 *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    20
 *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    23
 * questions.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    24
 */
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    25
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    26
package javax.xml.bind;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    27
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    29
import java.lang.reflect.Method;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    30
import java.util.Iterator;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    31
import java.util.ServiceLoader;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    32
import java.util.logging.Level;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    33
import java.util.logging.Logger;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    34
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    35
/**
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    36
 * Shared ServiceLoader/FactoryFinder Utils shared among SAAJ, JAXB and JAXWS
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    37
 * - this class must be duplicated to all those projects, but it's
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    38
 * basically generic code and we want to have it everywhere same.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    39
 *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    40
 * @author Miroslav.Kos@oracle.com
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    41
 */
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    42
class ServiceLoaderUtil {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    43
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    44
    private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "com.sun.org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    45
    private static final String OSGI_SERVICE_LOADER_METHOD_NAME = "lookupProviderClasses";
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    46
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    47
    static <P, T extends Exception> P firstByServiceLoader(Class<P> spiClass,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    48
                                                           Logger logger,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    49
                                                           ExceptionHandler<T> handler) throws T {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    50
        // service discovery
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    51
        try {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    52
            ServiceLoader<P> serviceLoader = ServiceLoader.load(spiClass);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    53
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    54
            for (P impl : serviceLoader) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    55
                logger.fine("ServiceProvider loading Facility used; returning object [" +
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    56
                        impl.getClass().getName() + "]");
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    57
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    58
                return impl;
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    59
            }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    60
        } catch (Throwable t) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    61
            throw handler.createException(t, "Error while searching for service [" + spiClass.getName() + "]");
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    62
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    63
        return null;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    64
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    65
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    66
    static Object lookupUsingOSGiServiceLoader(String factoryId, Logger logger) {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    67
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    68
        try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    69
            // Use reflection to avoid having any dependendcy on ServiceLoader class
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    70
            Class serviceClass = Class.forName(factoryId);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    71
            Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    72
            Method m = target.getMethod(OSGI_SERVICE_LOADER_METHOD_NAME, Class.class);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    73
            Iterator iter = ((Iterable) m.invoke(null, serviceClass)).iterator();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    74
            if (iter.hasNext()) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    75
                Object next = iter.next();
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    76
                logger.fine("Found implementation using OSGi facility; returning object [" +
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    77
                        next.getClass().getName() + "].");
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    78
                return next;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    79
            } else {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    80
                return null;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    81
            }
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    82
        } catch (IllegalAccessException |
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    83
                InvocationTargetException |
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    84
                ClassNotFoundException |
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    85
                NoSuchMethodException ignored) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    86
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    87
            logger.log(Level.FINE, "Unable to find from OSGi: [" + factoryId + "]", ignored);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    88
            return null;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    89
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    90
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    91
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    92
    static void checkPackageAccess(String className) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    93
        // make sure that the current thread has an access to the package of the given name.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    94
        SecurityManager s = System.getSecurityManager();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    95
        if (s != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    96
            int i = className.lastIndexOf('.');
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    97
            if (i != -1) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    98
                s.checkPackageAccess(className.substring(0, i));
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
    99
            }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   100
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   101
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   102
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   103
    static Class nullSafeLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   104
        if (classLoader == null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   105
            return Class.forName(className);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   106
        } else {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   107
            return classLoader.loadClass(className);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   108
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   109
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   110
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   111
    // Returns instance of required class. It checks package access (security)
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   112
    // unless it is defaultClassname. It means if you are trying to instantiate
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   113
    // default implementation (fallback), pass the class name to both first and second parameter.
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   114
    static <T extends Exception> Object newInstance(String className,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   115
                                                    String defaultImplClassName,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   116
                                                    final ExceptionHandler<T> handler) throws T {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   117
        try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   118
            return safeLoadClass(className, defaultImplClassName, contextClassLoader(handler)).newInstance();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   119
        } catch (ClassNotFoundException x) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   120
            throw handler.createException(x, "Provider " + className + " not found");
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   121
        } catch (Exception x) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   122
            throw handler.createException(x, "Provider " + className + " could not be instantiated: " + x);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   123
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   124
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   125
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   126
    static Class safeLoadClass(String className,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   127
                               String defaultImplClassName,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   128
                               ClassLoader classLoader) throws ClassNotFoundException {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   129
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   130
        try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   131
            checkPackageAccess(className);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   132
        } catch (SecurityException se) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   133
            // anyone can access the platform default factory class without permission
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   134
            if (defaultImplClassName != null && defaultImplClassName.equals(className)) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   135
                return Class.forName(className);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   136
            }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   137
            // not platform default implementation ...
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   138
            throw se;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   139
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   140
        return nullSafeLoadClass(className, classLoader);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   141
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   142
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   143
    static ClassLoader contextClassLoader(ExceptionHandler exceptionHandler) throws Exception {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   144
        try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   145
            return Thread.currentThread().getContextClassLoader();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   146
        } catch (Exception x) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   147
            throw exceptionHandler.createException(x, x.toString());
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   148
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   149
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   150
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   151
    static abstract class ExceptionHandler<T extends Exception> {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   152
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   153
        public abstract T createException(Throwable throwable, String message);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   154
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   155
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   156
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents:
diff changeset
   157
}