KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > expr > NodeListExpression


1 package com.icl.saxon.expr;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.NodeEnumeration;
4 import java.util.*;
5
6 /**
7 * A NodeListExpression is an expression denoting a set of nodes sorted in document order. <BR>
8 *
9 * It is not possible to write a NodeListExpression directly using XPath; however a node set
10 * expression is treated as a NodeListExpression when it appears in certain contexts, specifically
11 * the select attribute of xsl:apply-templates or xsl:for-each.
12 */

13
14
15 public class NodeListExpression extends NodeSetExpression {
16
17     private Expression baseExpression;
18
19     /**
20     * Constructor
21     * @param exp The expression that delivers the unsorted node-set
22     */

23
24     public NodeListExpression(Expression exp) {
25         baseExpression = exp;
26     }
27
28     /**
29     * Simplify the expression
30     * @return the simplified expression
31     */

32
33     public Expression simplify() throws XPathException {
34         baseExpression = baseExpression.simplify();
35         if (baseExpression instanceof EmptyNodeSet) {
36             return baseExpression;
37         } else if (baseExpression instanceof SingletonNodeSet) {
38             return baseExpression;
39         } else {
40             return this;
41         }
42     }
43
44     /**
45     * Determine which aspects of the context the expression depends on. The result is
46     * a bitwise-or'ed value composed from constants such as Context.VARIABLES and
47     * Context.CURRENT_NODE
48     */

49
50     public int getDependencies() {
51         return baseExpression.getDependencies();
52     }
53
54     /**
55     * Perform a partial evaluation of the expression, by eliminating specified dependencies
56     * on the context.
57     * @param dependencies The dependencies to be removed
58     * @param context The context to be used for the partial evaluation
59     * @return a new expression that does not have any of the specified
60     * dependencies
61     */

62
63     public Expression reduce(int dependencies, Context context) throws XPathException {
64         if ((getDependencies() & dependencies) != 0) {
65             return new NodeListExpression(baseExpression.reduce(dependencies, context));
66         } else {
67             return this;
68         }
69     }
70
71
72     /**
73     * Return an enumeration that returns the nodes in document order
74     * @param c the evaluation context
75     * @param sort: ignored, this class is used because the enumeration is always in
76     * document order
77     */

78
79     public NodeEnumeration enumerate(Context c, boolean sort) throws XPathException {
80         return baseExpression.enumerate(c, true);
81     }
82
83     /**
84     * Diagnostic print of expression structure
85     */

86     
87     public void display(int level) {
88         System.err.println(indent(level) + "NodeListExpression");
89         baseExpression.display(level+1);
90     }
91
92 }
93     
94
95 //
96
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
97
// you may not use this file except in compliance with the License. You may obtain a copy of the
98
// License at http://www.mozilla.org/MPL/
99
//
100
// Software distributed under the License is distributed on an "AS IS" basis,
101
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
102
// See the License for the specific language governing rights and limitations under the License.
103
//
104
// The Original Code is: all this file.
105
//
106
// The Initial Developer of the Original Code is
107
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
108
//
109
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
110
//
111
// Contributor(s): none.
112
//
113
Popular Tags