KickJava   Java API By Example, From Geeks To Geeks.

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


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.Executable;
5 import net.sf.saxon.instruct.While;
6 import net.sf.saxon.om.AttributeCollection;
7 import net.sf.saxon.om.Axis;
8 import net.sf.saxon.value.EmptySequence;
9 import net.sf.saxon.trans.XPathException;
10
11 import javax.xml.transform.TransformerConfigurationException JavaDoc;
12
13
14 /**
15 * Handler for saxon:while elements in stylesheet.
16 * The saxon:while element has a mandatory attribute test, a boolean expression.
17 * The content is output repeatedly so long as the test condition is true.
18 */

19
20 public class SaxonWhile extends StyleElement {
21
22     private Expression test;
23
24     /**
25     * Determine whether this node is an instruction.
26     * @return true - it is an instruction
27     */

28
29     public boolean isInstruction() {
30         return true;
31     }
32
33     /**
34     * Determine whether this type of element is allowed to contain a template-body
35     * @return true: yes, it may contain a template-body
36     */

37
38     public boolean mayContainSequenceConstructor() {
39         return true;
40     }
41
42     public void prepareAttributes() throws XPathException {
43
44         String JavaDoc testAtt=null;
45
46         AttributeCollection atts = getAttributeList();
47
48         for (int a=0; a<atts.getLength(); a++) {
49             int nc = atts.getNameCode(a);
50             String JavaDoc f = getNamePool().getClarkName(nc);
51             if (f==StandardNames.TEST) {
52                 testAtt = atts.getValue(a);
53             } else {
54                 checkUnknownAttribute(nc);
55             }
56         }
57
58         if (testAtt==null) {
59             reportAbsence("test");
60             return;
61         }
62         test = makeExpression(testAtt);
63     }
64
65     public void validate() throws XPathException {
66         checkWithinTemplate();
67         test = typeCheck("test", test);
68     }
69
70     public Expression compile(Executable exec) throws XPathException {
71         Expression action = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true);
72         if (action == null) {
73             action = EmptySequence.getInstance();
74         }
75         //try {
76
While w = new While(test, action);
77             ExpressionTool.makeParentReferences(w);
78             return w;
79 // } catch (XPathException e) {
80
// compileError(e);
81
// return null;
82
// }
83
}
84
85 }
86
87 //
88
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
89
// you may not use this file except in compliance with the License. You may obtain a copy of the
90
// License at http://www.mozilla.org/MPL/
91
//
92
// Software distributed under the License is distributed on an "AS IS" basis,
93
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
94
// See the License for the specific language governing rights and limitations under the License.
95
//
96
// The Original Code is: all this file.
97
//
98
// The Initial Developer of the Original Code is Michael H. Kay.
99
//
100
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
101
//
102
// Contributor(s): none.
103
//
104
Popular Tags