01: package net.sf.saxon.expr;
02:
03: import net.sf.saxon.om.Item;
04: import net.sf.saxon.om.NamePool;
05: import net.sf.saxon.om.NodeInfo;
06: import net.sf.saxon.trans.XPathException;
07:
08: import java.io.PrintStream;
09:
10: /**
11: * Class ParentNodeExpression represents the XPath expression ".." or "parent::node()"
12: */
13:
14: public class ParentNodeExpression extends SingleNodeExpression {
15:
16: /**
17: * Return the node selected by this SingleNodeExpression
18: * @param context The context for the evaluation
19: * @return the parent of the current node defined by the context
20: */
21:
22: public NodeInfo getNode(XPathContext context) throws XPathException {
23: Item item = context.getContextItem();
24: if (item == null) {
25: dynamicError("The context item is not set", context);
26: }
27: if (item instanceof NodeInfo) {
28: return ((NodeInfo) item).getParent();
29: } else {
30: return null;
31: }
32: }
33:
34: /**
35: * Determine which aspects of the context the expression depends on. The result is
36: * a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and
37: * XPathContext.CURRENT_NODE
38: */
39: /*
40: public int getDependencies() {
41: return StaticProperty.CONTEXT_ITEM;
42: }
43: */
44: /**
45: * Is this expression the same as another expression?
46: */
47:
48: public boolean equals(Object other) {
49: return (other instanceof ParentNodeExpression);
50: }
51:
52: /**
53: * get HashCode for comparing two expressions
54: */
55:
56: public int hashCode() {
57: return "ParentNodeExpression".hashCode();
58: }
59:
60: /**
61: * Diagnostic print of expression structure
62: */
63:
64: public void display(int level, NamePool pool, PrintStream 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: //
|