KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > ParentNodeExpression


1 package net.sf.saxon.expr;
2 import net.sf.saxon.om.Item;
3 import net.sf.saxon.om.NamePool;
4 import net.sf.saxon.om.NodeInfo;
5 import net.sf.saxon.trans.XPathException;
6
7 import java.io.PrintStream JavaDoc;
8
9 /**
10 * Class ParentNodeExpression represents the XPath expression ".." or "parent::node()"
11 */

12
13 public class ParentNodeExpression extends SingleNodeExpression {
14
15     /**
16     * Return the node selected by this SingleNodeExpression
17     * @param context The context for the evaluation
18     * @return the parent of the current node defined by the context
19     */

20
21     public NodeInfo getNode(XPathContext context) throws XPathException {
22         Item item = context.getContextItem();
23         if (item==null) {
24             dynamicError("The context item is not set", context);
25         }
26         if (item instanceof NodeInfo) {
27             return ((NodeInfo)item).getParent();
28         } else {
29             return null;
30         }
31     }
32
33     /**
34     * Determine which aspects of the context the expression depends on. The result is
35     * a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and
36     * XPathContext.CURRENT_NODE
37     */

38 /*
39     public int getDependencies() {
40         return StaticProperty.CONTEXT_ITEM;
41     }
42 */

43     /**
44     * Is this expression the same as another expression?
45     */

46
47     public boolean equals(Object JavaDoc other) {
48         return (other instanceof ParentNodeExpression);
49     }
50
51     /**
52     * get HashCode for comparing two expressions
53     */

54
55     public int hashCode() {
56         return "ParentNodeExpression".hashCode();
57     }
58
59
60     /**
61     * Diagnostic print of expression structure
62     */

63
64     public void display(int level, NamePool pool, PrintStream JavaDoc out) {
65         out.println(ExpressionTool.indent(level) + "..");
66     }
67
68 }
69
70 //
71
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
72
// you may not use this file except in compliance with the License. You may obtain a copy of the
73
// License at http://www.mozilla.org/MPL/
74
//
75
// Software distributed under the License is distributed on an "AS IS" basis,
76
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
77
// See the License for the specific language governing rights and limitations under the License.
78
//
79
// The Original Code is: all this file.
80
//
81
// The Initial Developer of the Original Code is Michael H. Kay.
82
//
83
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
84
//
85
// Contributor(s): none.
86
//
87
Popular Tags