src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 47359 e1a6c0168741
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Sep 2017
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    11
 * the License.  You may obtain a copy of the License at
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 *
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 * limitations under the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
 * $Id: TemplatesImpl.java,v 1.8 2007/03/26 20:12:27 spericas Exp $
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
package com.sun.org.apache.xalan.internal.xsltc.trax;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
    27
import com.sun.org.apache.xalan.internal.XalanConstants;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    28
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    29
import com.sun.org.apache.xalan.internal.xsltc.DOM;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    30
import com.sun.org.apache.xalan.internal.xsltc.Translet;
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
    31
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    32
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
import java.io.IOException;
33350
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
    35
import java.io.NotSerializableException;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    36
import java.io.ObjectInputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    37
import java.io.ObjectOutputStream;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    38
import java.io.ObjectStreamField;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
import java.io.Serializable;
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
    40
import java.lang.RuntimePermission;
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    41
import java.lang.module.Configuration;
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    42
import java.lang.module.ModuleDescriptor;
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    43
import java.lang.module.ModuleFinder;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    44
import java.lang.module.ModuleReader;
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    45
import java.lang.module.ModuleReference;
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
    46
import java.lang.reflect.InvocationTargetException;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
import java.security.AccessController;
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
    48
import java.security.CodeSigner;
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
    49
import java.security.CodeSource;
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
    50
import java.security.PermissionCollection;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
import java.security.PrivilegedAction;
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
    52
import java.security.ProtectionDomain;
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    53
import java.util.Arrays;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    54
import java.util.HashMap;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    55
import java.util.Map;
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    56
import java.util.Optional;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
    57
import java.util.Properties;
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
    58
import java.util.Set;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
import javax.xml.XMLConstants;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
import javax.xml.transform.Templates;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
import javax.xml.transform.Transformer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
import javax.xml.transform.TransformerConfigurationException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
import javax.xml.transform.URIResolver;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    64
import jdk.xml.internal.SecuritySupport;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
    66
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
 * @author Morten Jorgensen
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
 * @author G. Todd Millerj
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
 * @author Jochen Cordes <Jochen.Cordes@t-online.de>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
 * @author Santiago Pericas-Geertsen
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
public final class TemplatesImpl implements Templates, Serializable {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
    static final long serialVersionUID = 673094361519270707L;
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    75
    public final static String DESERIALIZE_TRANSLET = "jdk.xml.enableTemplatesImplDeserialization";
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    76
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
     * Name of the superclass of all translets. This is needed to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
     * determine which, among all classes comprising a translet,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
     * is the main one.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
    private static String ABSTRACT_TRANSLET
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
        = "com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
     * Name of the main class or default name if unknown.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
    private String _name = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    91
     * Contains the actual class definition for the translet class and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
     * any auxiliary classes.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
    private byte[][] _bytecodes = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
     * Contains the translet class definition(s). These are created when
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
     * this Templates is created or when it is read back from disk.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
    private Class[] _class = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
     * The index of the main translet class in the arrays _class[] and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
     * _bytecodes.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
    private int _transletIndex = -1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
     * Contains the list of auxiliary class definitions.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
     */
33350
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   111
    private transient Map<String, Class<?>> _auxClasses = null;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
     * Output properties of this translet.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
    private Properties _outputProperties;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
     * Number of spaces to add for output indentation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
    private int _indentNumber;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
     * This URIResolver is passed to all Transformers.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
     * Declaring it transient to fix bug 22438
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
    private transient URIResolver _uriResolver = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
     * Cache the DTM for the stylesheet in a thread local variable,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
     * which is used by the document('') function.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
     * Use ThreadLocal because a DTM cannot be shared between
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
     * multiple threads.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
     * Declaring it transient to fix bug 22438
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
    private transient ThreadLocal _sdom = new ThreadLocal();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
     * A reference to the transformer factory that this templates
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
     * object belongs to.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
    private transient TransformerFactoryImpl _tfactory = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   144
    /**
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   145
     * A flag to determine whether the Service Mechanism is used
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   146
     */
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   147
    private transient boolean _useServicesMechanism;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   148
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   149
    /**
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   150
     * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   151
     */
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   152
    private transient String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   153
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   154
    /**
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   155
     * @serialField _name String The Name of the main class
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   156
     * @serialField _bytecodes byte[][] Class definition
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   157
     * @serialField _class Class[] The translet class definition(s).
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   158
     * @serialField _transletIndex int The index of the main translet class
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   159
     * @serialField _outputProperties Properties Output properties of this translet.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   160
     * @serialField _indentNumber int Number of spaces to add for output indentation.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   161
     */
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   162
    private static final ObjectStreamField[] serialPersistentFields =
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   163
        new ObjectStreamField[] {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   164
            new ObjectStreamField("_name", String.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   165
            new ObjectStreamField("_bytecodes", byte[][].class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   166
            new ObjectStreamField("_class", Class[].class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   167
            new ObjectStreamField("_transletIndex", int.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   168
            new ObjectStreamField("_outputProperties", Properties.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   169
            new ObjectStreamField("_indentNumber", int.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   170
        };
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   171
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
    static final class TransletClassLoader extends ClassLoader {
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39801
diff changeset
   173
        private final Map<String, Class<?>> _loadedExternalExtensionFunctions;
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   174
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   175
         TransletClassLoader(ClassLoader parent) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   176
             super(parent);
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   177
            _loadedExternalExtensionFunctions = null;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   178
        }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   179
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39801
diff changeset
   180
        TransletClassLoader(ClassLoader parent, Map<String, Class<?>> mapEF) {
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   181
            super(parent);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   182
            _loadedExternalExtensionFunctions = mapEF;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   183
        }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   184
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   185
        @Override
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   186
        public Class<?> loadClass(String name) throws ClassNotFoundException {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   187
            Class<?> ret = null;
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   188
            // The _loadedExternalExtensionFunctions will be empty when the
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   189
            // SecurityManager is not set and the FSP is turned off
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   190
            if (_loadedExternalExtensionFunctions != null) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   191
                ret = _loadedExternalExtensionFunctions.get(name);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   192
            }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   193
            if (ret == null) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   194
                ret = super.loadClass(name);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   195
            }
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   196
            return ret;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   197
         }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
        /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
         * Access to final protected superclass member from outer class.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
         */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
        Class defineClass(final byte[] b) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
            return defineClass(null, b, 0, b.length);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
        }
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   205
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   206
        Class defineClass(final byte[] b, ProtectionDomain pd) {
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   207
            return defineClass(null, b, 0, b.length, pd);
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   208
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   213
     * Create an XSLTC template object from the bytecodes.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
     * The bytecodes for the translet and auxiliary classes, plus the name of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
     * the main translet class, must be supplied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
    protected TemplatesImpl(byte[][] bytecodes, String transletName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
        Properties outputProperties, int indentNumber,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
        TransformerFactoryImpl tfactory)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
        _bytecodes = bytecodes;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   222
        init(transletName, outputProperties, indentNumber, tfactory);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
     * Create an XSLTC template object from the translet class definition(s).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
     */
42247
52fafb950d5a 8158619: Very large CDATA section in XML document causes OOME
joehw
parents: 39801
diff changeset
   228
    protected TemplatesImpl(Class<?>[] transletClasses, String transletName,
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
        Properties outputProperties, int indentNumber,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
        TransformerFactoryImpl tfactory)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
        _class     = transletClasses;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   233
        _transletIndex = 0;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   234
        init(transletName, outputProperties, indentNumber, tfactory);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   235
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   236
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   237
    private void init(String transletName,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   238
        Properties outputProperties, int indentNumber,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   239
        TransformerFactoryImpl tfactory) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
        _name      = transletName;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
        _outputProperties = outputProperties;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
        _indentNumber = indentNumber;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
        _tfactory = tfactory;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   244
        _useServicesMechanism = tfactory.useServicesMechnism();
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   245
        _accessExternalStylesheet = (String) tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   247
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
     * Need for de-serialization, see readObject().
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
    public TemplatesImpl() { }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
     *  Overrides the default readObject implementation since we decided
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
     *  it would be cleaner not to serialize the entire tranformer
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
     *  factory.  [ ref bugzilla 12317 ]
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
     *  We need to check if the user defined class for URIResolver also
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
     *  implemented Serializable
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
     *  if yes then we need to deserialize the URIResolver
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
     *  Fix for bugzilla bug 22438
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
     */
33350
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   261
    @SuppressWarnings("unchecked")
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
    private void  readObject(ObjectInputStream is)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
      throws IOException, ClassNotFoundException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
    {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   265
        SecurityManager security = System.getSecurityManager();
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   266
        if (security != null){
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   267
            String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   268
            if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   269
                ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   270
                throw new UnsupportedOperationException(err.toString());
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   271
            }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   272
        }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   273
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   274
        // We have to read serialized fields first.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   275
        ObjectInputStream.GetField gf = is.readFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   276
        _name = (String)gf.get("_name", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   277
        _bytecodes = (byte[][])gf.get("_bytecodes", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   278
        _class = (Class[])gf.get("_class", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   279
        _transletIndex = gf.get("_transletIndex", -1);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   280
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   281
        _outputProperties = (Properties)gf.get("_outputProperties", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   282
        _indentNumber = gf.get("_indentNumber", 0);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   283
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
        if (is.readBoolean()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
            _uriResolver = (URIResolver) is.readObject();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   286
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
        _tfactory = new TransformerFactoryImpl();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
     *  This is to fix bugzilla bug 22438
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
     *  If the user defined class implements URIResolver and Serializable
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
     *  then we want it to get serialized
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
    private void writeObject(ObjectOutputStream os)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
        throws IOException, ClassNotFoundException {
33350
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   299
        if (_auxClasses != null) {
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   300
            //throw with the same message as when Hashtable was used for compatibility.
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   301
            throw new NotSerializableException(
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   302
                    "com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable");
97bf4aeb431d 8079323: Serialization compatibility for Templates: need to exclude Hashtable from serialization
joehw
parents: 33349
diff changeset
   303
        }
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   304
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   305
        // Write serialized fields
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   306
        ObjectOutputStream.PutField pf = os.putFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   307
        pf.put("_name", _name);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   308
        pf.put("_bytecodes", _bytecodes);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   309
        pf.put("_class", _class);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   310
        pf.put("_transletIndex", _transletIndex);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   311
        pf.put("_outputProperties", _outputProperties);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   312
        pf.put("_indentNumber", _indentNumber);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   313
        os.writeFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   314
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   315
        if (_uriResolver instanceof Serializable) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   316
            os.writeBoolean(true);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   317
            os.writeObject((Serializable) _uriResolver);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   318
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   319
        else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   320
            os.writeBoolean(false);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   321
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   322
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   323
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   324
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   325
     * Return the state of the services mechanism feature.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   326
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   327
    public boolean useServicesMechnism() {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   328
        return _useServicesMechanism;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   329
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   330
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   331
     /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   332
     * Store URIResolver needed for Transformers.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   333
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   334
    public synchronized void setURIResolver(URIResolver resolver) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   335
        _uriResolver = resolver;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   336
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   337
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   338
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   339
     * The TransformerFactory must pass us the translet bytecodes using this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   340
     * method before we can create any translet instances
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   341
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   342
     * Note: This method is private for security reasons. See
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   343
     * CR 6537898. When merging with Apache, we must ensure
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   344
     * that the privateness of this method is maintained (that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   345
     * is why it wasn't removed).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   346
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   347
    private synchronized void setTransletBytecodes(byte[][] bytecodes) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   348
        _bytecodes = bytecodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   349
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   350
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   351
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   352
     * Returns the translet bytecodes stored in this template
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   353
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   354
     * Note: This method is private for security reasons. See
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   355
     * CR 6537898. When merging with Apache, we must ensure
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   356
     * that the privateness of this method is maintained (that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   357
     * is why it wasn't removed).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   358
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   359
    private synchronized byte[][] getTransletBytecodes() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   360
        return _bytecodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   361
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   362
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   363
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   364
     * Returns the translet bytecodes stored in this template
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   365
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   366
     * Note: This method is private for security reasons. See
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   367
     * CR 6537898. When merging with Apache, we must ensure
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   368
     * that the privateness of this method is maintained (that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   369
     * is why it wasn't removed).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   370
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   371
    private synchronized Class[] getTransletClasses() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   372
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   373
            if (_class == null) defineTransletClasses();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   374
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   375
        catch (TransformerConfigurationException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   376
            // Falls through
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   377
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   378
        return _class;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   379
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   380
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   381
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   382
     * Returns the index of the main class in array of bytecodes
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   383
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   384
    public synchronized int getTransletIndex() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   385
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   386
            if (_class == null) defineTransletClasses();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   387
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   388
        catch (TransformerConfigurationException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   389
            // Falls through
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   390
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   391
        return _transletIndex;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   392
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   393
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   394
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   395
     * The TransformerFactory should call this method to set the translet name
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   396
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   397
    protected synchronized void setTransletName(String name) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   398
        _name = name;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   399
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   400
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   401
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   402
     * Returns the name of the main translet class stored in this template
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   403
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   404
    protected synchronized String getTransletName() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   405
        return _name;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   406
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   407
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   408
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   409
    /**
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   410
     * Creates a module layer with one module that is defined to the given class
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   411
     * loader.
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   412
     */
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   413
    private Module createModule(ModuleDescriptor descriptor, ClassLoader loader) {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   414
        String mn = descriptor.name();
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   415
42803
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   416
        ModuleReference mref = new ModuleReference(descriptor, null) {
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   417
            @Override
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   418
            public ModuleReader open() {
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   419
                throw new UnsupportedOperationException();
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   420
            }
d78543be1ebb 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42392
diff changeset
   421
        };
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   422
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   423
        ModuleFinder finder = new ModuleFinder() {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   424
            @Override
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   425
            public Optional<ModuleReference> find(String name) {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   426
                if (name.equals(mn)) {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   427
                    return Optional.of(mref);
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   428
                } else {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   429
                    return Optional.empty();
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   430
                }
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   431
            }
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   432
            @Override
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   433
            public Set<ModuleReference> findAll() {
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   434
                return Set.of(mref);
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   435
            }
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   436
        };
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   437
44558
2ee2259a06e2 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44376
diff changeset
   438
        ModuleLayer bootLayer = ModuleLayer.boot();
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   439
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   440
        Configuration cf = bootLayer.configuration()
43747
9d82e9cac79e 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43254
diff changeset
   441
                .resolve(finder, ModuleFinder.of(), Set.of(mn));
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   442
44558
2ee2259a06e2 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44376
diff changeset
   443
        PrivilegedAction<ModuleLayer> pa = () -> bootLayer.defineModules(cf, name -> loader);
2ee2259a06e2 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44376
diff changeset
   444
        ModuleLayer layer = AccessController.doPrivileged(pa);
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   445
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   446
        Module m = layer.findModule(mn).get();
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   447
        assert m.getLayer() == layer;
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   448
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   449
        return m;
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   450
    }
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   451
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   452
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   453
     * Defines the translet class and auxiliary classes.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   454
     * Returns a reference to the Class object that defines the main class
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   455
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   456
    private void defineTransletClasses()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   457
        throws TransformerConfigurationException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   458
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   459
        if (_bytecodes == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   460
            ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   461
            throw new TransformerConfigurationException(err.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   462
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   463
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   464
        TransletClassLoader loader = (TransletClassLoader)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   465
            AccessController.doPrivileged(new PrivilegedAction() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   466
                public Object run() {
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   467
                    return new TransletClassLoader(ObjectFactory.findClassLoader(),_tfactory.getExternalExtensionsMap());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   468
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   469
            });
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   470
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   471
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   472
            final int classCount = _bytecodes.length;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   473
            _class = new Class[classCount];
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   474
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   475
            if (classCount > 1) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   476
                _auxClasses = new HashMap<>();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   477
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   478
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   479
            // create a module for the translet
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   480
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   481
            String mn = "jdk.translet";
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   482
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   483
            String pn = _tfactory.getPackageName();
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   484
            assert pn != null && pn.length() > 0;
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   485
43747
9d82e9cac79e 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43254
diff changeset
   486
            ModuleDescriptor descriptor =
9d82e9cac79e 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43254
diff changeset
   487
                ModuleDescriptor.newModule(mn, Set.of(ModuleDescriptor.Modifier.SYNTHETIC))
9d82e9cac79e 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43254
diff changeset
   488
                                .requires("java.xml")
44376
d1cd4860ffe4 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43747
diff changeset
   489
                                .exports(pn, Set.of("java.xml"))
43747
9d82e9cac79e 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43254
diff changeset
   490
                                .build();
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   491
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   492
            Module m = createModule(descriptor, loader);
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   493
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   494
            // the module needs access to runtime classes
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   495
            Module thisModule = TemplatesImpl.class.getModule();
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   496
            // the module also needs permission to access each package
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   497
            // that is exported to it
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   498
            PermissionCollection perms =
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   499
                new RuntimePermission("*").newPermissionCollection();
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   500
            Arrays.asList(Constants.PKGS_USED_BY_TRANSLET_CLASSES).forEach(p -> {
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   501
                thisModule.addExports(p, m);
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   502
                perms.add(new RuntimePermission("accessClassInPackage." + p));
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   503
            });
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   504
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   505
            CodeSource codeSource = new CodeSource(null, (CodeSigner[])null);
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   506
            ProtectionDomain pd = new ProtectionDomain(codeSource, perms,
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   507
                                                       loader, null);
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   508
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   509
            // java.xml needs to instantiate the translet class
37838
45821736044e 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36520
diff changeset
   510
            thisModule.addReads(m);
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   511
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   512
            for (int i = 0; i < classCount; i++) {
43254
0dd6e35cf667 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42803
diff changeset
   513
                _class[i] = loader.defineClass(_bytecodes[i], pd);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   514
                final Class superClass = _class[i].getSuperclass();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   515
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   516
                // Check if this is the main class
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   517
                if (superClass.getName().equals(ABSTRACT_TRANSLET)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   518
                    _transletIndex = i;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   519
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   520
                else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   521
                    _auxClasses.put(_class[i].getName(), _class[i]);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   522
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   523
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   524
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   525
            if (_transletIndex < 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   526
                ErrorMsg err= new ErrorMsg(ErrorMsg.NO_MAIN_TRANSLET_ERR, _name);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   527
                throw new TransformerConfigurationException(err.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   528
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   529
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   530
        catch (ClassFormatError e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   531
            ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 38501
diff changeset
   532
            throw new TransformerConfigurationException(err.toString(), e);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   533
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   534
        catch (LinkageError e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   535
            ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
36520
cb52aa47ff0a 8142968: Module System implementation
alanb
parents: 33350
diff changeset
   536
            throw new TransformerConfigurationException(err.toString(), e);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   537
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   538
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   539
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   540
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   541
     * This method generates an instance of the translet class that is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   542
     * wrapped inside this Template. The translet instance will later
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   543
     * be wrapped inside a Transformer object.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   544
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   545
    private Translet getTransletInstance()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   546
        throws TransformerConfigurationException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   547
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   548
            if (_name == null) return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   549
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   550
            if (_class == null) defineTransletClasses();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   551
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   552
            // The translet needs to keep a reference to all its auxiliary
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   553
            // class to prevent the GC from collecting them
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
   554
            AbstractTranslet translet = (AbstractTranslet)
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
   555
                    _class[_transletIndex].getConstructor().newInstance();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   556
            translet.postInitialization();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   557
            translet.setTemplates(this);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   558
            translet.setServicesMechnism(_useServicesMechanism);
17534
21dc0b2762da 8011653: Upgrade JDK8 to JAXP 1.5
joehw
parents: 16953
diff changeset
   559
            translet.setAllowedProtocols(_accessExternalStylesheet);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   560
            if (_auxClasses != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   561
                translet.setAuxiliaryClasses(_auxClasses);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   562
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   563
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   564
            return translet;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   565
        }
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
   566
        catch (InstantiationException | IllegalAccessException |
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
   567
                NoSuchMethodException | InvocationTargetException e) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   568
            ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44558
diff changeset
   569
            throw new TransformerConfigurationException(err.toString(), e);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   570
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   571
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   572
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   573
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   574
     * Implements JAXP's Templates.newTransformer()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   575
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   576
     * @throws TransformerConfigurationException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   577
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   578
    public synchronized Transformer newTransformer()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   579
        throws TransformerConfigurationException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   580
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   581
        TransformerImpl transformer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   582
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   583
        transformer = new TransformerImpl(getTransletInstance(), _outputProperties,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   584
            _indentNumber, _tfactory);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   585
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   586
        if (_uriResolver != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   587
            transformer.setURIResolver(_uriResolver);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   588
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   589
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   590
        if (_tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   591
            transformer.setSecureProcessing(true);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   592
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   593
        return transformer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   594
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   595
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   596
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   597
     * Implements JAXP's Templates.getOutputProperties(). We need to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   598
     * instanciate a translet to get the output settings, so
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   599
     * we might as well just instanciate a Transformer and use its
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   600
     * implementation of this method.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   601
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   602
    public synchronized Properties getOutputProperties() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   603
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   604
            return newTransformer().getOutputProperties();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   605
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   606
        catch (TransformerConfigurationException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   607
            return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   608
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   609
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   610
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   611
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   612
     * Return the thread local copy of the stylesheet DOM.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   613
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   614
    public DOM getStylesheetDOM() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   615
        return (DOM)_sdom.get();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   616
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   617
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   618
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   619
     * Set the thread local copy of the stylesheet DOM.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   620
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   621
    public void setStylesheetDOM(DOM sdom) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   622
        _sdom.set(sdom);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   623
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   624
}