001: package net.sf.saxon.instruct;
002:
003: import net.sf.saxon.expr.*;
004: import net.sf.saxon.om.NamePool;
005: import net.sf.saxon.pattern.NodeKindTest;
006: import net.sf.saxon.trans.XPathException;
007: import net.sf.saxon.type.ItemType;
008: import net.sf.saxon.type.TypeHierarchy;
009:
010: import java.io.PrintStream;
011:
012: /**
013: * This instruction corresponds to a use-attribute-sets attribute on a literal result element, xsl:element,
014: * or xsl:copy.
015: */
016: public class UseAttributeSets extends Instruction {
017:
018: private AttributeSet[] attributeSets;
019:
020: public UseAttributeSets(AttributeSet[] sets) {
021: attributeSets = sets;
022: }
023:
024: /**
025: * Simplify an expression. This performs any static optimization (by rewriting the expression
026: * as a different expression). The default implementation does nothing.
027: *
028: * @return the simplified expression
029: * @throws net.sf.saxon.trans.XPathException
030: * if an error is discovered during expression
031: * rewriting
032: */
033:
034: public Expression simplify(StaticContext env) throws XPathException {
035: return this ;
036: }
037:
038: /**
039: * Perform optimisation of an expression and its subexpressions.
040: * <p/>
041: * <p>This method is called after all references to functions and variables have been resolved
042: * to the declaration of the function or variable, and after all type checking has been done.</p>
043: *
044: * @param opt the optimizer in use. This provides access to supporting functions; it also allows
045: * different optimization strategies to be used in different circumstances.
046: * @param env the static context of the expression
047: * @param contextItemType the static type of "." at the point where this expression is invoked.
048: * The parameter is set to null if it is known statically that the context item will be undefined.
049: * If the type of the context item is not known statically, the argument is set to
050: * {@link net.sf.saxon.type.Type#ITEM_TYPE}
051: * @return the original expression, rewritten if appropriate to optimize execution
052: * @throws net.sf.saxon.trans.StaticError if an error is discovered during this phase
053: * (typically a type error)
054: */
055:
056: public Expression optimize(Optimizer opt, StaticContext env,
057: ItemType contextItemType) throws XPathException {
058: return this ;
059: }
060:
061: /**
062: * Perform type checking of an expression and its subexpressions.
063: * <p/>
064: * <p>This checks statically that the operands of the expression have
065: * the correct type; if necessary it generates code to do run-time type checking or type
066: * conversion. A static type error is reported only if execution cannot possibly succeed, that
067: * is, if a run-time type error is inevitable. The call may return a modified form of the expression.</p>
068: * <p/>
069: * <p>This method is called after all references to functions and variables have been resolved
070: * to the declaration of the function or variable. However, the types of such functions and
071: * variables may not be accurately known if they have not been explicitly declared.</p>
072: *
073: * @param env the static context of the expression
074: * @param contextItemType the static type of "." at the point where this expression is invoked.
075: * The parameter is set to null if it is known statically that the context item will be undefined.
076: * If the type of the context item is not known statically, the argument is set to
077: * {@link net.sf.saxon.type.Type#ITEM_TYPE}
078: * @return the original expression, rewritten to perform necessary
079: * run-time type checks, and to perform other type-related
080: * optimizations
081: * @throws net.sf.saxon.trans.StaticError if an error is discovered during this phase
082: * (typically a type error)
083: */
084:
085: public Expression typeCheck(StaticContext env,
086: ItemType contextItemType) throws XPathException {
087: return this ;
088: }
089:
090: /**
091: * Get the item type of the items returned by evaluating this instruction
092: *
093: * @return the static item type of the instruction
094: * @param th
095: */
096:
097: public ItemType getItemType(TypeHierarchy th) {
098: return NodeKindTest.ATTRIBUTE;
099: }
100:
101: /**
102: * ProcessLeavingTail: called to do the real work of this instruction. This method
103: * must be implemented in each subclass. The results of the instruction are written
104: * to the current Receiver, which can be obtained via the Controller.
105: *
106: * @param context The dynamic context of the transformation, giving access to the current node,
107: * the current variables, etc.
108: * @return null if the instruction has completed execution; or a TailCall indicating
109: * a function call or template call that is delegated to the caller, to be made after the stack has
110: * been unwound so as to save stack space.
111: */
112:
113: public TailCall processLeavingTail(XPathContext context)
114: throws XPathException {
115: AttributeSet.expand(attributeSets, context);
116: return null;
117: }
118:
119: /**
120: * Diagnostic print of expression structure. The expression is written to the System.err
121: * output stream
122: *
123: * @param level indentation level for this expression
124: * @param pool NamePool used to expand any names appearing in the expression
125: * @param out Output destination
126: */
127:
128: public void display(int level, NamePool pool, PrintStream out) {
129: out
130: .println(ExpressionTool.indent(level)
131: + "use attribute sets");
132: }
133: }
134:
135: //
136: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
137: // you may not use this file except in compliance with the License. You may obtain a copy of the
138: // License at http://www.mozilla.org/MPL/
139: //
140: // Software distributed under the License is distributed on an "AS IS" basis,
141: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
142: // See the License for the specific language governing rights and limitations under the License.
143: //
144: // The Original Code is: all this file.
145: //
146: // The Initial Developer of the Original Code is Michael H. Kay.
147: //
148: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
149: //
150: // Contributor(s): none.
151: //
|