jaxws/src/java.xml.bind/share/classes/javax/xml/bind/ContextFinder.java
author lana
Thu, 11 Aug 2016 15:47:07 +0000
changeset 40243 225732b21228
parent 39173 68169040e394
child 43852 93a527059d8a
permissions -rw-r--r--
Added tag jdk-9+131 for changeset 2bf4f6d6a72f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     1
/*
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     4
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    10
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    15
 * accompanied this code).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    16
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    20
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    23
 * questions.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    24
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    25
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    26
package javax.xml.bind;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    27
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    28
import java.io.BufferedReader;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    29
import java.io.IOException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    30
import java.io.InputStream;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    31
import java.io.InputStreamReader;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    32
import java.lang.reflect.InvocationTargetException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    33
import java.lang.reflect.Method;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    34
import java.net.URL;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    35
import java.security.AccessController;
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
    36
import java.security.PrivilegedActionException;
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
    37
import java.security.PrivilegedExceptionAction;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    38
import java.util.Map;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    39
import java.util.Properties;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    40
import java.util.StringTokenizer;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    41
import java.util.logging.ConsoleHandler;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    42
import java.util.logging.Level;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    43
import java.util.logging.Logger;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    44
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    45
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    46
/**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    47
 * This class is package private and therefore is not exposed as part of the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    48
 * JAXB API.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    49
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    50
 * This code is designed to implement the JAXB 1.0 spec pluggability feature
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    51
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    52
 * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    53
 * @see JAXBContext
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    54
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    55
class ContextFinder {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    56
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    57
    /**
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    58
     * When JAXB is in J2SE, rt.jar has to have a JAXB implementation.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    59
     * However, rt.jar cannot have META-INF/services/javax.xml.bind.JAXBContext
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    60
     * because if it has, it will take precedence over any file that applications have
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    61
     * in their jar files.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    62
     *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    63
     * <p>
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    64
     * When the user bundles his own JAXB implementation, we'd like to use it, and we
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    65
     * want the platform default to be used only when there's no other JAXB provider.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    66
     *
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    67
     * <p>
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    68
     * For this reason, we have to hard-code the class name into the API.
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    69
     */
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    70
    private static final String PLATFORM_DEFAULT_FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory";
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    71
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    72
    // previous value of JAXBContext.JAXB_CONTEXT_FACTORY, using also this to ensure backwards compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    73
    private static final String JAXB_CONTEXT_FACTORY_DEPRECATED = "javax.xml.bind.context.factory";
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    74
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    75
    private static final Logger logger;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    76
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    77
    static {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    78
        logger = Logger.getLogger("javax.xml.bind");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    79
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    80
            if (AccessController.doPrivileged(new GetPropertyAction("jaxb.debug")) != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    81
                // disconnect the logger from a bigger framework (if any)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    82
                // and take the matters into our own hands
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    83
                logger.setUseParentHandlers(false);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    84
                logger.setLevel(Level.ALL);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    85
                ConsoleHandler handler = new ConsoleHandler();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    86
                handler.setLevel(Level.ALL);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    87
                logger.addHandler(handler);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    88
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    89
                // don't change the setting of this logger
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    90
                // to honor what other frameworks
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    91
                // have done on configurations.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    92
            }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
    93
        } catch (Throwable t) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    94
            // just to be extra safe. in particular System.getProperty may throw
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    95
            // SecurityException.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    96
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    97
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    98
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
    99
    private static ServiceLoaderUtil.ExceptionHandler<JAXBException> EXCEPTION_HANDLER =
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   100
            new ServiceLoaderUtil.ExceptionHandler<JAXBException>() {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   101
                @Override
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   102
                public JAXBException createException(Throwable throwable, String message) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   103
                    return new JAXBException(message, throwable);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   104
                }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   105
            };
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   106
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   107
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   108
     * If the {@link InvocationTargetException} wraps an exception that shouldn't be wrapped,
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   109
     * throw the wrapped exception. Otherwise returns exception to be wrapped for further processing.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   110
     */
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   111
    private static Throwable handleInvocationTargetException(InvocationTargetException x) throws JAXBException {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   112
        Throwable t = x.getTargetException();
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   113
        if (t != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   114
            if (t instanceof JAXBException)
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   115
                // one of our exceptions, just re-throw
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   116
                throw (JAXBException) t;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   117
            if (t instanceof RuntimeException)
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   118
                // avoid wrapping exceptions unnecessarily
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   119
                throw (RuntimeException) t;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   120
            if (t instanceof Error)
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   121
                throw (Error) t;
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   122
            return t;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   123
        }
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   124
        return x;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   125
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   126
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   127
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   128
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   129
     * Determine if two types (JAXBContext in this case) will generate a ClassCastException.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   130
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   131
     * For example, (targetType)originalType
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   132
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   133
     * @param originalType
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   134
     *          The Class object of the type being cast
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   135
     * @param targetType
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   136
     *          The Class object of the type that is being cast to
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   137
     * @return JAXBException to be thrown.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   138
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   139
    private static JAXBException handleClassCastException(Class originalType, Class targetType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   140
        final URL targetTypeURL = which(targetType);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   141
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   142
        return new JAXBException(Messages.format(Messages.ILLEGAL_CAST,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   143
                // we don't care where the impl class is, we want to know where JAXBContext lives in the impl
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   144
                // class' ClassLoader
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   145
                getClassClassLoader(originalType).getResource("javax/xml/bind/JAXBContext.class"),
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   146
                targetTypeURL));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   147
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   148
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   149
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   150
     * Create an instance of a class using the specified ClassLoader
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   151
     */
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   152
    static JAXBContext newInstance(String contextPath,
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   153
                                   String className,
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   154
                                   ClassLoader classLoader,
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   155
                                   Map properties) throws JAXBException {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   156
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   157
        try {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   158
            Class spFactory = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   159
            return newInstance(contextPath, spFactory, classLoader, properties);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   160
        } catch (ClassNotFoundException x) {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   161
            throw new JAXBException(Messages.format(Messages.PROVIDER_NOT_FOUND, className), x);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   162
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   163
        } catch (RuntimeException | JAXBException x) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   164
            // avoid wrapping RuntimeException to JAXBException,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   165
            // because it indicates a bug in this code.
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   166
            // JAXBException re-thrown as is
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   167
            throw x;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   168
        } catch (Exception x) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   169
            // can't catch JAXBException because the method is hidden behind
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   170
            // reflection.  Root element collisions detected in the call to
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   171
            // createContext() are reported as JAXBExceptions - just re-throw it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   172
            // some other type of exception - just wrap it
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   173
            throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, className, x), x);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   174
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   175
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   176
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   177
    static JAXBContext newInstance(String contextPath,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   178
                                   Class spFactory,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   179
                                   ClassLoader classLoader,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   180
                                   Map properties) throws JAXBException {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   181
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   182
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   183
            /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   184
             * javax.xml.bind.context.factory points to a class which has a
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   185
             * static method called 'createContext' that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   186
             * returns a javax.xml.JAXBContext.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   187
             */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   188
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   189
            Object context = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   190
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   191
            // first check the method that takes Map as the third parameter.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   192
            // this is added in 2.0.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   193
            try {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   194
                Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class, Map.class);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   195
                // any failure in invoking this method would be considered fatal
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   196
                Object obj = instantiateProviderIfNecessary(spFactory);
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   197
                context = m.invoke(obj, contextPath, classLoader, properties);
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   198
            } catch (NoSuchMethodException ignored) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   199
                // it's not an error for the provider not to have this method.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   200
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   201
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   202
            if (context == null) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   203
                // try the old method that doesn't take properties. compatible with 1.0.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   204
                // it is an error for an implementation not to have both forms of the createContext method.
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   205
                Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class);
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   206
                Object obj = instantiateProviderIfNecessary(spFactory);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   207
                // any failure in invoking this method would be considered fatal
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   208
                context = m.invoke(obj, contextPath, classLoader);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   209
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   210
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   211
            if (!(context instanceof JAXBContext)) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   212
                // the cast would fail, so generate an exception with a nice message
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   213
                throw handleClassCastException(context.getClass(), JAXBContext.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   214
            }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   215
            return (JAXBContext) context;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   216
        } catch (InvocationTargetException x) {
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   217
            // throw if it is exception not to be wrapped
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   218
            // otherwise, wrap with a JAXBException
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   219
            Throwable e = handleInvocationTargetException(x);
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   220
            throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, e), e);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   221
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   222
        } catch (Exception x) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   223
            // can't catch JAXBException because the method is hidden behind
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   224
            // reflection.  Root element collisions detected in the call to
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   225
            // createContext() are reported as JAXBExceptions - just re-throw it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   226
            // some other type of exception - just wrap it
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   227
            throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   228
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   229
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   230
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   231
    private static Object instantiateProviderIfNecessary(Class<?> implClass) throws JAXBException {
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   232
        try {
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   233
            if (JAXBContextFactory.class.isAssignableFrom(implClass)) {
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   234
                return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   235
                    @Override
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   236
                    public Object run() throws Exception {
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   237
                        return implClass.newInstance();
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   238
                    }
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   239
                });
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   240
            }
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   241
            return null;
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   242
        } catch (PrivilegedActionException x) {
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   243
            Throwable e = (x.getCause() == null) ? x : x.getCause();
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   244
            throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, implClass, e), e);
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   245
        }
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   246
    }
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   247
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   248
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   249
     * Create an instance of a class using the thread context ClassLoader
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   250
     */
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   251
    static JAXBContext newInstance(Class[] classes, Map properties, String className) throws JAXBException {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   252
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   253
        Class spi;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   254
        try {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   255
            spi = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, getContextClassLoader());
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   256
        } catch (ClassNotFoundException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   257
            throw new JAXBException(e);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   258
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   259
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   260
        if (logger.isLoggable(Level.FINE)) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   261
            // extra check to avoid costly which operation if not logged
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   262
            logger.log(Level.FINE, "loaded {0} from {1}", new Object[]{className, which(spi)});
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   263
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   264
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   265
        return newInstance(classes, properties, spi);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   266
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   267
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   268
    static JAXBContext newInstance(Class[] classes,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   269
                                   Map properties,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   270
                                   Class spFactory) throws JAXBException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   271
        try {
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   272
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   273
            Method m = spFactory.getMethod("createContext", Class[].class, Map.class);
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   274
            Object obj = instantiateProviderIfNecessary(spFactory);
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   275
            Object context = m.invoke(obj, classes, properties);
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   276
            if (!(context instanceof JAXBContext)) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   277
                // the cast would fail, so generate an exception with a nice message
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   278
                throw handleClassCastException(context.getClass(), JAXBContext.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   279
            }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   280
            return (JAXBContext) context;
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   281
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   282
        } catch (NoSuchMethodException | IllegalAccessException e) {
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   283
            throw new JAXBException(e);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   284
        } catch (InvocationTargetException e) {
35413
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   285
            // throw if it is exception not to be wrapped
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   286
            // otherwise, wrap with a JAXBException
56a695bbebe8 8145104: NPE is thrown when JAXBContextFactory implementation is specified in system property,
mkos
parents: 31109
diff changeset
   287
            Throwable x = handleInvocationTargetException(e);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   288
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   289
            throw new JAXBException(x);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   290
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   291
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   292
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   293
    static JAXBContext find(String factoryId,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   294
                            String contextPath,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   295
                            ClassLoader classLoader,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   296
                            Map properties) throws JAXBException {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   297
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   298
        StringTokenizer packages = new StringTokenizer(contextPath, ":");
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   299
        if (!packages.hasMoreTokens()) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   300
            // no context is specified
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   301
            throw new JAXBException(Messages.format(Messages.NO_PACKAGE_IN_CONTEXTPATH));
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   302
        }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   303
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   304
        // search for jaxb.properties in the class loader of each class first
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   305
        logger.fine("Searching jaxb.properties");
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   306
        while (packages.hasMoreTokens()) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   307
            // com.acme.foo - > com/acme/foo/jaxb.properties
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   308
            String factoryClassName =
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   309
                    classNameFromPackageProperties(
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   310
                        classLoader,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   311
                        packages.nextToken(":").replace('.', '/'),
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   312
                        factoryId,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   313
                        JAXB_CONTEXT_FACTORY_DEPRECATED);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   314
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   315
            if (factoryClassName != null) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   316
                return newInstance(contextPath, factoryClassName, classLoader, properties);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   317
            }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   318
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   319
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   320
        String factoryName = classNameFromSystemProperties();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   321
        if (factoryName != null) return newInstance(contextPath, factoryName, classLoader, properties);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   322
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   323
        JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader(
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   324
                JAXBContextFactory.class, logger, EXCEPTION_HANDLER);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   325
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   326
        if (obj != null) return obj.createContext(contextPath, classLoader, properties);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   327
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   328
        // to ensure backwards compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   329
        factoryName = firstByServiceLoaderDeprecated(JAXBContext.class, classLoader);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   330
        if (factoryName != null) return newInstance(contextPath, factoryName, classLoader, properties);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   331
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   332
        Class ctxFactory = (Class) ServiceLoaderUtil.lookupUsingOSGiServiceLoader(
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   333
                "javax.xml.bind.JAXBContext", logger);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   334
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   335
        if (ctxFactory != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   336
            return newInstance(contextPath, ctxFactory, classLoader, properties);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   337
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   338
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   339
        // else no provider found
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   340
        logger.fine("Trying to create the platform default provider");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   341
        return newInstance(contextPath, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader, properties);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   342
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   343
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   344
    static JAXBContext find(Class<?>[] classes, Map<String, ?> properties) throws JAXBException {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   345
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   346
        // search for jaxb.properties in the class loader of each class first
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   347
        logger.fine("Searching jaxb.properties");
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   348
        for (final Class c : classes) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   349
            // this classloader is used only to load jaxb.properties, so doing this should be safe.
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   350
            // this is possible for primitives, arrays, and classes that are
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   351
            // loaded by poorly implemented ClassLoaders
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   352
            if (c.getPackage() == null) continue;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   353
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   354
            // TODO: do we want to optimize away searching the same package?  org.Foo, org.Bar, com.Baz
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   355
            // classes from the same package might come from different class loades, so it might be a bad idea
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   356
            // TODO: it's easier to look things up from the class
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   357
            // c.getResourceAsStream("jaxb.properties");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   358
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   359
            String factoryClassName =
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   360
                    classNameFromPackageProperties(
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   361
                            getClassClassLoader(c),
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   362
                            c.getPackage().getName().replace('.', '/'),
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   363
                            JAXBContext.JAXB_CONTEXT_FACTORY, JAXB_CONTEXT_FACTORY_DEPRECATED);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   364
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   365
            if (factoryClassName != null) return newInstance(classes, properties, factoryClassName);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   366
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   367
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   368
        String factoryClassName = classNameFromSystemProperties();
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   369
        if (factoryClassName != null) return newInstance(classes, properties, factoryClassName);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   370
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   371
        JAXBContextFactory factory =
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   372
                ServiceLoaderUtil.firstByServiceLoader(JAXBContextFactory.class, logger, EXCEPTION_HANDLER);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   373
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   374
        if (factory != null) return factory.createContext(classes, properties);
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   375
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   376
        // to ensure backwards compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   377
        String className = firstByServiceLoaderDeprecated(JAXBContext.class, getContextClassLoader());
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   378
        if (className != null) return newInstance(classes, properties, className);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   379
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   380
        logger.fine("Trying to create the platform default provider");
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   381
        Class ctxFactoryClass =
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   382
                (Class) ServiceLoaderUtil.lookupUsingOSGiServiceLoader("javax.xml.bind.JAXBContext", logger);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   383
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   384
        if (ctxFactoryClass != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   385
            return newInstance(classes, properties, ctxFactoryClass);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   386
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   387
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   388
        // else no provider found
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   389
        logger.fine("Trying to create the platform default provider");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   390
        return newInstance(classes, properties, PLATFORM_DEFAULT_FACTORY_CLASS);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   391
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   392
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   393
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   394
    /**
39173
68169040e394 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents: 35413
diff changeset
   395
     * first factoryId should be the preferred one,
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   396
     * more of those can be provided to support backwards compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   397
     */
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   398
    private static String classNameFromPackageProperties(ClassLoader classLoader,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   399
                                                         String packageName,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   400
                                                         String ... factoryIds) throws JAXBException {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   401
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   402
        String resourceName = packageName + "/jaxb.properties";
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   403
        logger.log(Level.FINE, "Trying to locate {0}", resourceName);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   404
        Properties props = loadJAXBProperties(classLoader, resourceName);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   405
        if (props != null) {
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   406
            for(String factoryId : factoryIds) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   407
                if (props.containsKey(factoryId)) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   408
                    return props.getProperty(factoryId);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   409
                }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   410
            }
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   411
            throw new JAXBException(Messages.format(Messages.MISSING_PROPERTY, packageName, factoryIds[0]));
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   412
        }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   413
        return null;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   414
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   415
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   416
    private static String classNameFromSystemProperties() throws JAXBException {
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   417
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   418
        String factoryClassName = getSystemProperty(JAXBContext.JAXB_CONTEXT_FACTORY);
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   419
        if (factoryClassName != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   420
            return factoryClassName;
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   421
        }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   422
        // leave this here to assure compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   423
        factoryClassName = getDeprecatedSystemProperty(JAXB_CONTEXT_FACTORY_DEPRECATED);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   424
        if (factoryClassName != null) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   425
            return factoryClassName;
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   426
        }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   427
        // leave this here to assure compatibility
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   428
        factoryClassName = getDeprecatedSystemProperty(JAXBContext.class.getName());
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   429
        if (factoryClassName != null) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   430
            return factoryClassName;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   431
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   432
        return null;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   433
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   434
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   435
    private static String getDeprecatedSystemProperty(String property) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   436
        String value = getSystemProperty(property);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   437
        if (value != null) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   438
            logger.log(Level.WARNING, "Using non-standard property: {0}. Property {1} should be used instead.",
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   439
                    new Object[] {property, JAXBContext.JAXB_CONTEXT_FACTORY});
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   440
        }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   441
        return value;
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   442
    }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   443
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   444
    private static String getSystemProperty(String property) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   445
        logger.log(Level.FINE, "Checking system property {0}", property);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   446
        String value = AccessController.doPrivileged(new GetPropertyAction(property));
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   447
        if (value != null) {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   448
            logger.log(Level.FINE, "  found {0}", value);
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   449
        } else {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   450
            logger.log(Level.FINE, "  not found");
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   451
        }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   452
        return value;
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   453
    }
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   454
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   455
    private static Properties loadJAXBProperties(ClassLoader classLoader,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   456
                                                 String propFileName) throws JAXBException {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   457
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   458
        Properties props = null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   459
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   460
            URL url;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   461
            if (classLoader == null)
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   462
                url = ClassLoader.getSystemResource(propFileName);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   463
            else
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   464
                url = classLoader.getResource(propFileName);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   465
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   466
            if (url != null) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   467
                logger.log(Level.FINE, "loading props from {0}", url);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   468
                props = new Properties();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   469
                InputStream is = url.openStream();
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   470
                props.load(is);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   471
                is.close();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   472
            }
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   473
        } catch (IOException ioe) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   474
            logger.log(Level.FINE, "Unable to load " + propFileName, ioe);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   475
            throw new JAXBException(ioe.toString(), ioe);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   476
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   477
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   478
        return props;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   479
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   480
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   481
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   482
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   483
     * Search the given ClassLoader for an instance of the specified class and
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   484
     * return a string representation of the URL that points to the resource.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   485
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   486
     * @param clazz
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   487
     *          The class to search for
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   488
     * @param loader
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   489
     *          The ClassLoader to search.  If this parameter is null, then the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   490
     *          system class loader will be searched
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   491
     * @return
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   492
     *          the URL for the class or null if it wasn't found
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   493
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   494
    static URL which(Class clazz, ClassLoader loader) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   495
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   496
        String classnameAsResource = clazz.getName().replace('.', '/') + ".class";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   497
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   498
        if (loader == null) {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   499
            loader = getSystemClassLoader();
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   500
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   501
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   502
        return loader.getResource(classnameAsResource);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   503
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   504
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   505
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   506
     * Get the URL for the Class from it's ClassLoader.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   507
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   508
     * Convenience method for {@link #which(Class, ClassLoader)}.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   509
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   510
     * Equivalent to calling: which(clazz, clazz.getClassLoader())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   511
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   512
     * @param clazz
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   513
     *          The class to search for
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   514
     * @return
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   515
     *          the URL for the class or null if it wasn't found
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   516
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   517
    static URL which(Class clazz) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   518
        return which(clazz, getClassClassLoader(clazz));
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   519
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   520
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   521
    @SuppressWarnings("unchecked")
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   522
    private static ClassLoader getContextClassLoader() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   523
        if (System.getSecurityManager() == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   524
            return Thread.currentThread().getContextClassLoader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   525
        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   526
            return (ClassLoader) java.security.AccessController.doPrivileged(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   527
                    new java.security.PrivilegedAction() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   528
                        public java.lang.Object run() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   529
                            return Thread.currentThread().getContextClassLoader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   530
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   531
                    });
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   532
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   533
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   534
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   535
    @SuppressWarnings("unchecked")
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   536
    private static ClassLoader getClassClassLoader(final Class c) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   537
        if (System.getSecurityManager() == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   538
            return c.getClassLoader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   539
        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   540
            return (ClassLoader) java.security.AccessController.doPrivileged(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   541
                    new java.security.PrivilegedAction() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   542
                        public java.lang.Object run() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   543
                            return c.getClassLoader();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   544
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   545
                    });
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   546
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   547
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   548
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   549
    private static ClassLoader getSystemClassLoader() {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   550
        if (System.getSecurityManager() == null) {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   551
            return ClassLoader.getSystemClassLoader();
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   552
        } else {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   553
            return (ClassLoader) java.security.AccessController.doPrivileged(
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   554
                    new java.security.PrivilegedAction() {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   555
                        public java.lang.Object run() {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   556
                            return ClassLoader.getSystemClassLoader();
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   557
                        }
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   558
                    });
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   559
        }
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   560
    }
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   561
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   562
    // ServiceLoaderUtil.firstByServiceLoaderDeprecated should be used instead.
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   563
    @Deprecated
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   564
    static String firstByServiceLoaderDeprecated(Class spiClass,
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   565
                                                 ClassLoader classLoader) throws JAXBException {
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   566
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   567
        final String jaxbContextFQCN = spiClass.getName();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   568
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   569
        logger.fine("Searching META-INF/services");
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   570
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   571
        // search META-INF services next
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   572
        BufferedReader r = null;
31109
a542f8dcbbf8 8072839: JAX-B Plugability Layer: using java.util.ServiceLoader
mkos
parents: 29839
diff changeset
   573
        final String resource = "META-INF/services/" + jaxbContextFQCN;
29839
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   574
        try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   575
            final InputStream resourceStream =
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   576
                    (classLoader == null) ?
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   577
                            ClassLoader.getSystemResourceAsStream(resource) :
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   578
                            classLoader.getResourceAsStream(resource);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   579
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   580
            if (resourceStream != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   581
                r = new BufferedReader(new InputStreamReader(resourceStream, "UTF-8"));
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   582
                String factoryClassName = r.readLine();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   583
                if (factoryClassName != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   584
                    factoryClassName = factoryClassName.trim();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   585
                }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   586
                r.close();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   587
                logger.log(Level.FINE, "Configured factorty class:{0}", factoryClassName);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   588
                return factoryClassName;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   589
            } else {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   590
                logger.log(Level.FINE, "Unable to load:{0}", resource);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   591
                return null;
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   592
            }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   593
        } catch (IOException e) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   594
            throw new JAXBException(e);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   595
        } finally {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   596
            try {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   597
                if (r != null) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   598
                    r.close();
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   599
                }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   600
            } catch (IOException ex) {
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   601
                logger.log(Level.SEVERE, "Unable to close resource: " + resource, ex);
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   602
            }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   603
        }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   604
    }
6d5d546e953b 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
aefimov
parents: 25871
diff changeset
   605
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   606
}