KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.expr;
2 import com.icl.saxon.Context;
3 import com.icl.saxon.om.*;
4
5
6 /**
7 * This class represents the expression ".", which always returns the context node.
8 */

9
10 public final class ContextNodeExpression extends SingletonExpression {
11
12     /**
13     * Return the node selected by this expression.
14     * @param context The context for the evaluation
15     * @return one NodeInfo only,
16     * namely the current node defined by the context
17     */

18
19     public NodeInfo getNode(Context context) throws XPathException {
20         return context.getContextNodeInfo();
21     }
22
23     /**
24     * Determine which aspects of the context the expression depends on. The result is
25     * a bitwise-or'ed value composed from constants such as Context.VARIABLES and
26     * Context.CURRENT_NODE
27     */

28
29     public int getDependencies() {
30         return Context.CONTEXT_NODE;
31     }
32
33     /**
34     * Perform a partial evaluation of the expression, by eliminating specified dependencies
35     * on the context.
36     * @param dependencies The dependencies to be removed
37     * @param context The context to be used for the partial evaluation
38     * @return a new expression that does not have any of the specified
39     * dependencies
40     */

41
42     public Expression reduce(int dependencies, Context context) throws XPathException {
43         if ((dependencies & Context.CONTEXT_NODE) != 0 ) {
44             return new SingletonNodeSet(context.getContextNodeInfo());
45         } else {
46             return this;
47         }
48     }
49
50     /**
51     * Diagnostic print of expression structure
52     */

53     
54     public void display(int level) {
55         System.err.println(indent(level) + ".");
56     }
57
58 }
59
60 //
61
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
62
// you may not use this file except in compliance with the License. You may obtain a copy of the
63
// License at http://www.mozilla.org/MPL/
64
//
65
// Software distributed under the License is distributed on an "AS IS" basis,
66
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
67
// See the License for the specific language governing rights and limitations under the License.
68
//
69
// The Original Code is: all this file.
70
//
71
// The Initial Developer of the Original Code is
72
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
73
//
74
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
75
//
76
// Contributor(s): none.
77
//
78
Popular Tags