KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > instruct > NextMatch


1 package net.sf.saxon.instruct;
2 import net.sf.saxon.Controller;
3 import net.sf.saxon.expr.XPathContext;
4 import net.sf.saxon.expr.XPathContextMajor;
5 import net.sf.saxon.om.Item;
6 import net.sf.saxon.om.NodeInfo;
7 import net.sf.saxon.style.StandardNames;
8 import net.sf.saxon.trans.DynamicError;
9 import net.sf.saxon.trans.Mode;
10 import net.sf.saxon.trans.XPathException;
11
12 /**
13 * An xsl:next-match element in the stylesheet
14 */

15
16 public class NextMatch extends ApplyImports {
17
18     public NextMatch(boolean backwardsCompatible) {
19         super(backwardsCompatible);
20     }
21
22     /**
23     * Get the name of this instruction for diagnostic and tracing purposes
24     */

25
26     public int getInstructionNameCode() {
27         return StandardNames.XSL_NEXT_MATCH;
28     }
29
30     public TailCall processLeavingTail(XPathContext context) throws XPathException {
31
32         Controller controller = context.getController();
33
34         // handle parameters if any
35

36         ParameterSet params = assembleParams(context, actualParams);
37         ParameterSet tunnels = assembleTunnelParams(context, tunnelParams);
38
39         Template currentTemplate = context.getCurrentTemplate();
40         if (currentTemplate==null) {
41             DynamicError e = new DynamicError("There is no current template rule");
42             e.setXPathContext(context);
43             e.setErrorCode("XTDE0560");
44             throw e;
45         }
46         Mode mode = context.getCurrentMode();
47         if (mode == null) {
48             mode = controller.getRuleManager().getMode(Mode.DEFAULT_MODE);
49         }
50         if (context.getCurrentIterator()==null) {
51             DynamicError e = new DynamicError("There is no context item");
52             e.setXPathContext(context);
53             e.setErrorCode("XTDE0565");
54             throw e;
55         }
56         Item currentItem = context.getCurrentIterator().current();
57         if (!(currentItem instanceof NodeInfo)) {
58             DynamicError e = new DynamicError("Cannot call xsl:next-match when context item is not a node");
59             e.setXPathContext(context);
60             e.setErrorCode("XTDE0565");
61             throw e;
62         }
63         NodeInfo node = (NodeInfo)currentItem;
64         Template nh = controller.getRuleManager().getNextMatchHandler(node, mode, currentTemplate, context);
65
66         if (nh==null) { // use the default action for the node
67
ApplyTemplates.defaultAction(node, params, tunnels, context, false, getLocationId());
68         } else {
69             XPathContextMajor c2 = context.newContext();
70             c2.setOrigin(this);
71             c2.openStackFrame(nh.getStackFrameMap());
72             c2.setLocalParameters(params);
73             c2.setTunnelParameters(tunnels);
74             nh.process(c2);
75         }
76         return null;
77     }
78 }
79
80 //
81
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
82
// you may not use this file except in compliance with the License. You may obtain a copy of the
83
// License at http://www.mozilla.org/MPL/
84
//
85
// Software distributed under the License is distributed on an "AS IS" basis,
86
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
87
// See the License for the specific language governing rights and limitations under the License.
88
//
89
// The Original Code is: all this file.
90
//
91
// The Initial Developer of the Original Code is Michael H. Kay.
92
//
93
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
94
//
95
// Contributor(s): none.
96
//
97
Popular Tags