KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.tree.NodeImpl;
4 import com.icl.saxon.*;
5 import com.icl.saxon.expr.*;
6 import com.icl.saxon.om.NodeInfo;
7
8 import javax.xml.transform.*;
9
10
11 /**
12 * Handler for saxon:return or exslt:result elements in stylesheet.<BR>
13 * The element has optional attribute select
14 */

15
16 public class SAXONReturn extends XSLGeneralVariable {
17
18     /**
19     * Determine whether this node is an instruction.
20     * @return true - it is an instruction
21     */

22
23     public boolean isInstruction() {
24         return true;
25     }
26
27     public int getVariableFingerprint() {
28         return -1;
29     }
30
31     public void prepareAttributes() throws TransformerConfigurationException {
32         
33         StandardNames sn = getStandardNames();
34         AttributeCollection atts = getAttributeList();
35         
36         String JavaDoc selectAtt = null;
37         
38         for (int a=0; a<atts.getLength(); a++) {
39             int nc = atts.getNameCode(a);
40             int f = nc & 0xfffff;
41             if (f==sn.SELECT) {
42                 selectAtt = atts.getValue(a);
43             } else {
44                 checkUnknownAttribute(nc);
45             }
46         }
47         
48         if (selectAtt!=null) {
49             select = makeExpression(selectAtt);
50         }
51
52     }
53
54
55     /**
56     * Validate
57     */

58
59     public void validate() throws TransformerConfigurationException {
60
61         // check it's within a function body
62

63         NodeInfo anc = (NodeInfo)getParentNode();
64         while (anc!=null) {
65             if (anc instanceof SAXONFunction) break;
66             if (anc instanceof XSLGeneralVariable ) {
67                 compileError(getDisplayName() + " must not be used within a variable definition");
68             };
69             anc = (NodeInfo)anc.getParent();
70         }
71
72         if (anc==null) {
73             compileError(getDisplayName() + " must only be used within a function definition");
74         }
75
76         
77         // check there is no following instruction
78

79         NodeImpl next = (NodeImpl)getNextSibling();
80         if (next!=null && !(next instanceof XSLFallback)) {
81             compileError(getDisplayName() + " must be the last instruction in its template body");
82         }
83
84         if (select==null) {
85             if (!hasChildNodes()) {
86                 select = new StringValue("");
87             }
88         }
89     }
90
91     /**
92     * Process the return/result instruction
93     */

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