KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > AbsoluteLocationPath


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

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
23 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
24 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
25 import com.sun.org.apache.bcel.internal.generic.InstructionList;
26 import com.sun.org.apache.bcel.internal.generic.NEW;
27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType;
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
32
33 /**
34  * @author Jacek Ambroziak
35  * @author Santiago Pericas-Geertsen
36  */

37 final class AbsoluteLocationPath extends Expression {
38     private Expression _path; // may be null
39

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