KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.style;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.instruct.Executable;
4 import net.sf.saxon.om.AttributeCollection;
5 import net.sf.saxon.trans.XPathException;
6 import net.sf.saxon.type.ItemType;
7
8
9 /**
10 * Handler for xsl:when elements in stylesheet. <br>
11 * The xsl:while element has a mandatory attribute test, a boolean expression.
12 */

13
14 public class XSLWhen extends StyleElement {
15
16     private Expression test;
17
18     public Expression getCondition() {
19         return test;
20     }
21
22     /**
23      * Determine the type of item returned by this instruction (only relevant if
24      * it is an instruction).
25      * @return the item type returned
26      */

27
28     protected ItemType getReturnedItemType() {
29         return getCommonChildItemType();
30     }
31
32     public void prepareAttributes() throws XPathException {
33         String JavaDoc testAtt=null;
34
35         AttributeCollection atts = getAttributeList();
36
37         for (int a=0; a<atts.getLength(); a++) {
38             int nc = atts.getNameCode(a);
39             String JavaDoc f = getNamePool().getClarkName(nc);
40             if (f==StandardNames.TEST) {
41                 testAtt = atts.getValue(a);
42             } else {
43                 checkUnknownAttribute(nc);
44             }
45         }
46
47         if (testAtt==null) {
48             reportAbsence("test");
49         } else {
50             test = makeExpression(testAtt);
51         }
52     }
53
54     /**
55     * Determine whether this type of element is allowed to contain a template-body
56     * @return true: yes, it may contain a template-body
57     */

58
59     public boolean mayContainSequenceConstructor() {
60         return true;
61     }
62
63     public void validate() throws XPathException {
64         if (!(getParent() instanceof XSLChoose)) {
65             compileError("xsl:when must be immediately within xsl:choose", "XTSE0010");
66         }
67         test = typeCheck("test", test);
68     }
69
70     /**
71     * Mark tail-recursive calls on stylesheet functions. For most instructions, this does nothing.
72     */

73
74     public void markTailCalls() {
75         StyleElement last = getLastChildInstruction();
76         if (last != null) {
77             last.markTailCalls();
78         }
79     }
80
81     public Expression compile(Executable exec) throws XPathException {
82         return null;
83         // compilation is handled from the xsl:choose element
84
}
85
86 }
87
88 //
89
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
90
// you may not use this file except in compliance with the License. You may obtain a copy of the
91
// License at http://www.mozilla.org/MPL/
92
//
93
// Software distributed under the License is distributed on an "AS IS" basis,
94
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
95
// See the License for the specific language governing rights and limitations under the License.
96
//
97
// The Original Code is: all this file.
98
//
99
// The Initial Developer of the Original Code is Michael H. Kay.
100
//
101
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
102
//
103
// Contributor(s): none.
104
//
105
Popular Tags