src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/UnsupportedElement.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) 2015, 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
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *     http://www.apache.org/licenses/LICENSE-2.0
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: UnsupportedElement.java,v 1.2.4.1 2005/09/05 09:26:51 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.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    37
import java.util.ArrayList;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    38
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
final class UnsupportedElement extends SyntaxTreeNode {
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    45
    private List<SyntaxTreeNode> _fallbacks = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    private ErrorMsg _message = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    private boolean _isExtension = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * Basic consutrcor - stores element uri/prefix/localname
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    public UnsupportedElement(String uri, String prefix, String local, boolean isExtension) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
        super(uri, prefix, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
        _isExtension = isExtension;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     * There are different categories of unsupported elements (believe it
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     * or not): there are elements within the XSLT namespace (these would
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     * be elements that are not yet implemented), there are extensions of
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
     * other XSLT processors and there are unrecognised extension elements
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
     * of this XSLT processor. The error message passed to this method
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     * should describe the unsupported element itself and what category
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * the element belongs in.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    public void setErrorMessage(ErrorMsg message) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        _message = message;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * Displays the contents of this element
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    public void display(int indent) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        indent(indent);
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
        Util.println("Unsupported element = " + _qname.getNamespace() +
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
                     ":" + _qname.getLocalPart());
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        displayContents(indent + IndentIncrement);
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * Scan and process all fallback children of the unsupported element.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    private void processFallbacks(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    86
        List<SyntaxTreeNode> children = getContents();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        if (children != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
            final int count = children.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
            for (int i = 0; i < count; i++) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    90
                SyntaxTreeNode child = children.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                if (child instanceof Fallback) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
                    Fallback fallback = (Fallback)child;
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                    fallback.activate();
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
                    fallback.parseContents(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
                    if (_fallbacks == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    96
                        _fallbacks = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                    }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    98
                    _fallbacks.add(child);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     * Find any fallback in the descendant nodes; then activate & parse it
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    public void parseContents(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        processFallbacks(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * Run type check on the fallback element (if any).
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        if (_fallbacks != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            int count = _fallbacks.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            for (int i = 0; i < count; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   118
                Fallback fallback = (Fallback)_fallbacks.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                fallback.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        return Type.Void;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * Translate the fallback element (if any).
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
        if (_fallbacks != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            int count = _fallbacks.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            for (int i = 0; i < count; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   132
                Fallback fallback = (Fallback)_fallbacks.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                fallback.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        // We only go into the else block in forward-compatibility mode, when
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        // the unsupported element has no fallback.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
            // If the unsupported element does not have any fallback child, then
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
            // at runtime, a runtime error should be raised when the unsupported
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            // element is instantiated. Otherwise, no error is thrown.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
            ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
            InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                                                         "(" + STRING_SIG + "Z)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            il.append(new PUSH(cpg, getQName().toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            il.append(new PUSH(cpg, _isExtension));
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            il.append(new INVOKESTATIC(unsupportedElem));
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
}