KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.*;
5 import com.icl.saxon.expr.*;
6 import javax.xml.transform.*;
7
8 /**
9 * A saxon:handler element in the style sheet: defines a Java nodehandler that
10 * can be used to process a node in place of an XSLT template
11 */

12     
13 public class SAXONHandler extends XSLTemplate {
14
15     private NodeHandler handler;
16
17     public void checkUnknownAttribute(int nc)
18     throws TransformerConfigurationException {
19
20         StandardNames sn = getStandardNames();
21         AttributeCollection atts = getAttributeList();
22
23         int f = nc & 0xfffff;
24         if (f==sn.HANDLER) {
25             String JavaDoc handlerAtt = atts.getValueByFingerprint(f);
26             handler = makeHandler(handlerAtt);
27         } else {
28             super.checkUnknownAttribute(nc);
29         }
30
31         if (handler==null) {
32             reportAbsence("handler");
33         }
34
35     }
36
37
38     public void validate() throws TransformerConfigurationException {
39         if (handler==null) {
40             reportAbsence("handler");
41         }
42         checkTopLevel();
43     }
44
45     /**
46     * Preprocess: this registers the node handler with the controller
47     */

48
49     public void preprocess() throws TransformerConfigurationException
50     {
51         RuleManager mgr = getPrincipalStyleSheet().getRuleManager();
52         Mode mode = mgr.getMode(modeNameCode);
53         if (match!=null) {
54             if (prioritySpecified) {
55                 mgr.setHandler(match, handler, mode, getPrecedence(), priority);
56             } else {
57                 mgr.setHandler(match, handler, mode, getPrecedence());
58             }
59         }
60       
61     }
62
63     /**
64     * Process saxon:handler element. This is called while all the top-level nodes are being
65     * processed in order, so it does nothing.
66     */

67
68     public void process(Context context) throws TransformerException {
69     }
70
71     /**
72     * Invoke the node handler. Called directly only when doing XSLCallTemplate
73     */

74
75     public void expand(Context context) throws TransformerException {
76         handler.start(context.getCurrentNodeInfo(), context);
77     }
78
79     /**
80     * Load a named node handler and check it is OK.
81     */

82
83     protected NodeHandler makeHandler (String JavaDoc className)
84     throws TransformerConfigurationException
85     {
86         try {
87             return (NodeHandler)(Loader.getInstance(className));
88         } catch (TransformerException err) {
89             compileError(err);
90         } catch (ClassCastException JavaDoc e) {
91             compileError("Node handler " + className +
92                             " does not implement the NodeHandler interface");
93         }
94         return null;
95      }
96
97 }
98
99 //
100
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
101
// you may not use this file except in compliance with the License. You may obtain a copy of the
102
// License at http://www.mozilla.org/MPL/
103
//
104
// Software distributed under the License is distributed on an "AS IS" basis,
105
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
106
// See the License for the specific language governing rights and limitations under the License.
107
//
108
// The Original Code is: all this file.
109
//
110
// The Initial Developer of the Original Code is
111
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
112
//
113
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
114
//
115
// Contributor(s): none.
116
//
117
Popular Tags