01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.StaticContext;
05: import net.sf.saxon.expr.StaticProperty;
06: import net.sf.saxon.expr.XPathContext;
07: import net.sf.saxon.om.EmptyIterator;
08: import net.sf.saxon.om.Item;
09: import net.sf.saxon.om.SequenceIterator;
10: import net.sf.saxon.sort.GroupIterator;
11: import net.sf.saxon.trans.XPathException;
12:
13: /**
14: * Implements the XSLT functions current-group() and current-grouping-key()
15: */
16:
17: public class CurrentGroup extends SystemFunction implements
18: XSLTFunction {
19:
20: public static final int CURRENT_GROUP = 0;
21: public static final int CURRENT_GROUPING_KEY = 1;
22:
23: /**
24: * preEvaluate: this method suppresses compile-time evaluation by doing nothing
25: * (because the value of the expression depends on the runtime context)
26: */
27:
28: public Expression preEvaluate(StaticContext env) {
29: return this ;
30: }
31:
32: /**
33: * Evaluate the expression
34: */
35:
36: public Item evaluateItem(XPathContext c) throws XPathException {
37: if (operation == CURRENT_GROUPING_KEY) {
38: GroupIterator gi = c.getCurrentGroupIterator();
39: if (gi == null) {
40: return null;
41: }
42: return gi.getCurrentGroupingKey();
43: } else {
44: return super .evaluateItem(c);
45: }
46: }
47:
48: /**
49: * Return an iteration over the result sequence
50: */
51:
52: public SequenceIterator iterate(XPathContext c)
53: throws XPathException {
54: if (operation == CURRENT_GROUP) {
55: GroupIterator gi = c.getCurrentGroupIterator();
56: if (gi == null) {
57: return EmptyIterator.getInstance();
58: }
59: return gi.iterateCurrentGroup();
60: } else {
61: return super .iterate(c);
62: }
63: }
64:
65: /**
66: * Determine the dependencies
67: */
68:
69: public int getIntrinsicDependencies() {
70: return StaticProperty.DEPENDS_ON_CURRENT_GROUP;
71: }
72:
73: }
74:
75: //
76: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
77: // you may not use this file except in compliance with the License. You may obtain a copy of the
78: // License at http://www.mozilla.org/MPL/
79: //
80: // Software distributed under the License is distributed on an "AS IS" basis,
81: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
82: // See the License for the specific language governing rights and limitations under the License.
83: //
84: // The Original Code is: all this file.
85: //
86: // The Initial Developer of the Original Code is Michael H. Kay.
87: //
88: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
89: //
90: // Contributor(s): none.
91: //
|