jaxp/src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12458 d601e4bba306
child 18352 a1e183c996d6
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     1
/*
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     2
 * reserved comment block
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     4
 */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     5
/*
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     7
 *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    10
 * You may obtain a copy of the License at
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    11
 *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    13
 *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    18
 * limitations under the License.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    19
 */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    20
/*
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    21
 * $Id: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    22
 */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    23
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.utils;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    25
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    26
import java.io.InputStream;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    27
import java.io.IOException;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    28
import java.io.File;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    29
import java.io.FileInputStream;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    30
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    31
import java.util.Properties;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    32
import java.io.BufferedReader;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    33
import java.io.InputStreamReader;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    34
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    35
/**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    36
 * This class is duplicated for each JAXP subpackage so keep it in sync.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    37
 * It is package private and therefore is not exposed as part of the JAXP
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    38
 * API.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    39
 * <p>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    40
 * This code is designed to implement the JAXP 1.1 spec pluggability
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    41
 * feature and is designed to run on JDK version 1.1 and
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    42
 * later, and to compile on JDK 1.2 and onward.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    43
 * The code also runs both as part of an unbundled jar file and
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    44
 * when bundled as part of the JDK.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    45
 * <p>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    46
 * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    47
 * class and modified to be used as a general utility for creating objects
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    48
 * dynamically.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    49
 *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    50
 * @version $Id: ObjectFactory.java,v 1.11 2010-11-01 04:34:25 joehw Exp $
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    51
 */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    52
public class ObjectFactory {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    53
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    54
    //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    55
    // Constants
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    56
    //
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    57
     private static final String XALAN_INTERNAL = "com.sun.org.apache.xalan.internal";
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    58
     private static final String XERCES_INTERNAL = "com.sun.org.apache.xerces.internal";
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    59
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    60
    // name of default properties file to look for in JDK's jre/lib directory
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    61
    private static final String DEFAULT_PROPERTIES_FILENAME =
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    62
                                                     "xalan.properties";
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    63
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    64
    private static final String SERVICES_PATH = "META-INF/services/";
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    65
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    66
    /** Set to true for debugging */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    67
    private static final boolean DEBUG = false;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    68
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    69
    /** cache the contents of the xalan.properties file.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    70
     *  Until an attempt has been made to read this file, this will
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    71
     * be null; if the file does not exist or we encounter some other error
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    72
     * during the read, this will be empty.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    73
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    74
    private static Properties fXalanProperties = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    75
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    76
    /***
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    77
     * Cache the time stamp of the xalan.properties file so
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    78
     * that we know if it's been modified and can invalidate
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    79
     * the cache when necessary.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    80
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    81
    private static long fLastModified = -1;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    82
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    83
    //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    84
    // Public static methods
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    85
    //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    86
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    87
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    88
     * Finds the implementation Class object in the specified order.  The
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    89
     * specified order is the following:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    90
     * <ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    91
     *  <li>query the system property using <code>System.getProperty</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    92
     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    93
     *  <li>use fallback classname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    94
     * </ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    95
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    96
     * @return instance of factory, never null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    97
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    98
     * @param factoryId             Name of the factory to find, same as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
    99
     *                              a property name
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   100
     * @param fallbackClassName     Implementation class name, if nothing else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   101
     *                              is found.  Use null to mean no fallback.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   102
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   103
     * @exception ObjectFactory.ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   104
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   105
    public static Object createObject(String factoryId, String fallbackClassName)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   106
        throws ConfigurationError {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   107
        return createObject(factoryId, null, fallbackClassName);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   108
    } // createObject(String,String):Object
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   109
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   110
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   111
     * Finds the implementation Class object in the specified order.  The
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   112
     * specified order is the following:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   113
     * <ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   114
     *  <li>query the system property using <code>System.getProperty</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   115
     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   116
     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   117
     *  <li>use fallback classname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   118
     * </ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   119
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   120
     * @return instance of factory, never null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   121
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   122
     * @param factoryId             Name of the factory to find, same as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   123
     *                              a property name
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   124
     * @param propertiesFilename The filename in the $java.home/lib directory
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   125
     *                           of the properties file.  If none specified,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   126
     *                           ${java.home}/lib/xalan.properties will be used.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   127
     * @param fallbackClassName     Implementation class name, if nothing else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   128
     *                              is found.  Use null to mean no fallback.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   129
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   130
     * @exception ObjectFactory.ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   131
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   132
    static Object createObject(String factoryId,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   133
                                      String propertiesFilename,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   134
                                      String fallbackClassName)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   135
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   136
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   137
        Class factoryClass = lookUpFactoryClass(factoryId,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   138
                                                propertiesFilename,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   139
                                                fallbackClassName);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   140
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   141
        if (factoryClass == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   142
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   143
                "Provider for " + factoryId + " cannot be found", null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   144
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   145
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   146
        try{
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   147
            Object instance = factoryClass.newInstance();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   148
            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   149
            return instance;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   150
        } catch (Exception x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   151
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   152
                "Provider for factory " + factoryId
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   153
                    + " could not be instantiated: " + x, x);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   154
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   155
    } // createObject(String,String,String):Object
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   156
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   157
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   158
     * Finds the implementation Class object in the specified order.  The
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   159
     * specified order is the following:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   160
     * <ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   161
     *  <li>query the system property using <code>System.getProperty</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   162
     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   163
     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   164
     *  <li>use fallback classname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   165
     * </ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   166
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   167
     * @return Class object of factory, never null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   168
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   169
     * @param factoryId             Name of the factory to find, same as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   170
     *                              a property name
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   171
     * @param propertiesFilename The filename in the $java.home/lib directory
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   172
     *                           of the properties file.  If none specified,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   173
     *                           ${java.home}/lib/xalan.properties will be used.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   174
     * @param fallbackClassName     Implementation class name, if nothing else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   175
     *                              is found.  Use null to mean no fallback.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   176
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   177
     * @exception ObjectFactory.ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   178
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   179
    public static Class lookUpFactoryClass(String factoryId)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   180
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   181
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   182
        return lookUpFactoryClass(factoryId, null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   183
    } // lookUpFactoryClass(String):Class
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   184
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   185
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   186
     * Finds the implementation Class object in the specified order.  The
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   187
     * specified order is the following:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   188
     * <ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   189
     *  <li>query the system property using <code>System.getProperty</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   190
     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   191
     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   192
     *  <li>use fallback classname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   193
     * </ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   194
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   195
     * @return Class object that provides factory service, never null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   196
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   197
     * @param factoryId             Name of the factory to find, same as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   198
     *                              a property name
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   199
     * @param propertiesFilename The filename in the $java.home/lib directory
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   200
     *                           of the properties file.  If none specified,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   201
     *                           ${java.home}/lib/xalan.properties will be used.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   202
     * @param fallbackClassName     Implementation class name, if nothing else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   203
     *                              is found.  Use null to mean no fallback.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   204
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   205
     * @exception ObjectFactory.ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   206
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   207
    public static Class lookUpFactoryClass(String factoryId,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   208
                                           String propertiesFilename,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   209
                                           String fallbackClassName)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   210
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   211
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   212
        String factoryClassName = lookUpFactoryClassName(factoryId,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   213
                                                         propertiesFilename,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   214
                                                         fallbackClassName);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   215
        ClassLoader cl = findClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   216
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   217
        if (factoryClassName == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   218
            factoryClassName = fallbackClassName;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   219
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   220
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   221
        // assert(className != null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   222
        try{
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   223
            Class providerClass = findProviderClass(factoryClassName,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   224
                                                    cl,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   225
                                                    true);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   226
            if (DEBUG) debugPrintln("created new instance of " + providerClass +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   227
                   " using ClassLoader: " + cl);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   228
            return providerClass;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   229
        } catch (ClassNotFoundException x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   230
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   231
                "Provider " + factoryClassName + " not found", x);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   232
        } catch (Exception x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   233
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   234
                "Provider "+factoryClassName+" could not be instantiated: "+x,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   235
                x);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   236
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   237
    } // lookUpFactoryClass(String,String,String):Class
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   238
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   239
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   240
     * Finds the name of the required implementation class in the specified
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   241
     * order.  The specified order is the following:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   242
     * <ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   243
     *  <li>query the system property using <code>System.getProperty</code>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   244
     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   245
     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   246
     *  <li>use fallback classname
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   247
     * </ol>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   248
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   249
     * @return name of class that provides factory service, never null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   250
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   251
     * @param factoryId             Name of the factory to find, same as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   252
     *                              a property name
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   253
     * @param propertiesFilename The filename in the $java.home/lib directory
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   254
     *                           of the properties file.  If none specified,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   255
     *                           ${java.home}/lib/xalan.properties will be used.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   256
     * @param fallbackClassName     Implementation class name, if nothing else
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   257
     *                              is found.  Use null to mean no fallback.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   258
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   259
     * @exception ObjectFactory.ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   260
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   261
    static String lookUpFactoryClassName(String factoryId,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   262
                                                String propertiesFilename,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   263
                                                String fallbackClassName)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   264
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   265
        // Use the system property first
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   266
        try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   267
            String systemProp = SecuritySupport.getSystemProperty(factoryId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   268
            if (systemProp != null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   269
                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   270
                return systemProp;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   271
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   272
        } catch (SecurityException se) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   273
            // Ignore and continue w/ next location
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   274
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   275
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   276
        // Try to read from propertiesFilename, or
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   277
        // $java.home/lib/xalan.properties
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   278
        String factoryClassName = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   279
        // no properties file name specified; use
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   280
        // $JAVA_HOME/lib/xalan.properties:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   281
        if (propertiesFilename == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   282
            File propertiesFile = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   283
            boolean propertiesFileExists = false;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   284
            try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   285
                String javah = SecuritySupport.getSystemProperty("java.home");
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   286
                propertiesFilename = javah + File.separator +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   287
                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   288
                propertiesFile = new File(propertiesFilename);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   289
                propertiesFileExists = SecuritySupport.getFileExists(propertiesFile);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   290
            } catch (SecurityException e) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   291
                // try again...
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   292
                fLastModified = -1;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   293
                fXalanProperties = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   294
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   295
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   296
            synchronized (ObjectFactory.class) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   297
                boolean loadProperties = false;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   298
                FileInputStream fis = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   299
                try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   300
                    // file existed last time
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   301
                    if(fLastModified >= 0) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   302
                        if(propertiesFileExists &&
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   303
                                (fLastModified < (fLastModified = SecuritySupport.getLastModified(propertiesFile)))) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   304
                            loadProperties = true;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   305
                        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   306
                            // file has stopped existing...
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   307
                            if(!propertiesFileExists) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   308
                                fLastModified = -1;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   309
                                fXalanProperties = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   310
                            } // else, file wasn't modified!
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   311
                        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   312
                    } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   313
                        // file has started to exist:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   314
                        if(propertiesFileExists) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   315
                            loadProperties = true;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   316
                            fLastModified = SecuritySupport.getLastModified(propertiesFile);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   317
                        } // else, nothing's changed
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   318
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   319
                    if(loadProperties) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   320
                        // must never have attempted to read xalan.properties
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   321
                        // before (or it's outdeated)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   322
                        fXalanProperties = new Properties();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   323
                        fis = SecuritySupport.getFileInputStream(propertiesFile);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   324
                        fXalanProperties.load(fis);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   325
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   326
                } catch (Exception x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   327
                    fXalanProperties = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   328
                    fLastModified = -1;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   329
                    // assert(x instanceof FileNotFoundException
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   330
                    //        || x instanceof SecurityException)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   331
                    // In both cases, ignore and continue w/ next location
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   332
                }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   333
                finally {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   334
                    // try to close the input stream if one was opened.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   335
                    if (fis != null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   336
                        try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   337
                            fis.close();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   338
                        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   339
                        // Ignore the exception.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   340
                        catch (IOException exc) {}
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   341
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   342
                }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   343
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   344
            if(fXalanProperties != null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   345
                factoryClassName = fXalanProperties.getProperty(factoryId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   346
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   347
        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   348
            FileInputStream fis = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   349
            try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   350
                fis = SecuritySupport.getFileInputStream(new File(propertiesFilename));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   351
                Properties props = new Properties();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   352
                props.load(fis);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   353
                factoryClassName = props.getProperty(factoryId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   354
            } catch (Exception x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   355
                // assert(x instanceof FileNotFoundException
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   356
                //        || x instanceof SecurityException)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   357
                // In both cases, ignore and continue w/ next location
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   358
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   359
            finally {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   360
                // try to close the input stream if one was opened.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   361
                if (fis != null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   362
                    try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   363
                        fis.close();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   364
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   365
                    // Ignore the exception.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   366
                    catch (IOException exc) {}
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   367
                }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   368
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   369
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   370
        if (factoryClassName != null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   371
            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   372
                          + factoryClassName);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   373
            return factoryClassName;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   374
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   375
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   376
        // Try Jar Service Provider Mechanism
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   377
        return findJarServiceProviderName(factoryId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   378
    } // lookUpFactoryClass(String,String):String
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   379
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   380
    //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   381
    // Private static methods
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   382
    //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   383
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   384
    /** Prints a message to standard error if debugging is enabled. */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   385
    private static void debugPrintln(String msg) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   386
        if (DEBUG) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   387
            System.err.println("JAXP: " + msg);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   388
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   389
    } // debugPrintln(String)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   390
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   391
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   392
     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   393
     * the context ClassLoader.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   394
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   395
    public static ClassLoader findClassLoader()
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   396
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   397
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   398
        if (System.getSecurityManager()!=null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   399
            //this will ensure bootclassloader is used
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   400
            return null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   401
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   402
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   403
        // Figure out which ClassLoader to use for loading the provider
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   404
        // class.  If there is a Context ClassLoader then use it.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   405
        ClassLoader context = SecuritySupport.getContextClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   406
        ClassLoader system = SecuritySupport.getSystemClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   407
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   408
        ClassLoader chain = system;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   409
        while (true) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   410
            if (context == chain) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   411
                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   412
                // or any Context ClassLoader in chain of system classloader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   413
                // (including extension ClassLoader) so extend to widest
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   414
                // ClassLoader (always look in system ClassLoader if Xalan
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   415
                // is in boot/extension/system classpath and in current
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   416
                // ClassLoader otherwise); normal classloaders delegate
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   417
                // back to system ClassLoader first so this widening doesn't
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   418
                // change the fact that context ClassLoader will be consulted
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   419
                ClassLoader current = ObjectFactory.class.getClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   420
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   421
                chain = system;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   422
                while (true) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   423
                    if (current == chain) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   424
                        // Assert: Current ClassLoader in chain of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   425
                        // boot/extension/system ClassLoaders
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   426
                        return system;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   427
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   428
                    if (chain == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   429
                        break;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   430
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   431
                    chain = SecuritySupport.getParentClassLoader(chain);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   432
                }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   433
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   434
                // Assert: Current ClassLoader not in chain of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   435
                // boot/extension/system ClassLoaders
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   436
                return current;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   437
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   438
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   439
            if (chain == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   440
                // boot ClassLoader reached
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   441
                break;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   442
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   443
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   444
            // Check for any extension ClassLoaders in chain up to
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   445
            // boot ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   446
            chain = SecuritySupport.getParentClassLoader(chain);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   447
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   448
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   449
        // Assert: Context ClassLoader not in chain of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   450
        // boot/extension/system ClassLoaders
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   451
        return context;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   452
    } // findClassLoader():ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   453
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   454
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   455
     * Create an instance of a class using the same classloader for the ObjectFactory by default
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   456
     * or bootclassloader when Security Manager is in place
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   457
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   458
    public static Object newInstance(String className, boolean doFallback)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   459
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   460
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   461
        if (System.getSecurityManager()!=null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   462
            return newInstance(className, null, doFallback);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   463
        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   464
            return newInstance(className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   465
                findClassLoader (), doFallback);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   466
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   467
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   468
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   469
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   470
     * Create an instance of a class using the specified ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   471
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   472
    static Object newInstance(String className, ClassLoader cl,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   473
                                      boolean doFallback)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   474
        throws ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   475
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   476
        // assert(className != null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   477
        try{
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   478
            Class providerClass = findProviderClass(className, cl, doFallback);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   479
            Object instance = providerClass.newInstance();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   480
            if (DEBUG) debugPrintln("created new instance of " + providerClass +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   481
                   " using ClassLoader: " + cl);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   482
            return instance;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   483
        } catch (ClassNotFoundException x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   484
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   485
                "Provider " + className + " not found", x);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   486
        } catch (Exception x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   487
            throw new ConfigurationError(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   488
                "Provider " + className + " could not be instantiated: " + x,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   489
                x);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   490
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   491
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   492
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   493
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   494
     * Find a Class using the same classloader for the ObjectFactory by default
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   495
     * or bootclassloader when Security Manager is in place
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   496
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   497
    public static Class findProviderClass(String className, boolean doFallback)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   498
        throws ClassNotFoundException, ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   499
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   500
        if (System.getSecurityManager()!=null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   501
            return Class.forName(className);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   502
        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   503
            return findProviderClass (className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   504
                findClassLoader (), doFallback);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   505
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   506
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   507
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   508
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   509
     * Find a Class using the specified ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   510
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   511
    static Class findProviderClass(String className, ClassLoader cl,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   512
                                           boolean doFallback)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   513
        throws ClassNotFoundException, ConfigurationError
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   514
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   515
        //throw security exception if the calling thread is not allowed to access the
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   516
        //class. Restrict the access to the package classes as specified in java.security policy.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   517
        SecurityManager security = System.getSecurityManager();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   518
        try{
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   519
            if (security != null){
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   520
                if (className.startsWith(XALAN_INTERNAL) ||
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   521
                    className.startsWith(XERCES_INTERNAL)) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   522
                    cl = null;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   523
                } else {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   524
                    final int lastDot = className.lastIndexOf(".");
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   525
                    String packageName = className;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   526
                    if (lastDot != -1) packageName = className.substring(0, lastDot);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   527
                    security.checkPackageAccess(packageName);
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   528
                }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   529
             }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   530
        }catch(SecurityException e){
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   531
            throw e;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   532
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   533
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   534
        Class providerClass;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   535
        if (cl == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   536
            // XXX Use the bootstrap ClassLoader.  There is no way to
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   537
            // load a class using the bootstrap ClassLoader that works
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   538
            // in both JDK 1.1 and Java 2.  However, this should still
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   539
            // work b/c the following should be true:
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   540
            //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   541
            // (cl == null) iff current ClassLoader == null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   542
            //
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   543
            // Thus Class.forName(String) will use the current
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   544
            // ClassLoader which will be the bootstrap ClassLoader.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   545
            providerClass = Class.forName(className);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   546
        } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   547
            try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   548
                providerClass = cl.loadClass(className);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   549
            } catch (ClassNotFoundException x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   550
                if (doFallback) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   551
                    // Fall back to current classloader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   552
                    ClassLoader current = ObjectFactory.class.getClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   553
                    if (current == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   554
                        providerClass = Class.forName(className);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   555
                    } else if (cl != current) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   556
                        cl = current;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   557
                        providerClass = cl.loadClass(className);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   558
                    } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   559
                        throw x;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   560
                    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   561
                } else {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   562
                    throw x;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   563
                }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   564
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   565
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   566
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   567
        return providerClass;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   568
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   569
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   570
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   571
     * Find the name of service provider using Jar Service Provider Mechanism
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   572
     *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   573
     * @return instance of provider class if found or null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   574
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   575
    private static String findJarServiceProviderName(String factoryId)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   576
    {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   577
        String serviceId = SERVICES_PATH + factoryId;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   578
        InputStream is = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   579
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   580
        // First try the Context ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   581
        ClassLoader cl = findClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   582
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   583
        is = SecuritySupport.getResourceAsStream(cl, serviceId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   584
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   585
        // If no provider found then try the current ClassLoader
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   586
        if (is == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   587
            ClassLoader current = ObjectFactory.class.getClassLoader();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   588
            if (cl != current) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   589
                cl = current;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   590
                is = SecuritySupport.getResourceAsStream(cl, serviceId);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   591
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   592
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   593
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   594
        if (is == null) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   595
            // No provider found
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   596
            return null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   597
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   598
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   599
        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   600
               " using ClassLoader: " + cl);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   601
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   602
        // Read the service provider name in UTF-8 as specified in
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   603
        // the jar spec.  Unfortunately this fails in Microsoft
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   604
        // VJ++, which does not implement the UTF-8
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   605
        // encoding. Theoretically, we should simply let it fail in
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   606
        // that case, since the JVM is obviously broken if it
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   607
        // doesn't support such a basic standard.  But since there
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   608
        // are still some users attempting to use VJ++ for
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   609
        // development, we have dropped in a fallback which makes a
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   610
        // second attempt using the platform's default encoding. In
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   611
        // VJ++ this is apparently ASCII, which is a subset of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   612
        // UTF-8... and since the strings we'll be reading here are
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   613
        // also primarily limited to the 7-bit ASCII range (at
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   614
        // least, in English versions), this should work well
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   615
        // enough to keep us on the air until we're ready to
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   616
        // officially decommit from VJ++. [Edited comment from
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   617
        // jkesselm]
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   618
        BufferedReader rd;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   619
        try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   620
            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   621
        } catch (java.io.UnsupportedEncodingException e) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   622
            rd = new BufferedReader(new InputStreamReader(is));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   623
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   624
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   625
        String factoryClassName = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   626
        try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   627
            // XXX Does not handle all possible input as specified by the
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   628
            // Jar Service Provider specification
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   629
            factoryClassName = rd.readLine();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   630
        } catch (IOException x) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   631
            // No provider found
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   632
            return null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   633
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   634
        finally {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   635
            try {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   636
                // try to close the reader.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   637
                rd.close();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   638
            }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   639
            // Ignore the exception.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   640
            catch (IOException exc) {}
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   641
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   642
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   643
        if (factoryClassName != null &&
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   644
            ! "".equals(factoryClassName)) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   645
            if (DEBUG) debugPrintln("found in resource, value="
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   646
                   + factoryClassName);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   647
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   648
            // Note: here we do not want to fall back to the current
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   649
            // ClassLoader because we want to avoid the case where the
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   650
            // resource file was found using one ClassLoader and the
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   651
            // provider class was instantiated using a different one.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   652
            return factoryClassName;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   653
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   654
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   655
        // No provider found
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   656
        return null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   657
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   658
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents:
diff changeset
   659
} // class ObjectFactory