KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > CurrentGroup


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.StaticContext;
4 import net.sf.saxon.expr.StaticProperty;
5 import net.sf.saxon.expr.XPathContext;
6 import net.sf.saxon.om.EmptyIterator;
7 import net.sf.saxon.om.Item;
8 import net.sf.saxon.om.SequenceIterator;
9 import net.sf.saxon.sort.GroupIterator;
10 import net.sf.saxon.trans.XPathException;
11
12 /**
13 * Implements the XSLT functions current-group() and current-grouping-key()
14 */

15
16 public class CurrentGroup extends SystemFunction implements XSLTFunction {
17
18     public static final int CURRENT_GROUP = 0;
19     public static final int CURRENT_GROUPING_KEY = 1;
20
21     /**
22     * preEvaluate: this method suppresses compile-time evaluation by doing nothing
23     * (because the value of the expression depends on the runtime context)
24     */

25
26     public Expression preEvaluate(StaticContext env) {
27         return this;
28     }
29
30     /**
31      * Evaluate the expression
32      */

33
34     public Item evaluateItem(XPathContext c) throws XPathException {
35         if (operation==CURRENT_GROUPING_KEY) {
36             GroupIterator gi = c.getCurrentGroupIterator();
37             if (gi==null) {
38                 return null;
39             }
40             return gi.getCurrentGroupingKey();
41         } else {
42             return super.evaluateItem(c);
43         }
44     }
45
46     /**
47     * Return an iteration over the result sequence
48     */

49
50     public SequenceIterator iterate(XPathContext c) throws XPathException {
51         if (operation==CURRENT_GROUP) {
52             GroupIterator gi = c.getCurrentGroupIterator();
53             if (gi==null) {
54                 return EmptyIterator.getInstance();
55             }
56             return gi.iterateCurrentGroup();
57         } else {
58             return super.iterate(c);
59         }
60     }
61
62     /**
63     * Determine the dependencies
64     */

65
66     public int getIntrinsicDependencies() {
67        return StaticProperty.DEPENDS_ON_CURRENT_GROUP;
68     }
69
70 }
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
//
92
Popular Tags