KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.*;
4 import com.icl.saxon.expr.*;
5 import javax.xml.transform.*;
6 import java.util.*;
7
8 /**
9 * GroupActivation represents one activation of a saxon:group loop. It is implemented as a
10 * NodeEnumeration with one extra method, the ability to test whether the value of a key on
11 * the current node is the same as the value of the key on the next node. Control over the
12 * iteration is shared between the saxon:group and saxon:item elements.
13 */

14
15 public class GroupActivation implements NodeEnumeration {
16
17     private SAXONGroup group;
18     private NodeEnumeration nodes;
19     private Expression groupkey;
20     private Context context;
21     private NodeInfo next = null;
22     private Value nextValue = null;
23     private NodeInfo current = null;
24     private Value currentValue = null;
25     private int position = 0;
26             
27     public GroupActivation(SAXONGroup group, Expression groupkey, NodeEnumeration nodes, Context c)
28             throws XPathException
29     {
30         this.group = group;
31         this.groupkey = groupkey;
32         this.nodes = nodes;
33         this.context = c;
34         this.position = 0;
35         this.current = null;
36         this.currentValue = null;
37         lookAhead();
38     }
39
40     private void lookAhead() throws XPathException {
41         if (nodes.hasMoreElements()) {
42             next = nodes.nextElement();
43             context.setCurrentNode(next);
44             context.setContextNode(next);
45             context.setPosition(position+1);
46             nextValue = groupkey.evaluate(context);
47         } else {
48             next = null;
49         }
50     }
51
52     public boolean hasMoreElements() {
53         return next != null;
54     }
55
56     public NodeInfo nextElement() throws XPathException {
57         current = next;
58         currentValue = nextValue;
59         position++;
60         lookAhead();
61         context.setCurrentNode(current);
62         context.setContextNode(current);
63         context.setPosition(position);
64         return current;
65     }
66
67     public boolean sameAsNext() throws XPathException {
68         if (next==null) return false;
69         return (currentValue.equals(nextValue));
70     }
71
72     public boolean isSorted() {
73         return nodes.isSorted();
74     }
75
76     public boolean isReverseSorted() {
77         return nodes.isReverseSorted();
78     }
79
80     public boolean isPeer() {
81         return nodes.isPeer();
82     }
83         
84 }
85
86 //
87
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
88
// you may not use this file except in compliance with the License. You may obtain a copy of the
89
// License at http://www.mozilla.org/MPL/
90
//
91
// Software distributed under the License is distributed on an "AS IS" basis,
92
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
93
// See the License for the specific language governing rights and limitations under the License.
94
//
95
// The Original Code is: all this file.
96
//
97
// The Initial Developer of the Original Code is
98
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
99
//
100
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
101
//
102
// Contributor(s): none.
103
//
104
Popular Tags