001: package net.sf.saxon.instruct;
002:
003: import net.sf.saxon.Controller;
004: import net.sf.saxon.expr.XPathContext;
005: import net.sf.saxon.expr.XPathContextMajor;
006: import net.sf.saxon.om.Item;
007: import net.sf.saxon.om.NodeInfo;
008: import net.sf.saxon.style.StandardNames;
009: import net.sf.saxon.trans.DynamicError;
010: import net.sf.saxon.trans.Mode;
011: import net.sf.saxon.trans.XPathException;
012:
013: /**
014: * An xsl:next-match element in the stylesheet
015: */
016:
017: public class NextMatch extends ApplyImports {
018:
019: public NextMatch(boolean backwardsCompatible) {
020: super (backwardsCompatible);
021: }
022:
023: /**
024: * Get the name of this instruction for diagnostic and tracing purposes
025: */
026:
027: public int getInstructionNameCode() {
028: return StandardNames.XSL_NEXT_MATCH;
029: }
030:
031: public TailCall processLeavingTail(XPathContext context)
032: throws XPathException {
033:
034: Controller controller = context.getController();
035:
036: // handle parameters if any
037:
038: ParameterSet params = assembleParams(context, actualParams);
039: ParameterSet tunnels = assembleTunnelParams(context,
040: tunnelParams);
041:
042: Template currentTemplate = context.getCurrentTemplate();
043: if (currentTemplate == null) {
044: DynamicError e = new DynamicError(
045: "There is no current template rule");
046: e.setXPathContext(context);
047: e.setErrorCode("XTDE0560");
048: throw e;
049: }
050: Mode mode = context.getCurrentMode();
051: if (mode == null) {
052: mode = controller.getRuleManager().getMode(
053: Mode.DEFAULT_MODE);
054: }
055: if (context.getCurrentIterator() == null) {
056: DynamicError e = new DynamicError(
057: "There is no context item");
058: e.setXPathContext(context);
059: e.setErrorCode("XTDE0565");
060: throw e;
061: }
062: Item currentItem = context.getCurrentIterator().current();
063: if (!(currentItem instanceof NodeInfo)) {
064: DynamicError e = new DynamicError(
065: "Cannot call xsl:next-match when context item is not a node");
066: e.setXPathContext(context);
067: e.setErrorCode("XTDE0565");
068: throw e;
069: }
070: NodeInfo node = (NodeInfo) currentItem;
071: Template nh = controller.getRuleManager().getNextMatchHandler(
072: node, mode, currentTemplate, context);
073:
074: if (nh == null) { // use the default action for the node
075: ApplyTemplates.defaultAction(node, params, tunnels,
076: context, false, getLocationId());
077: } else {
078: XPathContextMajor c2 = context.newContext();
079: c2.setOrigin(this );
080: c2.openStackFrame(nh.getStackFrameMap());
081: c2.setLocalParameters(params);
082: c2.setTunnelParameters(tunnels);
083: nh.process(c2);
084: }
085: return null;
086: }
087: }
088:
089: //
090: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
091: // you may not use this file except in compliance with the License. You may obtain a copy of the
092: // License at http://www.mozilla.org/MPL/
093: //
094: // Software distributed under the License is distributed on an "AS IS" basis,
095: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
096: // See the License for the specific language governing rights and limitations under the License.
097: //
098: // The Original Code is: all this file.
099: //
100: // The Initial Developer of the Original Code is Michael H. Kay.
101: //
102: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
103: //
104: // Contributor(s): none.
105: //
|