src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/UseAttributeSets.java
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
equal deleted inserted replaced
47358:d07d5f7cab35 47359:e1a6c0168741
     1 /*
     1 /*
     2  * reserved comment block
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT REMOVE OR ALTER!
     3  * @LastModified: Oct 2017
     4  */
     4  */
     5 /*
     5 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     7  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     8  * this work for additional information regarding copyright ownership.
    19  * limitations under the License.
    19  * limitations under the License.
    20  */
    20  */
    21 
    21 
    22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
    22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
    23 
    23 
    24 import java.util.StringTokenizer;
       
    25 import java.util.Vector;
       
    26 
       
    27 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
    24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
    28 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
    25 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
    29 import com.sun.org.apache.bcel.internal.generic.InstructionList;
    26 import com.sun.org.apache.bcel.internal.generic.InstructionList;
    30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
    27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
    31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
    28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
    32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
    29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
    33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
    30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
    34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
    31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
       
    32 import java.util.ArrayList;
       
    33 import java.util.List;
       
    34 import java.util.StringTokenizer;
    35 
    35 
    36 /**
    36 /**
    37  * @author Jacek Ambroziak
    37  * @author Jacek Ambroziak
    38  * @author Santiago Pericas-Geertsen
    38  * @author Santiago Pericas-Geertsen
    39  * @author Morten Jorgensen
    39  * @author Morten Jorgensen
    43     // Only error that can occur:
    43     // Only error that can occur:
    44     private final static String ATTR_SET_NOT_FOUND =
    44     private final static String ATTR_SET_NOT_FOUND =
    45         "";
    45         "";
    46 
    46 
    47     // Contains the names of all references attribute sets
    47     // Contains the names of all references attribute sets
    48     private final Vector _sets = new Vector(2);
    48     private final List<QName> _sets = new ArrayList<>(2);
    49 
    49 
    50     /**
    50     /**
    51      * Constructur - define initial attribute sets to use
    51      * Constructur - define initial attribute sets to use
    52      */
    52      */
    53     public UseAttributeSets(String setNames, Parser parser) {
    53     public UseAttributeSets(String setNames, Parser parser) {
    85 
    85 
    86         final ConstantPoolGen cpg = classGen.getConstantPool();
    86         final ConstantPoolGen cpg = classGen.getConstantPool();
    87         final InstructionList il = methodGen.getInstructionList();
    87         final InstructionList il = methodGen.getInstructionList();
    88         final SymbolTable symbolTable = getParser().getSymbolTable();
    88         final SymbolTable symbolTable = getParser().getSymbolTable();
    89 
    89 
    90         // Go through each attribute set and generate a method call
    90         for (QName name : _sets) {
    91         for (int i=0; i<_sets.size(); i++) {
       
    92             // Get the attribute set name
       
    93             final QName name = (QName)_sets.elementAt(i);
       
    94             // Get the AttributeSet reference from the symbol table
    91             // Get the AttributeSet reference from the symbol table
    95             final AttributeSet attrs = symbolTable.lookupAttributeSet(name);
    92             final AttributeSet attrs = symbolTable.lookupAttributeSet(name);
    96             // Compile the call to the set's method if the set exists
    93             // Compile the call to the set's method if the set exists
    97             if (attrs != null) {
    94             if (attrs != null) {
    98                 final String methodName = attrs.getMethodName();
    95                 final String methodName = attrs.getMethodName();
   100                 il.append(methodGen.loadDOM());
    97                 il.append(methodGen.loadDOM());
   101                 il.append(methodGen.loadIterator());
    98                 il.append(methodGen.loadIterator());
   102                 il.append(methodGen.loadHandler());
    99                 il.append(methodGen.loadHandler());
   103                 il.append(methodGen.loadCurrentNode());
   100                 il.append(methodGen.loadCurrentNode());
   104                 final int method = cpg.addMethodref(classGen.getClassName(),
   101                 final int method = cpg.addMethodref(classGen.getClassName(),
   105                                                     methodName, ATTR_SET_SIG);
   102                         methodName, ATTR_SET_SIG);
   106                 il.append(new INVOKESPECIAL(method));
   103                 il.append(new INVOKESPECIAL(method));
   107             }
   104             }
   108             // Generate an error if the attribute set does not exist
   105             // Generate an error if the attribute set does not exist
   109             else {
   106             else {
   110                 final Parser parser = getParser();
   107                 final Parser parser = getParser();