KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > compiler > FilteredAbsoluteLocationPath


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: FilteredAbsoluteLocationPath.java,v 1.6 2004/02/16 22:24:28 minchau Exp $
18  */

19
20 package org.apache.xalan.xsltc.compiler;
21
22 import org.apache.bcel.generic.ConstantPoolGen;
23 import org.apache.bcel.generic.INVOKEINTERFACE;
24 import org.apache.bcel.generic.INVOKESPECIAL;
25 import org.apache.bcel.generic.InstructionList;
26 import org.apache.bcel.generic.NEW;
27 import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
28 import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
29 import org.apache.xalan.xsltc.compiler.util.NodeType;
30 import org.apache.xalan.xsltc.compiler.util.Type;
31 import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
32
33 /**
34  * @author G. Todd Miller
35  */

36 final class FilteredAbsoluteLocationPath extends Expression {
37     private Expression _path; // may be null
38

39     public FilteredAbsoluteLocationPath() {
40     _path = null;
41     }
42
43     public FilteredAbsoluteLocationPath(Expression path) {
44     _path = path;
45     if (path != null) {
46         _path.setParent(this);
47     }
48     }
49
50     public void setParser(Parser parser) {
51     super.setParser(parser);
52     if (_path != null) {
53         _path.setParser(parser);
54     }
55     }
56
57     public Expression getPath() {
58     return(_path);
59     }
60     
61     public String JavaDoc toString() {
62     return "FilteredAbsoluteLocationPath(" +
63         (_path != null ? _path.toString() : "null") + ')';
64     }
65     
66     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
67     if (_path != null) {
68         final Type ptype = _path.typeCheck(stable);
69         if (ptype instanceof NodeType) { // promote to node-set
70
_path = new CastExpr(_path, Type.NodeSet);
71         }
72     }
73     return _type = Type.NodeSet;
74     }
75     
76     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
77     final ConstantPoolGen cpg = classGen.getConstantPool();
78     final InstructionList il = methodGen.getInstructionList();
79     if (_path != null) {
80         final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR,
81                         "<init>",
82                         "("
83                         + NODE_ITERATOR_SIG
84                         + ")V");
85         // Create new Dup Filter Iterator
86
il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
87         il.append(DUP);
88
89         // Compile relative path iterator(s)
90
_path.translate(classGen, methodGen);
91
92         // Initialize Dup Filter Iterator with iterator from the stack
93
il.append(new INVOKESPECIAL(initDFI));
94     }
95     else {
96         final int git = cpg.addInterfaceMethodref(DOM_INTF,
97                               "getIterator",
98                               "()"+NODE_ITERATOR_SIG);
99         il.append(methodGen.loadDOM());
100         il.append(new INVOKEINTERFACE(git, 1));
101     }
102     }
103 }
104
Popular Tags