KickJava   Java API By Example, From Geeks To Geeks.

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


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

15
16 public class XSLParam extends XSLGeneralVariable implements Binding {
17
18     private int slotNumber;
19
20     public int getSlotNumber() {
21         return slotNumber;
22     }
23
24     public void validate() throws TransformerConfigurationException {
25
26         super.validate();
27
28         NodeInfo parent = (NodeInfo)getParentNode();
29         boolean local = (parent instanceof XSLTemplate || parent instanceof SAXONFunction);
30
31         if (!local && !global) {
32             compileError("xsl:param must be immediately within a template, function or stylesheet");
33         }
34
35         checkDuplicateDeclaration();
36
37         if (global && !redundant) {
38             slotNumber = getPrincipalStyleSheet().allocateSlotNumber();
39         } else {
40             Procedure p = getOwningProcedure();
41             slotNumber = p.allocateSlotNumber();
42         }
43
44         if (!global) {
45             NodeInfo preceding = (NodeInfo)getPreviousSibling();
46             if (preceding!=null && !(preceding instanceof XSLParam)) {
47                 compileError("xsl:param must be the first element within a template");
48             }
49         }
50
51     }
52
53     public void process(Context context) throws TransformerException
54     {
55         if (redundant) return;
56         
57         Bindery bindery = context.getBindery();
58         boolean wasSupplied;
59
60         if (global) {
61             wasSupplied = bindery.useGlobalParameter(variableFingerprint, this);
62         } else {
63             wasSupplied = bindery.useLocalParameter(variableFingerprint, this);
64         }
65
66         // don't evaluate the default if a value has been supplied or if it has already been
67
// evaluated by virtue of a forwards reference
68

69         if (!wasSupplied) {
70             if (global) {
71                 if (!redundant) {
72                     Value value = getSelectValue(context);
73                     bindery.defineGlobalVariable(this, value);
74                 }
75             } else {
76                 Value value = getSelectValue(context);
77                 bindery.defineLocalVariable(this, value);
78             }
79         }
80     }
81
82     /**
83     * Get the data type, if known statically.
84     * @return Value.ANY, because the data type of a parameter is never known in advance
85     */

86     
87     public int getDataType() {
88         return Value.ANY;
89     }
90
91     /**
92     * Get the value, if known statically.
93     * @return null, because the value of a parameter is never known in advance
94     */

95     
96     public Value constantValue() {
97         return null;
98     }
99 }
100
101 //
102
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
103
// you may not use this file except in compliance with the License. You may obtain a copy of the
104
// License at http://www.mozilla.org/MPL/
105
//
106
// Software distributed under the License is distributed on an "AS IS" basis,
107
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
108
// See the License for the specific language governing rights and limitations under the License.
109
//
110
// The Original Code is: all this file.
111
//
112
// The Initial Developer of the Original Code is
113
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
114
//
115
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
116
//
117
// Contributor(s): none.
118
//
119
Popular Tags