KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > instruct > UseAttributeSets


1 package net.sf.saxon.instruct;
2
3 import net.sf.saxon.expr.*;
4 import net.sf.saxon.om.NamePool;
5 import net.sf.saxon.pattern.NodeKindTest;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.type.ItemType;
8
9 import java.io.PrintStream JavaDoc;
10
11 /**
12  * This instruction corresponds to a use-attribute-sets attribute on a literal result element, xsl:element,
13  * or xsl:copy.
14  */

15 public class UseAttributeSets extends Instruction {
16
17     private AttributeSet[] attributeSets;
18
19     public UseAttributeSets(AttributeSet[] sets) {
20         attributeSets = sets;
21     }
22
23     /**
24      * Simplify an expression. This performs any static optimization (by rewriting the expression
25      * as a different expression). The default implementation does nothing.
26      *
27      * @return the simplified expression
28      * @throws net.sf.saxon.trans.XPathException
29      * if an error is discovered during expression
30      * rewriting
31      */

32
33     public Expression simplify(StaticContext env) throws XPathException {
34         return this;
35     }
36
37     /**
38      * Perform optimisation of an expression and its subexpressions.
39      * <p/>
40      * <p>This method is called after all references to functions and variables have been resolved
41      * to the declaration of the function or variable, and after all type checking has been done.</p>
42      *
43      * @param opt the optimizer in use. This provides access to supporting functions; it also allows
44      * different optimization strategies to be used in different circumstances.
45      * @param env the static context of the expression
46      * @param contextItemType the static type of "." at the point where this expression is invoked.
47      * The parameter is set to null if it is known statically that the context item will be undefined.
48      * If the type of the context item is not known statically, the argument is set to
49      * {@link net.sf.saxon.type.Type#ITEM_TYPE}
50      * @return the original expression, rewritten if appropriate to optimize execution
51      * @throws net.sf.saxon.trans.StaticError if an error is discovered during this phase
52      * (typically a type error)
53      */

54
55     public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException {
56         return this;
57     }
58
59     /**
60      * Perform type checking of an expression and its subexpressions.
61      * <p/>
62      * <p>This checks statically that the operands of the expression have
63      * the correct type; if necessary it generates code to do run-time type checking or type
64      * conversion. A static type error is reported only if execution cannot possibly succeed, that
65      * is, if a run-time type error is inevitable. The call may return a modified form of the expression.</p>
66      * <p/>
67      * <p>This method is called after all references to functions and variables have been resolved
68      * to the declaration of the function or variable. However, the types of such functions and
69      * variables may not be accurately known if they have not been explicitly declared.</p>
70      *
71      * @param env the static context of the expression
72      * @param contextItemType the static type of "." at the point where this expression is invoked.
73      * The parameter is set to null if it is known statically that the context item will be undefined.
74      * If the type of the context item is not known statically, the argument is set to
75      * {@link net.sf.saxon.type.Type#ITEM_TYPE}
76      * @return the original expression, rewritten to perform necessary
77      * run-time type checks, and to perform other type-related
78      * optimizations
79      * @throws net.sf.saxon.trans.StaticError if an error is discovered during this phase
80      * (typically a type error)
81      */

82
83     public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException {
84         return this;
85     }
86
87     /**
88      * Get the item type of the items returned by evaluating this instruction
89      *
90      * @return the static item type of the instruction
91      */

92
93     public ItemType getItemType() {
94         return NodeKindTest.ATTRIBUTE;
95     }
96
97     /**
98      * ProcessLeavingTail: called to do the real work of this instruction. This method
99      * must be implemented in each subclass. The results of the instruction are written
100      * to the current Receiver, which can be obtained via the Controller.
101      *
102      * @param context The dynamic context of the transformation, giving access to the current node,
103      * the current variables, etc.
104      * @return null if the instruction has completed execution; or a TailCall indicating
105      * a function call or template call that is delegated to the caller, to be made after the stack has
106      * been unwound so as to save stack space.
107      */

108
109     public TailCall processLeavingTail(XPathContext context) throws XPathException {
110         AttributeSet.expand(attributeSets, context);
111         return null;
112     }
113
114     /**
115      * Diagnostic print of expression structure. The expression is written to the System.err
116      * output stream
117      *
118      * @param level indentation level for this expression
119      * @param pool NamePool used to expand any names appearing in the expression
120      * @param out Output destination
121      */

122
123     public void display(int level, NamePool pool, PrintStream JavaDoc out) {
124         out.println(ExpressionTool.indent(level) + "use attribute sets");
125     }
126 }
127
128 //
129
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
130
// you may not use this file except in compliance with the License. You may obtain a copy of the
131
// License at http://www.mozilla.org/MPL/
132
//
133
// Software distributed under the License is distributed on an "AS IS" basis,
134
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
135
// See the License for the specific language governing rights and limitations under the License.
136
//
137
// The Original Code is: all this file.
138
//
139
// The Initial Developer of the Original Code is Michael H. Kay.
140
//
141
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
142
//
143
// Contributor(s): none.
144
//
145

146
Popular Tags