KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLVariable


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.handlers.*;
5 import com.icl.saxon.expr.*;
6
7 import javax.xml.transform.*;
8 import java.io.*;
9
10 /**
11 * Handler for xsl:variable elements in stylesheet.<BR>
12 * The xsl:variable element has mandatory attribute name and optional attribute select
13 */

14
15 public class XSLVariable extends XSLGeneralVariable implements Binding {
16
17     private int slotNumber;
18
19     public int getSlotNumber() {
20         return slotNumber;
21     }
22
23     /**
24     * Determine whether this node is an instruction.
25     * @return true - it is an instruction (well, it can be, anyway)
26     */

27
28     public boolean isInstruction() {
29         return true;
30     }
31
32     /**
33     * Check that the variable is not already declared, and allocate a slot number
34     */

35
36     public void validate() throws TransformerConfigurationException {
37         super.validate();
38         checkDuplicateDeclaration();
39         if (global && !redundant) {
40             slotNumber = getPrincipalStyleSheet().allocateSlotNumber();
41         } else {
42             Procedure p = getOwningProcedure();
43             slotNumber = p.allocateSlotNumber();
44         }
45     }
46
47     /**
48     * Get the data type, if known statically.
49     * @return the data type if known
50     */

51     
52     public int getDataType() {
53         if (assignable) {
54             return Value.ANY;
55         }
56         if (select!=null) {
57             return select.getDataType();
58         } else {
59             return Value.NODESET;
60         }
61     }
62
63     /**
64     * Get the value, if known statically.
65     * @return the value if known in advance, or null if not.
66     */

67     
68     public Value constantValue() {
69         if (assignable) {
70             return null;
71         }
72         if (select!=null && select instanceof Value) {
73             return (Value)select;
74         } else {
75             return null;
76         }
77     }
78
79
80     /**
81     * Process the variable declaration
82     */

83
84     public void process(Context context) throws TransformerException
85     {
86         Bindery b = context.getBindery();
87         if (global) {
88             if (!redundant && !b.isEvaluated(this)) { // don't evaluate a global variable twice
89
Value value = getSelectValue(context);
90                 b.defineGlobalVariable(this, value);
91             }
92         } else {
93             Value value = getSelectValue(context);
94             b.defineLocalVariable(this, value);
95         }
96     }
97
98 }
99
100 //
101
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
102
// you may not use this file except in compliance with the License. You may obtain a copy of the
103
// License at http://www.mozilla.org/MPL/
104
//
105
// Software distributed under the License is distributed on an "AS IS" basis,
106
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
107
// See the License for the specific language governing rights and limitations under the License.
108
//
109
// The Original Code is: all this file.
110
//
111
// The Initial Developer of the Original Code is
112
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
113
//
114
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
115
//
116
// Contributor(s): none.
117
//
118
Popular Tags