KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > compiler > util > TestGenerator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: TestGenerator.java,v 1.6 2004/02/16 22:26:44 minchau Exp $
18  */

19
20 package org.apache.xalan.xsltc.compiler.util;
21
22 import org.apache.bcel.generic.ALOAD;
23 import org.apache.bcel.generic.ASTORE;
24 import org.apache.bcel.generic.ConstantPoolGen;
25 import org.apache.bcel.generic.ILOAD;
26 import org.apache.bcel.generic.ISTORE;
27 import org.apache.bcel.generic.Instruction;
28 import org.apache.bcel.generic.InstructionList;
29 import org.apache.bcel.generic.Type;
30
31 /**
32  * @author Jacek Ambroziak
33  * @author Santiago Pericas-Geertsen
34  * @author Morten Jorgensen
35  */

36 public final class TestGenerator extends MethodGenerator {
37     private static int CONTEXT_NODE_INDEX = 1;
38     private static int CURRENT_NODE_INDEX = 4;
39     private static int ITERATOR_INDEX = 6;
40
41     private Instruction _aloadDom;
42     private final Instruction _iloadCurrent;
43     private final Instruction _iloadContext;
44     private final Instruction _istoreCurrent;
45     private final Instruction _istoreContext;
46     private final Instruction _astoreIterator;
47     private final Instruction _aloadIterator;
48
49     public TestGenerator(int access_flags, Type return_type,
50              Type[] arg_types, String JavaDoc[] arg_names,
51              String JavaDoc method_name, String JavaDoc class_name,
52              InstructionList il, ConstantPoolGen cp) {
53     super(access_flags, return_type, arg_types, arg_names, method_name,
54           class_name, il, cp);
55     
56     _iloadCurrent = new ILOAD(CURRENT_NODE_INDEX);
57     _istoreCurrent = new ISTORE(CURRENT_NODE_INDEX);
58     _iloadContext = new ILOAD(CONTEXT_NODE_INDEX);
59     _istoreContext = new ILOAD(CONTEXT_NODE_INDEX);
60     _astoreIterator = new ASTORE(ITERATOR_INDEX);
61     _aloadIterator = new ALOAD(ITERATOR_INDEX);
62     }
63
64     public int getHandlerIndex() {
65     return INVALID_INDEX; // not available
66
}
67
68     public int getIteratorIndex() {
69     return ITERATOR_INDEX; // not available
70
}
71
72     public void setDomIndex(int domIndex) {
73     _aloadDom = new ALOAD(domIndex);
74     }
75
76     public Instruction loadDOM() {
77     return _aloadDom;
78     }
79
80     public Instruction loadCurrentNode() {
81     return _iloadCurrent;
82     }
83
84     /** by default context node is the same as current node. MK437 */
85     public Instruction loadContextNode() {
86     return _iloadContext;
87     }
88
89     public Instruction storeContextNode() {
90     return _istoreContext;
91     }
92
93     public Instruction storeCurrentNode() {
94     return _istoreCurrent;
95     }
96
97     public Instruction storeIterator() {
98     return _astoreIterator;
99     }
100     
101     public Instruction loadIterator() {
102     return _aloadIterator;
103     }
104
105     public int getLocalIndex(String JavaDoc name) {
106     if (name.equals("current")) {
107         return CURRENT_NODE_INDEX;
108     }
109     else {
110         return super.getLocalIndex(name);
111     }
112     }
113 }
114
Popular Tags