KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package org.apache.xalan.xsltc.compiler;
21
22 import org.apache.bcel.generic.CHECKCAST;
23 import org.apache.bcel.generic.ConstantPoolGen;
24 import org.apache.bcel.generic.GETFIELD;
25 import org.apache.bcel.generic.INVOKEINTERFACE;
26 import org.apache.bcel.generic.InstructionList;
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.NodeSetType;
30 import org.apache.xalan.xsltc.runtime.BasisLibrary;
31
32 /**
33  * @author Jacek Ambroziak
34  * @author Santiago Pericas-Geertsen
35  * @author Morten Jorgensen
36  * @author Erwin Bolwidt <ejb@klomp.org>
37  */

38 final class ParameterRef extends VariableRefBase {
39
40     /**
41      * Name of param being referenced.
42      */

43     QName _name = null;
44     
45     public ParameterRef(Param param) {
46     super(param);
47         _name = param._name;
48         
49     }
50
51     public String JavaDoc toString() {
52     return "parameter-ref("+_variable.getName()+'/'+_variable.getType()+')';
53     }
54
55     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
56     final ConstantPoolGen cpg = classGen.getConstantPool();
57     final InstructionList il = methodGen.getInstructionList();
58
59         /*
60          * To fix bug 24518 related to setting parameters of the form
61          * {namespaceuri}localName, which will get mapped to an instance
62          * variable in the class.
63          */

64         final String JavaDoc name = BasisLibrary.mapQNameToJavaName (_name.toString());
65     final String JavaDoc signature = _type.toSignature();
66
67     if (_variable.isLocal()) {
68         if (classGen.isExternal()) {
69         Closure variableClosure = _closure;
70         while (variableClosure != null) {
71             if (variableClosure.inInnerClass()) break;
72             variableClosure = variableClosure.getParentClosure();
73         }
74         
75         if (variableClosure != null) {
76             il.append(ALOAD_0);
77             il.append(new GETFIELD(
78             cpg.addFieldref(variableClosure.getInnerClassName(),
79                 name, signature)));
80         }
81         else {
82             il.append(_variable.loadInstruction());
83             _variable.removeReference(this);
84         }
85         }
86         else {
87         il.append(_variable.loadInstruction());
88         _variable.removeReference(this);
89         }
90     }
91     else {
92         final String JavaDoc className = classGen.getClassName();
93         il.append(classGen.loadTranslet());
94         if (classGen.isExternal()) {
95         il.append(new CHECKCAST(cpg.addClass(className)));
96         }
97         il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
98     }
99
100     if (_variable.getType() instanceof NodeSetType) {
101         // The method cloneIterator() also does resetting
102
final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
103                                "cloneIterator",
104                                "()" +
105                             NODE_ITERATOR_SIG);
106         il.append(new INVOKEINTERFACE(clone, 1));
107     }
108     }
109 }
110
Popular Tags