001: package net.sf.saxon.expr;
002:
003: import net.sf.saxon.om.Item;
004: import net.sf.saxon.om.NamePool;
005: import net.sf.saxon.om.SequenceIterator;
006: import net.sf.saxon.om.ValueRepresentation;
007: import net.sf.saxon.trans.XPathException;
008: import net.sf.saxon.type.AnyItemType;
009: import net.sf.saxon.type.ItemType;
010: import net.sf.saxon.type.TypeHierarchy;
011: import net.sf.saxon.value.Value;
012:
013: import java.io.PrintStream;
014:
015: /**
016: * Supplied parameter reference: this is an internal expression used to refer to
017: * the value of the n'th parameter supplied on a template call (apply-templates).
018: * It is used within a type-checking expression designed to check the consistency
019: * of the supplied value with the required type. This type checking is all done
020: * at run-time, because the binding of apply-templates to actual template rules
021: * is entirely dynamic.
022: */
023:
024: public class SuppliedParameterReference extends ComputedExpression {
025:
026: int slotNumber;
027:
028: /**
029: * Constructor
030: * @param slot identifies this parameter
031: */
032:
033: public SuppliedParameterReference(int slot) {
034: slotNumber = slot;
035: }
036:
037: /**
038: * Simplify the expression. Does nothing.
039: */
040:
041: public Expression simplify(StaticContext env) {
042: return this ;
043: }
044:
045: public Expression typeCheck(StaticContext env,
046: ItemType contextItemType) throws XPathException {
047: return this ;
048: }
049:
050: public Expression optimize(Optimizer opt, StaticContext env,
051: ItemType contextItemType) throws XPathException {
052: return this ;
053: }
054:
055: /**
056: * Determine the data type of the expression, if possible.
057: * @return Type.ITEM, because we don't know the type of the supplied value
058: * in advance.
059: * @param th
060: */
061:
062: public ItemType getItemType(TypeHierarchy th) {
063: return AnyItemType.getInstance();
064: }
065:
066: /**
067: * Get the static cardinality
068: * @return ZERO_OR_MORE, because we don't know the type of the supplied value
069: * in advance.
070: */
071:
072: public int computeCardinality() {
073: return StaticProperty.ALLOWS_ZERO_OR_MORE;
074: }
075:
076: /**
077: * Test if this expression is the same as another expression.
078: * (Note, we only compare expressions that
079: * have the same static and dynamic context).
080: */
081:
082: public boolean equals(Object other) {
083: return this == other;
084: }
085:
086: /**
087: * Get the value of this expression in a given context.
088: * @param c the XPathContext which contains the relevant variable bindings
089: * @return the value of the variable, if it is defined
090: * @throws XPathException if the variable is undefined
091: */
092:
093: public SequenceIterator iterate(XPathContext c)
094: throws XPathException {
095: return Value.getIterator(c.evaluateLocalVariable(slotNumber));
096: }
097:
098: public Item evaluateItem(XPathContext c) throws XPathException {
099: ValueRepresentation actual = c
100: .evaluateLocalVariable(slotNumber);
101: return Value.asItem(actual, c);
102: }
103:
104: /**
105: * Diagnostic print of expression structure
106: */
107:
108: public void display(int level, NamePool pool, PrintStream out) {
109: out.println(ExpressionTool.indent(level) + "$#" + slotNumber);
110: }
111: }
112:
113: //
114: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
115: // you may not use this file except in compliance with the License. You may obtain a copy of the
116: // License at http://www.mozilla.org/MPL/
117: //
118: // Software distributed under the License is distributed on an "AS IS" basis,
119: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
120: // See the License for the specific language governing rights and limitations under the License.
121: //
122: // The Original Code is: all this file.
123: //
124: // The Initial Developer of the Original Code is Michael H. Kay.
125: //
126: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
127: //
128: // Contributor(s):
129: // Portions marked "e.g." are from Edwin Glaser (edwin@pannenleiter.de)
130: //
|