KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.expr;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.*;
4
5 import java.util.*;
6
7 /**
8 * An expression whose value is always a set of nodes containing a single node, the document root.
9 */

10
11 public class RootExpression extends SingletonExpression {
12
13
14     /**
15     * Simplify an expression
16     * @return the simplified expression
17     */

18
19     public Expression simplify() throws XPathException {
20         return this;
21     }
22
23     /**
24     * Return the first element selected by this Expression
25     * @param context The evaluation context
26     * @return the NodeInfo of the first selected element, or null if no element
27     * is selected
28     */

29
30     public NodeInfo getNode(Context context) throws XPathException {
31         return (context.getContextNodeInfo()).getDocumentRoot();
32     }
33
34     /**
35     * Evaluate as a string
36     * @param context The context for evaluation
37     * @return The concatenation of all the character data within the document
38     */

39
40     public String JavaDoc evaluateAsString(Context context) throws XPathException {
41         return (context.getContextNodeInfo()).getDocumentRoot().getStringValue();
42     }
43
44     /**
45     * Evaluate as a boolean.
46     * @param context The context (not used)
47     * @return true (always - because the nodeset is never empty)
48     */

49
50     public boolean evaluateAsBoolean(Context context) throws XPathException {
51         return true;
52     }
53
54     /**
55     * Determine which aspects of the context the expression depends on. The result is
56     * a bitwise-or'ed value composed from constants such as Context.VARIABLES and
57     * Context.CURRENT_NODE
58     */

59
60     public int getDependencies() {
61         return Context.CONTEXT_NODE | Context.CONTEXT_DOCUMENT;
62     }
63
64     /**
65     * Perform a partial evaluation of the expression, by eliminating specified dependencies
66     * on the context.
67     * @param dependencies The dependencies to be removed
68     * @param context The context to be used for the partial evaluation
69     * @return a new expression that does not have any of the specified
70     * dependencies
71     */

72
73     public Expression reduce(int dependencies, Context context) throws XPathException {
74         if ((dependencies & (Context.CONTEXT_NODE | Context.CONTEXT_DOCUMENT)) != 0 ) {
75             return new SingletonNodeSet(
76                         (context.getContextNodeInfo()).getDocumentRoot());
77         } else {
78             return this;
79         }
80     }
81
82     /**
83     * Diagnostic print of expression structure
84     */

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