View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  /*
21   * $Id: NamedMethodGenerator.java,v 1.2.4.1 2005/09/05 11:19:56 pvedula Exp $
22   */
23  
24  package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
25  
26  import com.sun.org.apache.bcel.internal.generic.ALOAD;
27  import com.sun.org.apache.bcel.internal.generic.ASTORE;
28  import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
29  import com.sun.org.apache.bcel.internal.generic.Instruction;
30  import com.sun.org.apache.bcel.internal.generic.InstructionList;
31  import com.sun.org.apache.bcel.internal.generic.Type;
32  
33  /**
34   * This class is used for named templates. Named template methods have access
35   * to the DOM, the current iterator, the handler and the current node.
36   * @author Jacek Ambroziak
37   * @author Santiago Pericas-Geertsen
38   */
39  public final class NamedMethodGenerator extends MethodGenerator {
40      protected static final int CURRENT_INDEX  = 4;
41  
42      // The index of the first parameter (after dom/iterator/handler/current)
43      private static final int PARAM_START_INDEX = 5;
44  
45      public NamedMethodGenerator(int access_flags, Type return_type,
46                                  Type[] arg_types, String[] arg_names,
47                                  String method_name, String class_name,
48                                  InstructionList il, ConstantPoolGen cp) {
49          super(access_flags, return_type, arg_types, arg_names, method_name,
50                class_name, il, cp);
51      }
52  
53      public int getLocalIndex(String name) {
54          if (name.equals("current")) {
55              return CURRENT_INDEX;
56          }
57          return super.getLocalIndex(name);
58      }
59  
60      public Instruction loadParameter(int index) {
61          return new ALOAD(index + PARAM_START_INDEX);
62      }
63  
64      public Instruction storeParameter(int index) {
65          return new ASTORE(index + PARAM_START_INDEX);
66      }
67  }