src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
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: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * $Id: Stylesheet.java,v 1.5 2005/09/28 13:48:16 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.BasicType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.FieldGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
41623
d32a755d06d1 8167179: Make XSL generated namespace prefixes local to transformation process
aefimov
parents: 33349
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.bcel.internal.generic.ISTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.bcel.internal.generic.PUTSTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.bcel.internal.generic.TargetLostException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.bcel.internal.util.InstructionFinder;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import com.sun.org.apache.xml.internal.dtm.DTM;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    56
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    57
import java.util.ArrayList;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    58
import java.util.HashMap;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    59
import java.util.Iterator;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    60
import java.util.List;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    61
import java.util.Map;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    62
import java.util.Properties;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    63
import java.util.StringTokenizer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
public final class Stylesheet extends SyntaxTreeNode {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     * XSLT version defined in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    private String _version;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * Internal name of this stylesheet used as a key into the symbol table.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    private QName _name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * A URI that represents the system ID for this stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    private String _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     * A reference to the parent stylesheet or null if topmost.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    private Stylesheet _parentStylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * Contains global variables and parameters defined in the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    95
    private List<VariableBase> _globals = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * Used to cache the result returned by <code>hasLocalParams()</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    private Boolean _hasLocalParams = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     * The name of the class being generated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    private String _className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
      * Contains all templates defined in this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
      */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   110
    private final List<Template> _templates = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     * Used to cache result of <code>getAllValidTemplates()</code>. Only
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * set in top-level stylesheets that include/import other stylesheets.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   116
    private List<Template> _allValidTemplates = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     * Counter to generate unique mode suffixes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    private int _nextModeSerial = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
     * Mapping between mode names and Mode instances.
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
     */
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   126
    private final Map<String, Mode> _modes = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * A reference to the default Mode object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    private Mode _defaultMode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
     * Mapping between extension URIs and their prefixes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
     */
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   136
    private final Map<String, String> _extensions = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * Reference to the stylesheet from which this stylesheet was
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     * imported (if any).
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    public Stylesheet _importedFrom = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     * Reference to the stylesheet from which this stylesheet was
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * included (if any).
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    public Stylesheet _includedFrom = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * Array of all the stylesheets imported or included from this one.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   153
    private List<Stylesheet> _includedStylesheets = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * Import precendence for this stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    private int _importPrecedence = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     * Minimum precendence of any descendant stylesheet by inclusion or
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     * importation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    private int _minimumDescendantPrecedence = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * Mapping between key names and Key objects (needed by Key/IdPattern).
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     */
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   169
    private Map<String, Key> _keys = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * A reference to the SourceLoader set by the user (a URIResolver
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     * if the JAXP API is being used).
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    private SourceLoader _loader = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * Flag indicating if format-number() is called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    private boolean _numberFormattingUsed = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * Flag indicating if this is a simplified stylesheets. A template
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     * matching on "/" must be added in this case.
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    private boolean _simplified = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     * Flag indicating if multi-document support is needed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    private boolean _multiDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * Flag indicating if nodset() is called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    private boolean _callsNodeset = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     * Flag indicating if id() is called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    private boolean _hasIdCall = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     * Set to true to enable template inlining optimization.
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   205
     * @see XSLTC#_templateInlining
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     */
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   207
    private boolean _templateInlining = false;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * A reference to the last xsl:output object found in the styleshet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    private Output  _lastOutputElement = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     * Output properties for this stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    private Properties _outputProperties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     * Output method for this stylesheet (must be set to one of
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     * the constants defined below).
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    private int _outputMethod = UNKNOWN_OUTPUT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    // Output method constants
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    public static final int UNKNOWN_OUTPUT = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    public static final int XML_OUTPUT     = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    public static final int HTML_OUTPUT    = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    public static final int TEXT_OUTPUT    = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     * Return the output method
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    public int getOutputMethod() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        return _outputMethod;
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     * Check and set the output method
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    private void checkOutputMethod() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        if (_lastOutputElement != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            String method = _lastOutputElement.getOutputMethod();
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            if (method != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                if (method.equals("xml"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                    _outputMethod = XML_OUTPUT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                else if (method.equals("html"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                    _outputMethod = HTML_OUTPUT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
                else if (method.equals("text"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                    _outputMethod = TEXT_OUTPUT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    public boolean getTemplateInlining() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
        return _templateInlining;
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    public void setTemplateInlining(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        _templateInlining = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    public boolean isSimplified() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        return(_simplified);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    public void setSimplified() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        _simplified = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    public void setHasIdCall(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        _hasIdCall = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    public void setOutputProperty(String key, String value) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        if (_outputProperties == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            _outputProperties = new Properties();
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        _outputProperties.setProperty(key, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    public void setOutputProperties(Properties props) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        _outputProperties = props;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    public Properties getOutputProperties() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        return _outputProperties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    public Output getLastOutputElement() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        return _lastOutputElement;
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
    public void setMultiDocument(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
        _multiDocument = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    public boolean isMultiDocument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        return _multiDocument;
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    public void setCallsNodeset(boolean flag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        if (flag) setMultiDocument(flag);
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        _callsNodeset = flag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    public boolean callsNodeset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        return _callsNodeset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    public void numberFormattingUsed() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        _numberFormattingUsed = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
         * Fix for bug 23046, if the stylesheet is included, set the
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
         * numberFormattingUsed flag to the parent stylesheet too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
         * AbstractTranslet.addDecimalFormat() will be inlined once for the
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
         * outer most stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        Stylesheet parent = getParentStylesheet();
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        if (null != parent) parent.numberFormattingUsed();
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
    public void setImportPrecedence(final int precedence) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        // Set import precedence for this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        _importPrecedence = precedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        // Set import precedence for all included stylesheets
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   328
        final Iterator<SyntaxTreeNode> elements = elements();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   329
        while (elements.hasNext()) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   330
            SyntaxTreeNode child = elements.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
            if (child instanceof Include) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                Stylesheet included = ((Include)child).getIncludedStylesheet();
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                if (included != null && included._includedFrom == this) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                    included.setImportPrecedence(precedence);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        // Set import precedence for the stylesheet that imported this one
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        if (_importedFrom != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
            if (_importedFrom.getImportPrecedence() < precedence) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                final Parser parser = getParser();
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                final int nextPrecedence = parser.getNextImportPrecedence();
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                _importedFrom.setImportPrecedence(nextPrecedence);
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        // Set import precedence for the stylesheet that included this one
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        else if (_includedFrom != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
            if (_includedFrom.getImportPrecedence() != precedence)
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
                _includedFrom.setImportPrecedence(precedence);
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    public int getImportPrecedence() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        return _importPrecedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * Get the minimum of the precedence of this stylesheet, any stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     * imported by this stylesheet and any include/import descendant of this
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    public int getMinimumDescendantPrecedence() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        if (_minimumDescendantPrecedence == -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
            // Start with precedence of current stylesheet as a basis.
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
            int min = getImportPrecedence();
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
            // Recursively examine all imported/included stylesheets.
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
            final int inclImpCount = (_includedStylesheets != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                                          ? _includedStylesheets.size()
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
                                          : 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
            for (int i = 0; i < inclImpCount; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   374
                int prec = (_includedStylesheets.get(i)).getMinimumDescendantPrecedence();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                if (prec < min) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                    min = prec;
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
            _minimumDescendantPrecedence = min;
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        return _minimumDescendantPrecedence;
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    public boolean checkForLoop(String systemId) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        // Return true if this stylesheet includes/imports itself
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        if (_systemId != null && _systemId.equals(systemId)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
            return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
        // Then check with any stylesheets that included/imported this one
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        if (_parentStylesheet != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
            return _parentStylesheet.checkForLoop(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        // Otherwise OK
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
    public void setParser(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        super.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
        _name = makeStylesheetName("__stylesheet_");
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    public void setParentStylesheet(Stylesheet parent) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
        _parentStylesheet = parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
    public Stylesheet getParentStylesheet() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        return _parentStylesheet;
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    public void setImportingStylesheet(Stylesheet parent) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        _importedFrom = parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
        parent.addIncludedStylesheet(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
    public void setIncludingStylesheet(Stylesheet parent) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        _includedFrom = parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        parent.addIncludedStylesheet(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    public void addIncludedStylesheet(Stylesheet child) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
        if (_includedStylesheets == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   423
            _includedStylesheets = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   425
        _includedStylesheets.add(child);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
    public void setSystemId(String systemId) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        if (systemId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
            _systemId = SystemIDResolver.getAbsoluteURI(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        return _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
    public void setSourceLoader(SourceLoader loader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        _loader = loader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    public SourceLoader getSourceLoader() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
        return _loader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
    private QName makeStylesheetName(String prefix) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
        return getParser().getQName(prefix+getXSLTC().nextStylesheetSerial());
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     * Returns true if this stylesheet has global vars or params.
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    public boolean hasGlobals() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        return _globals.size() > 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
     * Returns true if at least one template in the stylesheet has params
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
     * defined. Uses the variable <code>_hasLocalParams</code> to cache the
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
     * result.
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
    public boolean hasLocalParams() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        if (_hasLocalParams == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   464
           List<Template> templates = getAllValidTemplates();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
            final int n = templates.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            for (int i = 0; i < n; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   467
                final Template template = templates.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                if (template.hasParams()) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   469
                    _hasLocalParams = Boolean.TRUE;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
            }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   473
            _hasLocalParams = Boolean.FALSE;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
            return _hasLocalParams.booleanValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
     * Adds a single prefix mapping to this syntax tree node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
     * @param prefix Namespace prefix.
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
     * @param uri Namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
    protected void addPrefixMapping(String prefix, String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
        if (prefix.equals(EMPTYSTRING) && uri.equals(XHTML_URI)) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
        super.addPrefixMapping(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
     * Store extension URIs
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
    private void extensionURI(String prefixes, SymbolTable stable) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
        if (prefixes != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
            StringTokenizer tokens = new StringTokenizer(prefixes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
            while (tokens.hasMoreTokens()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
                final String prefix = tokens.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
                final String uri = lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
                if (uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
                    _extensions.put(uri, prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
    public boolean isExtension(String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        return (_extensions.get(uri) != null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   511
    public void declareExtensionPrefixes(Parser parser) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
        final SymbolTable stable = parser.getSymbolTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        final String extensionPrefixes = getAttribute("extension-element-prefixes");
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
        extensionURI(extensionPrefixes, stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
     * Parse the version and uri fields of the stylesheet and add an
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
     * entry to the symbol table mapping the name <tt>__stylesheet_</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
     * to an instance of this class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
    public void parseContents(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
        final SymbolTable stable = parser.getSymbolTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
        // Make sure the XSL version set in this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        if ((_version == null) || (_version.equals(EMPTYSTRING))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
            reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR,"version");
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        // Verify that the version is 1.0 and nothing else
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
        else if (!_version.equals("1.0")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
            reportError(this, parser, ErrorMsg.XSL_VERSION_ERR, _version);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
        */
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
        // Add the implicit mapping of 'xml' to the XML namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
        addPrefixMapping("xml", "http://www.w3.org/XML/1998/namespace");
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
        // Report and error if more than one stylesheet defined
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
        final Stylesheet sheet = stable.addStylesheet(_name, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
        if (sheet != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
            // Error: more that one stylesheet defined
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
            ErrorMsg err = new ErrorMsg(ErrorMsg.MULTIPLE_STYLESHEET_ERR,this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
            parser.reportError(Constants.ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
        // If this is a simplified stylesheet we must create a template that
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
        // grabs the root node of the input doc ( <xsl:template match="/"/> ).
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
        // This template needs the current element (the one passed to this
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
        // method) as its only child, so the Template class has a special
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
        // method that handles this (parseSimplified()).
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
        if (_simplified) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
            stable.excludeURI(XSLT_URI);
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
            Template template = new Template();
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
            template.parseSimplified(this, parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
        // Parse the children of this node
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
            parseOwnChildren(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
     * Parse all direct children of the <xsl:stylesheet/> element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
    public final void parseOwnChildren(Parser parser) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   567
        final SymbolTable stable = parser.getSymbolTable();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   568
        final String excludePrefixes = getAttribute("exclude-result-prefixes");
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   569
        final String extensionPrefixes = getAttribute("extension-element-prefixes");
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   570
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   571
        // Exclude XSLT uri
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   572
        stable.pushExcludedNamespacesContext();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   573
        stable.excludeURI(Constants.XSLT_URI);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   574
        stable.excludeNamespaces(excludePrefixes);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   575
        stable.excludeNamespaces(extensionPrefixes);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   576
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   577
        final List<SyntaxTreeNode> contents = getContents();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
        final int count = contents.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
        // We have to scan the stylesheet element's top-level elements for
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
        // variables and/or parameters before we parse the other elements
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
        for (int i = 0; i < count; i++) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   583
            SyntaxTreeNode child = contents.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
            if ((child instanceof VariableBase) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
                (child instanceof NamespaceAlias)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
                parser.getSymbolTable().setCurrentNode(child);
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
                child.parseContents(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        // Now go through all the other top-level elements...
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        for (int i = 0; i < count; i++) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   593
            SyntaxTreeNode child = contents.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
            if (!(child instanceof VariableBase) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
                !(child instanceof NamespaceAlias)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
                parser.getSymbolTable().setCurrentNode(child);
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
                child.parseContents(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
            // All template code should be compiled as methods if the
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
            // <xsl:apply-imports/> element was ever used in this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
            if (!_templateInlining && (child instanceof Template)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
                Template template = (Template)child;
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
                String name = "template$dot$" + template.getPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
                template.setName(parser.getQName(name));
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   608
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   609
        stable.popExcludedNamespacesContext();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
    public void processModes() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
        if (_defaultMode == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
            _defaultMode = new Mode(null, this, Constants.EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
        _defaultMode.processPatterns(_keys);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   616
        _modes.values().stream().forEach((mode) -> {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
            mode.processPatterns(_keys);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   618
        });
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
    private void compileModes(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
        _defaultMode.compileApplyTemplates(classGen);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   623
        _modes.values().stream().forEach((mode) -> {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
            mode.compileApplyTemplates(classGen);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   625
        });
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
    public Mode getMode(QName modeName) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
        if (modeName == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
            if (_defaultMode == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                _defaultMode = new Mode(null, this, Constants.EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
            return _defaultMode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
        else {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   636
            Mode mode = _modes.get(modeName.getStringRep());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
            if (mode == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
                final String suffix = Integer.toString(_nextModeSerial++);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   639
                _modes.put(modeName.getStringRep(), mode = new Mode(modeName, this, suffix));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
            return mode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * Type check all the children of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
        final int count = _globals.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        for (int i = 0; i < count; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   651
            final VariableBase var = _globals.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
            var.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        return typeCheckContents(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
     * Translate the stylesheet into JVM bytecodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        translate();
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
    private void addDOMField(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
        final FieldGen fgen = new FieldGen(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
                                           Util.getJCRefType(DOM_INTF_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
                                           DOM_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
                                           classGen.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        classGen.addField(fgen.getField());
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
     * Add a static field
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
    private void addStaticField(ClassGenerator classGen, String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
                                String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        final FieldGen fgen = new FieldGen(ACC_PROTECTED|ACC_STATIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                                           Util.getJCRefType(type),
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
                                           name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
                                           classGen.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        classGen.addField(fgen.getField());
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
     * Translate the stylesheet into JVM bytecodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
    public void translate() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
        _className = getXSLTC().getClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
        // Define a new class by extending TRANSLET_CLASS
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
        final ClassGenerator classGen =
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
            new ClassGenerator(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                               TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
                               Constants.EMPTYSTRING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
                               ACC_PUBLIC | ACC_SUPER,
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                               null, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
        addDOMField(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
        // Compile transform() to initialize parameters, globals & output
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
        // and run the transformation
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        compileTransform(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
        // Translate all non-template elements and filter out all templates
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   707
        final Iterator<SyntaxTreeNode> elements = elements();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   708
        while (elements.hasNext()) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   709
            SyntaxTreeNode element = elements.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
            // xsl:template
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
            if (element instanceof Template) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
                // Separate templates by modes
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
                final Template template = (Template)element;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   714
                //_templates.add(template);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
                getMode(template.getModeName()).addTemplate(template);
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
            // xsl:attribute-set
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
            else if (element instanceof AttributeSet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
                ((AttributeSet)element).translate(classGen, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
            else if (element instanceof Output) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
                // save the element for later to pass to compileConstructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
                Output output = (Output)element;
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
                if (output.enabled()) _lastOutputElement = output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
                // Global variables and parameters are handled elsewhere.
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
                // Other top-level non-template elements are ignored. Literal
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
                // elements outside of templates will never be output.
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
        checkOutputMethod();
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
        processModes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
        compileModes(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
        compileStaticInitializer(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
        compileConstructor(classGen, _lastOutputElement);
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        if (!getParser().errorsFound()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
            getXSLTC().dumpClass(classGen.getJavaClass());
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
     * Compile the namesArray, urisArray and typesArray into
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
     * the static initializer. They are read-only from the
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
     * translet. All translet instances can share a single
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
     * copy of this informtion.
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
    private void compileStaticInitializer(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
        final MethodGenerator staticConst =
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
            new MethodGenerator(ACC_PUBLIC|ACC_STATIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
                                null, null, "<clinit>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
                                _className, il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
        addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMES_ARRAY_FIELD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        addStaticField(classGen, "[" + STRING_SIG, STATIC_URIS_ARRAY_FIELD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
        addStaticField(classGen, "[I", STATIC_TYPES_ARRAY_FIELD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
        addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMESPACE_ARRAY_FIELD);
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
        // Create fields of type char[] that will contain literal text from
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
        // the stylesheet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
        final int charDataFieldCount = getXSLTC().getCharacterDataCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
        for (int i = 0; i < charDataFieldCount; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
            addStaticField(classGen, STATIC_CHAR_DATA_FIELD_SIG,
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
                           STATIC_CHAR_DATA_FIELD+i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
        // Put the names array into the translet - used for dom/translet mapping
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   773
        final List<String> namesIndex = getXSLTC().getNamesIndex();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
        int size = namesIndex.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
        String[] namesArray = new String[size];
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
        String[] urisArray = new String[size];
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        int[] typesArray = new int[size];
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
        for (int i = 0; i < size; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   781
            String encodedName = namesIndex.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
            if ((index = encodedName.lastIndexOf(':')) > -1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
                urisArray[i] = encodedName.substring(0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
            index = index + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
            if (encodedName.charAt(index) == '@') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
                typesArray[i] = DTM.ATTRIBUTE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
                index++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
            } else if (encodedName.charAt(index) == '?') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
                typesArray[i] = DTM.NAMESPACE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
                index++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
                typesArray[i] = DTM.ELEMENT_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            if (index == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
                namesArray[i] = encodedName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
                namesArray[i] = encodedName.substring(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   805
        staticConst.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
        il.append(new PUSH(cpg, size));
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   808
        int namesArrayRef = cpg.addFieldref(_className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   809
                                            STATIC_NAMES_ARRAY_FIELD,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   810
                                            NAMES_INDEX_SIG);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   811
        il.append(new PUTSTATIC(namesArrayRef));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   812
        staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
        for (int i = 0; i < size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
            final String name = namesArray[i];
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   816
            staticConst.markChunkStart();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   817
            il.append(new GETSTATIC(namesArrayRef));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
            il.append(new PUSH(cpg, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
            il.append(new PUSH(cpg, name));
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
            il.append(AASTORE);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   821
            staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   824
        staticConst.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
        il.append(new PUSH(cpg, size));
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   827
        int urisArrayRef = cpg.addFieldref(_className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   828
                                           STATIC_URIS_ARRAY_FIELD,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   829
                                           URIS_INDEX_SIG);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   830
        il.append(new PUTSTATIC(urisArrayRef));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   831
        staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        for (int i = 0; i < size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
            final String uri = urisArray[i];
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   835
            staticConst.markChunkStart();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   836
            il.append(new GETSTATIC(urisArrayRef));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
            il.append(new PUSH(cpg, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
            il.append(new PUSH(cpg, uri));
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
            il.append(AASTORE);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   840
            staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   843
        staticConst.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
        il.append(new PUSH(cpg, size));
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
        il.append(new NEWARRAY(BasicType.INT));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   846
        int typesArrayRef = cpg.addFieldref(_className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   847
                                            STATIC_TYPES_ARRAY_FIELD,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   848
                                            TYPES_INDEX_SIG);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   849
        il.append(new PUTSTATIC(typesArrayRef));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   850
        staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
        for (int i = 0; i < size; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
            final int nodeType = typesArray[i];
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   854
            staticConst.markChunkStart();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   855
            il.append(new GETSTATIC(typesArrayRef));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
            il.append(new PUSH(cpg, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
            il.append(new PUSH(cpg, nodeType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
            il.append(IASTORE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
        // Put the namespace names array into the translet
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   862
        final List<String> namespaces = getXSLTC().getNamespaceIndex();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   863
        staticConst.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
        il.append(new PUSH(cpg, namespaces.size()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   866
        int namespaceArrayRef = cpg.addFieldref(_className,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   867
                                                STATIC_NAMESPACE_ARRAY_FIELD,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   868
                                                NAMESPACE_INDEX_SIG);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   869
        il.append(new PUTSTATIC(namespaceArrayRef));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   870
        staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
        for (int i = 0; i < namespaces.size(); i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   873
            final String ns = namespaces.get(i);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   874
            staticConst.markChunkStart();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   875
            il.append(new GETSTATIC(namespaceArrayRef));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
            il.append(new PUSH(cpg, i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
            il.append(new PUSH(cpg, ns));
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
            il.append(AASTORE);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   879
            staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
        // Grab all the literal text in the stylesheet and put it in a char[]
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
        final int charDataCount = getXSLTC().getCharacterDataCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
        final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
        for (int i = 0; i < charDataCount; i++) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   886
            staticConst.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
            il.append(new PUSH(cpg, getXSLTC().getCharacterData(i)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
            il.append(new INVOKEVIRTUAL(toCharArray));
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
            il.append(new PUTSTATIC(cpg.addFieldref(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
                                               STATIC_CHAR_DATA_FIELD+i,
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
                                               STATIC_CHAR_DATA_FIELD_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   892
            staticConst.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   897
        classGen.addMethod(staticConst);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
     * Compile the translet's constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
    private void compileConstructor(ClassGenerator classGen, Output output) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
        final MethodGenerator constructor =
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
                                null, null, "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
                                _className, il, cpg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
        // Call the constructor in the AbstractTranslet superclass
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
        il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
                                                     "<init>", "()V")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   920
        constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
        il.append(new GETSTATIC(cpg.addFieldref(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
                                                STATIC_NAMES_ARRAY_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
                                                NAMES_INDEX_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
                                               NAMES_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
                                               NAMES_INDEX_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
        il.append(new GETSTATIC(cpg.addFieldref(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
                                                STATIC_URIS_ARRAY_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
                                                URIS_INDEX_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
                                               URIS_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
                                               URIS_INDEX_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   936
        constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   938
        constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        il.append(new GETSTATIC(cpg.addFieldref(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
                                                STATIC_TYPES_ARRAY_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
                                                TYPES_INDEX_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
                                               TYPES_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
                                               TYPES_INDEX_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   946
        constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   948
        constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
        il.append(new GETSTATIC(cpg.addFieldref(_className,
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
                                                STATIC_NAMESPACE_ARRAY_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
                                                NAMESPACE_INDEX_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
                                               NAMESPACE_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
                                               NAMESPACE_INDEX_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   956
        constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   958
        constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
        il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION));
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
                                               TRANSLET_VERSION_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
                                               TRANSLET_VERSION_INDEX_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   964
        constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
        if (_hasIdCall) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   967
            constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
            il.append(new PUSH(cpg, Boolean.TRUE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
            il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
                                                   HASIDCALL_INDEX,
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
                                                   HASIDCALL_INDEX_SIG)));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   973
            constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
        // Compile in code to set the output configuration from <xsl:output>
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
        if (output != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
            // Set all the output settings files in the translet
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   979
            constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
            output.translate(classGen, constructor);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   981
            constructor.markChunkEnd();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
        // Compile default decimal formatting symbols.
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
        // This is an implicit, nameless xsl:decimal-format top-level element.
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   986
        if (_numberFormattingUsed) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   987
            constructor.markChunkStart();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
            DecimalFormatting.translateDefaultDFS(classGen, constructor);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   989
            constructor.markChunkEnd();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   990
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   994
        classGen.addMethod(constructor);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
     * Compile a topLevel() method into the output class. This method is
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
     * called from transform() to handle all non-template top-level elements.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
     * Returns the signature of the topLevel() method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
     * Global variables/params and keys are first sorted to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
     * dependencies between them. The XSLT 1.0 spec does not allow a key
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
     * to depend on a variable. However, for compatibility with Xalan
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
     * interpretive, that type of dependency is allowed. Note also that
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
     * the buildKeys() method is still generated as it is used by the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
     * LoadDocument class, but it no longer called from transform().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
    private String compileTopLevel(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
        final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
            Util.getJCRefType(DOM_INTF_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
            Util.getJCRefType(NODE_ITERATOR_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
            Util.getJCRefType(TRANSLET_OUTPUT_SIG)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
        };
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
        final String[] argNames = {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
            DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
        };
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
        final MethodGenerator toplevel =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
                                argTypes, argNames,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
                                "topLevel", _className, il,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
                                classGen.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
        toplevel.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1034
        // Define and initialize 'current' variable with the root node
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1035
        final LocalVariableGen current =
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1036
            toplevel.addLocalVariable("current",
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1037
                                      com.sun.org.apache.bcel.internal.generic.Type.INT,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1038
                                      null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1039
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
        final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
                               "setFilter",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
                               "(Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
        final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1045
                                                        "getIterator",
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1046
                                                        "()"+NODE_ITERATOR_SIG);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
        il.append(toplevel.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
        il.append(new INVOKEINTERFACE(gitr, 1));
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1049
        il.append(toplevel.nextNode());
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1050
        current.setStart(il.append(new ISTORE(current.getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
        // Create a new list containing variables/params + keys
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1053
        List<SyntaxTreeNode> varDepElements = new ArrayList<>(_globals);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1054
        Iterator<SyntaxTreeNode> elements = elements();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1055
        while (elements.hasNext()) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1056
            SyntaxTreeNode element = elements.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
            if (element instanceof Key) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
                varDepElements.add(element);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
        // Determine a partial order for the variables/params and keys
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
        varDepElements = resolveDependencies(varDepElements);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
        // Translate vars/params and keys in the right order
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
        final int count = varDepElements.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
        for (int i = 0; i < count; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1068
            final TopLevelElement tle = (TopLevelElement) varDepElements.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
            tle.translate(classGen, toplevel);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
            if (tle instanceof Key) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
                final Key key = (Key) tle;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
                _keys.put(key.getName(), key);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
        // Compile code for other top-level elements
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1077
       List<Whitespace.WhitespaceRule> whitespaceRules = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
        elements = elements();
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1079
        while (elements.hasNext()) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1080
            SyntaxTreeNode element = elements.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
            // xsl:decimal-format
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
            if (element instanceof DecimalFormatting) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
                ((DecimalFormatting)element).translate(classGen,toplevel);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
            // xsl:strip/preserve-space
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
            else if (element instanceof Whitespace) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
                whitespaceRules.addAll(((Whitespace)element).getRules());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
        // Translate all whitespace strip/preserve rules
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
        if (whitespaceRules.size() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
            Whitespace.translateRules(whitespaceRules,classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
        if (classGen.containsMethod(STRIP_SPACE, STRIP_SPACE_PARAMS) != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
            il.append(toplevel.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
            il.append(new INVOKEINTERFACE(setFilter, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
        // Compute max locals + stack and add method to class
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1105
        classGen.addMethod(toplevel);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
        return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
     * This method returns a vector with variables/params and keys in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
     * order in which they are to be compiled for initialization. The order
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
     * is determined by analyzing the dependencies between them. The XSLT 1.0
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
     * spec does not allow a key to depend on a variable. However, for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
     * compatibility with Xalan interpretive, that type of dependency is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
     * allowed and, therefore, consider to determine the partial order.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1118
    private List<SyntaxTreeNode> resolveDependencies(List<SyntaxTreeNode> input) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1119
        List<SyntaxTreeNode> result = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
        while (input.size() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
            boolean changed = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
            for (int i = 0; i < input.size(); ) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1123
                final TopLevelElement vde = (TopLevelElement) input.get(i);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1124
                final List<SyntaxTreeNode> dep = vde.getDependencies();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
                if (dep == null || result.containsAll(dep)) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1126
                    result.add(vde);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
                    input.remove(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
                    changed = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
                    i++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
            // If nothing was changed in this pass then we have a circular ref
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
            if (!changed) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
                ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
                                            input.toString(), this);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
                getParser().reportError(Constants.ERROR, err);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
                return(result);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
     * Compile a buildKeys() method into the output class. Note that keys
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
     * for the input document are created in topLevel(), not in this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
     * However, we still need this method to create keys for documents loaded
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
     * via the XPath document() function.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
    private String compileBuildKeys(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
        final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
            Util.getJCRefType(DOM_INTF_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
            Util.getJCRefType(NODE_ITERATOR_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
            Util.getJCRefType(TRANSLET_OUTPUT_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
            com.sun.org.apache.bcel.internal.generic.Type.INT
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
        };
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
        final String[] argNames = {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
            DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
        };
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
        final MethodGenerator buildKeys =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
                                argTypes, argNames,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                                "buildKeys", _className, il,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
                                classGen.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
        buildKeys.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1178
        final Iterator<SyntaxTreeNode> elements = elements();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1179
        while (elements.hasNext()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
            // xsl:key
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1181
            final SyntaxTreeNode element = elements.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
            if (element instanceof Key) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
                final Key key = (Key)element;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
                key.translate(classGen, buildKeys);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
                _keys.put(key.getName(),key);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
        // Compute max locals + stack and add method to class
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
        buildKeys.stripAttributes(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
        buildKeys.setMaxLocals();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
        buildKeys.setMaxStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
        buildKeys.removeNOPs();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
        classGen.addMethod(buildKeys.getMethod());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
        return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+"I)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
     * Compile transform() into the output class. This method is used to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
     * initialize global variables and global parameters. The current node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
     * is set to be the document's root node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
    private void compileTransform(ClassGenerator classGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
         * Define the the method transform with the following signature:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
         * void transform(DOM, NodeIterator, HandlerBase)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
        final com.sun.org.apache.bcel.internal.generic.Type[] argTypes =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
            new com.sun.org.apache.bcel.internal.generic.Type[3];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
        argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
        argTypes[1] = Util.getJCRefType(NODE_ITERATOR_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
        argTypes[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
        final String[] argNames = new String[3];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
        argNames[0] = DOCUMENT_PNAME;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
        argNames[1] = ITERATOR_PNAME;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
        argNames[2] = TRANSLET_OUTPUT_PNAME;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
        final InstructionList il = new InstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
        final MethodGenerator transf =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
            new MethodGenerator(ACC_PUBLIC,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
                                argTypes, argNames,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
                                "transform",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
                                _className,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
                                il,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
                                classGen.getConstantPool());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
        transf.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
41623
d32a755d06d1 8167179: Make XSL generated namespace prefixes local to transformation process
aefimov
parents: 33349
diff changeset
  1236
        // call resetPrefixIndex at the beginning of transform
d32a755d06d1 8167179: Make XSL generated namespace prefixes local to transformation process
aefimov
parents: 33349
diff changeset
  1237
        final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "resetPrefixIndex", "()V");
d32a755d06d1 8167179: Make XSL generated namespace prefixes local to transformation process
aefimov
parents: 33349
diff changeset
  1238
        il.append(new INVOKESTATIC(check));
d32a755d06d1 8167179: Make XSL generated namespace prefixes local to transformation process
aefimov
parents: 33349
diff changeset
  1239
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
        // Define and initialize current with the root node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
        final LocalVariableGen current =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
            transf.addLocalVariable("current",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
                                    com.sun.org.apache.bcel.internal.generic.Type.INT,
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1244
                                    null, null);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
        final String applyTemplatesSig = classGen.getApplyTemplatesSig();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
        final int applyTemplates = cpg.addMethodref(getClassName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
                                                    "applyTemplates",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
                                                    applyTemplatesSig);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
        final int domField = cpg.addFieldref(getClassName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
                                             DOM_FIELD,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
                                             DOM_INTF_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
        // push translet for PUTFIELD
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
        // prepare appropriate DOM implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
        if (isMultiDocument()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
            il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
            il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
        il.append(transf.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
                                                     "makeDOMAdapter",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
                                                     "("+DOM_INTF_SIG+")"+
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
                                                     DOM_ADAPTER_SIG)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
        // DOMAdapter is on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
        if (isMultiDocument()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
            final int init = cpg.addMethodref(MULTI_DOM_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
                                              "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
                                              "("+DOM_INTF_SIG+")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
            il.append(new INVOKESPECIAL(init));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
            // MultiDOM is on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
        //store to _dom variable
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
        il.append(new PUTFIELD(domField));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1281
        // continue with globals initialization
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1282
        final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1283
                                                        "getIterator",
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1284
                                                        "()"+NODE_ITERATOR_SIG);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1285
        il.append(transf.loadDOM());
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1286
        il.append(new INVOKEINTERFACE(gitr, 1));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1287
        il.append(transf.nextNode());
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1288
        current.setStart(il.append(new ISTORE(current.getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1289
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
        // Transfer the output settings to the output post-processor
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
        il.append(transf.loadHandler());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
        final int index = cpg.addMethodref(TRANSLET_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
                                           "transferOutputSettings",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
                                           "("+OUTPUT_HANDLER_SIG+")V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
        il.append(new INVOKEVIRTUAL(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
         * Compile buildKeys() method. Note that this method is not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
         * invoked here as keys for the input document are now created
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
         * in topLevel(). However, this method is still needed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
         * LoadDocument class.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
        final String keySig = compileBuildKeys(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
        final int keyIdx = cpg.addMethodref(getClassName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
                                               "buildKeys", keySig);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
        // Look for top-level elements that need handling
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1309
        final Iterator<SyntaxTreeNode> toplevel = elements();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
  1310
        if (_globals.size() > 0 || toplevel.hasNext()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
            // Compile method for handling top-level elements
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
            final String topLevelSig = compileTopLevel(classGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
            // Get a reference to that method
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
            final int topLevelIdx = cpg.addMethodref(getClassName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
                                                     "topLevel",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
                                                     topLevelSig);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
            // Push all parameters on the stack and call topLevel()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
            il.append(classGen.loadTranslet()); // The 'this' pointer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
            il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
            il.append(new GETFIELD(domField));  // The DOM reference
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
            il.append(transf.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
            il.append(transf.loadHandler());    // The output handler
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
            il.append(new INVOKEVIRTUAL(topLevelIdx));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
        // start document
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
        il.append(transf.loadHandler());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
        il.append(transf.startDocument());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
        // push first arg for applyTemplates
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
        // push translet for GETFIELD to get DOM arg
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
        il.append(classGen.loadTranslet());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
        il.append(new GETFIELD(domField));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
        // push remaining 2 args
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
        il.append(transf.loadIterator());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
        il.append(transf.loadHandler());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
        il.append(new INVOKEVIRTUAL(applyTemplates));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
        // endDocument
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
        il.append(transf.loadHandler());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
        il.append(transf.endDocument());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
        il.append(RETURN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
        // Compute max locals + stack and add method to class
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1346
        classGen.addMethod(transf);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
     * Peephole optimization: Remove sequences of [ALOAD, POP].
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
    private void peepHoleOptimization(MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
        final String pattern = "`aload'`pop'`instruction'";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
        final InstructionFinder find = new InstructionFinder(il);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1357
        for(Iterator<InstructionHandle[]> iter=find.search(pattern); iter.hasNext(); ) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1358
            InstructionHandle[] match = iter.next();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
                il.delete(match[0], match[1]);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
            catch (TargetLostException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
                // TODO: move target down into the list
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
    public int addParam(Param param) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1369
        _globals.add(param);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
        return _globals.size() - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
    public int addVariable(Variable global) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1374
        _globals.add(global);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
        return _globals.size() - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
    public void display(int indent) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
        indent(indent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
        Util.println("Stylesheet");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
        displayContents(indent + IndentIncrement);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
    // do we need this wrapper ?????
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
    public String getNamespace(String prefix) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
        return lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
    public String getClassName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
        return _className;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1393
    public List<Template> getTemplates() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
        return _templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1397
    public List<Template> getAllValidTemplates() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
        // Return templates if no imported/included stylesheets
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
        if (_includedStylesheets == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
            return _templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
        // Is returned value cached?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
        if (_allValidTemplates == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1405
            List<Template> templates = new ArrayList<>();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1406
            templates.addAll(_templates);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1407
            for (Stylesheet included : _includedStylesheets) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
                templates.addAll(included.getAllValidTemplates());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
            //templates.addAll(_templates);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
            // Cache results in top-level stylesheet only
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
            if (_parentStylesheet != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
                return templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
            _allValidTemplates = templates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
        return _allValidTemplates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
    protected void addTemplate(Template template) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1423
        _templates.add(template);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
}