KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > style > SaxonAssign


1 package net.sf.saxon.style;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.ExpressionTool;
4 import net.sf.saxon.instruct.Assign;
5 import net.sf.saxon.instruct.Executable;
6 import net.sf.saxon.trans.XPathException;
7
8 /**
9 * saxon:assign element in stylesheet.
10 * The saxon:assign element has mandatory attribute name and optional attribute expr.
11 * It also allows xsl:extension-element-prefixes etc.
12 */

13
14 public class SaxonAssign extends XSLGeneralVariable {
15
16     private XSLVariableDeclaration declaration; // link to the variable declaration
17
private Assign instruction = new Assign();
18
19     /**
20     * Determine whether this node is an instruction.
21     * @return true - it is an instruction
22     */

23
24     public boolean isInstruction() {
25         return true;
26     }
27
28     public boolean isAssignable() { // this variable is assignable by definition
29
return true;
30     }
31
32     protected boolean allowsAsAttribute() {
33         return false;
34     }
35
36     public void validate() throws XPathException {
37         checkWithinTemplate();
38         super.validate();
39         try {
40             declaration = bindVariable(getVariableFingerprint());
41             declaration.registerReference(instruction);
42             requiredType = declaration.getRequiredType();
43         } catch (XPathException err) {
44             // variable not declared
45
compileError(err.getMessage());
46             return;
47         }
48         if (!declaration.isAssignable()) {
49             compileError("Variable " + getVariableName() + " is not marked as assignable");
50         }
51         if (!declaration.isGlobal()) {
52             compileError("saxon:assign now works only with global variables");
53         }
54     }
55
56     public Expression compile(Executable exec) throws XPathException {
57         initializeInstruction(exec, instruction);
58         ExpressionTool.makeParentReferences(instruction);
59         return instruction;
60     }
61
62 }
63
64 //
65
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
66
// you may not use this file except in compliance with the License. You may obtain a copy of the
67
// License at http://www.mozilla.org/MPL/
68
//
69
// Software distributed under the License is distributed on an "AS IS" basis,
70
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
71
// See the License for the specific language governing rights and limitations under the License.
72
//
73
// The Original Code is: all this file.
74
//
75
// The Initial Developer of the Original Code is Michael H. Kay.
76
//
77
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
78
//
79
// Contributor(s): none.
80
//
81
Popular Tags