KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.instruct;
2 import net.sf.saxon.expr.*;
3 import net.sf.saxon.om.ValueRepresentation;
4 import net.sf.saxon.style.StandardNames;
5 import net.sf.saxon.trans.XPathException;
6 import net.sf.saxon.value.Closure;
7 import net.sf.saxon.value.SequenceExtent;
8 import net.sf.saxon.value.SequenceType;
9 import net.sf.saxon.value.Value;
10
11 /**
12 * saxon:assign element in stylesheet.
13 *
14 * The saxon:assign element has mandatory attribute name and optional attribute expr.
15 * It also allows xsl:extension-element-prefixes etc.
16 */

17
18 public class Assign extends GeneralVariable implements BindingReference {
19
20
21     private Binding binding; // link to the variable declaration
22

23     public Assign() {}
24
25     public void setStaticType(SequenceType type, Value constantValue, int properties) {}
26
27     public void fixup(Binding binding) {
28         this.binding = binding;
29     }
30
31     /**
32      * Determine whether this instruction creates new nodes.
33      * This implementation returns true: although the instruction doesn't create new
34      * nodes, pretending that it does causes the optimizer to avoid pulling the instruction out of a loop.
35      */

36
37     public final boolean createsNewNodes() {
38         return true;
39     }
40
41     /**
42      * Offer promotion for this subexpression. This needs careful handling in the
43      * case of saxon:assign
44      *
45      * @param offer details of the offer, for example the offer to move
46      * expressions that don't depend on the context to an outer level in
47      * the containing expression
48      * @exception net.sf.saxon.trans.XPathException if any error is detected
49      * @return if the offer is not accepted, return this expression unchanged.
50      * Otherwise return the result of rewriting the expression to promote
51      * this subexpression
52      */

53
54     public Expression promote(PromotionOffer offer) throws XPathException {
55         switch (offer.action) {
56             case PromotionOffer.RANGE_INDEPENDENT:
57             case PromotionOffer.FOCUS_INDEPENDENT:
58                 return this;
59
60             case PromotionOffer.REPLACE_CURRENT:
61             case PromotionOffer.INLINE_VARIABLE_REFERENCES:
62             case PromotionOffer.UNORDERED:
63                 return super.promote(offer);
64
65             default:
66                 throw new UnsupportedOperationException JavaDoc("Unknown promotion action " + offer.action);
67         }
68     }
69
70
71
72     /**
73     * Get the name of this instruction for diagnostic and tracing purposes
74     */

75
76     public int getInstructionNameCode() {
77         return StandardNames.SAXON_ASSIGN;
78     }
79
80
81     public TailCall processLeavingTail(XPathContext context) throws XPathException {
82         if (binding==null) {
83             throw new IllegalStateException JavaDoc("saxon:assign binding has not been fixed up");
84         }
85         ValueRepresentation value = getSelectValue(context);
86         if (value instanceof Closure) {
87             value = SequenceExtent.makeSequenceExtent(((Closure)value).iterate(null));
88         }
89         if (binding instanceof GeneralVariable) {
90             if (binding.isGlobal()) {
91                 context.getController().getBindery().assignGlobalVariable((GlobalVariable)binding, value);
92             } else {
93                 throw new UnsupportedOperationException JavaDoc("Local variables are not assignable");
94             }
95         } else {
96
97         }
98         return null;
99     }
100
101     /**
102      * Evaluate the variable (method exists only to satisfy the interface)
103      */

104
105     public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException {
106         throw new UnsupportedOperationException JavaDoc();
107     }
108 }
109
110 //
111
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
112
// you may not use this file except in compliance with the License. You may obtain a copy of the
113
// License at http://www.mozilla.org/MPL/
114
//
115
// Software distributed under the License is distributed on an "AS IS" basis,
116
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
117
// See the License for the specific language governing rights and limitations under the License.
118
//
119
// The Original Code is: all this file.
120
//
121
// The Initial Developer of the Original Code is Michael H. Kay.
122
//
123
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
124
//
125
// Contributor(s): none.
126
//
127
Popular Tags