KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > SuppliedParameterReference


1 package net.sf.saxon.expr;
2 import net.sf.saxon.om.Item;
3 import net.sf.saxon.om.NamePool;
4 import net.sf.saxon.om.SequenceIterator;
5 import net.sf.saxon.om.ValueRepresentation;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.type.AnyItemType;
8 import net.sf.saxon.type.ItemType;
9 import net.sf.saxon.value.Value;
10
11 import java.io.PrintStream JavaDoc;
12
13 /**
14  * Supplied parameter reference: this is an internal expression used to refer to
15  * the value of the n'th parameter supplied on a template call (apply-templates).
16  * It is used within a type-checking expression designed to check the consistency
17  * of the supplied value with the required type. This type checking is all done
18  * at run-time, because the binding of apply-templates to actual template rules
19  * is entirely dynamic.
20  */

21
22 public class SuppliedParameterReference extends ComputedExpression {
23
24     int slotNumber;
25
26     /**
27     * Constructor
28     * @param slot identifies this parameter
29     */

30
31     public SuppliedParameterReference(int slot) {
32         slotNumber = slot;
33     }
34
35     /**
36     * Simplify the expression. Does nothing.
37     */

38
39     public Expression simplify(StaticContext env) {
40         return this;
41     }
42
43     public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException {
44         return this;
45     }
46
47     public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException {
48         return this;
49     }
50
51     /**
52     * Determine the data type of the expression, if possible.
53     * @return Type.ITEM, because we don't know the type of the supplied value
54     * in advance.
55     */

56
57     public ItemType getItemType() {
58         return AnyItemType.getInstance();
59     }
60
61     /**
62     * Get the static cardinality
63      * @return ZERO_OR_MORE, because we don't know the type of the supplied value
64      * in advance.
65     */

66
67     public int computeCardinality() {
68         return StaticProperty.ALLOWS_ZERO_OR_MORE;
69     }
70
71     /**
72     * Test if this expression is the same as another expression.
73     * (Note, we only compare expressions that
74     * have the same static and dynamic context).
75     */

76
77     public boolean equals(Object JavaDoc other) {
78         return this==other;
79     }
80
81     /**
82     * Get the value of this expression in a given context.
83     * @param c the XPathContext which contains the relevant variable bindings
84     * @return the value of the variable, if it is defined
85     * @throws XPathException if the variable is undefined
86     */

87
88     public SequenceIterator iterate(XPathContext c) throws XPathException {
89         return Value.getIterator(c.evaluateLocalVariable(slotNumber));
90     }
91
92     public Item evaluateItem(XPathContext c) throws XPathException {
93         ValueRepresentation actual = c.evaluateLocalVariable(slotNumber);
94         return Value.asItem(actual, c);
95     }
96
97     /**
98     * Diagnostic print of expression structure
99     */

100
101     public void display(int level, NamePool pool, PrintStream JavaDoc out) {
102         out.println(ExpressionTool.indent(level) + "$#" + slotNumber);
103     }
104 }
105
106 //
107
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
108
// you may not use this file except in compliance with the License. You may obtain a copy of the
109
// License at http://www.mozilla.org/MPL/
110
//
111
// Software distributed under the License is distributed on an "AS IS" basis,
112
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
113
// See the License for the specific language governing rights and limitations under the License.
114
//
115
// The Original Code is: all this file.
116
//
117
// The Initial Developer of the Original Code is Michael H. Kay.
118
//
119
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
120
//
121
// Contributor(s):
122
// Portions marked "e.g." are from Edwin Glaser (edwin@pannenleiter.de)
123
//
124
Popular Tags