01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.StaticContext;
05: import net.sf.saxon.expr.StaticProperty;
06: import net.sf.saxon.expr.XPathContext;
07: import net.sf.saxon.om.Item;
08: import net.sf.saxon.om.NodeInfo;
09: import net.sf.saxon.trans.XPathException;
10:
11: /**
12: * Implement the XPath 2.0 root() function
13: */
14:
15: public class Root extends SystemFunction {
16:
17: /**
18: * Simplify and validate.
19: */
20:
21: public Expression simplify(StaticContext env) throws XPathException {
22: useContextItemAsDefault();
23: return simplifyArguments(env);
24: }
25:
26: /**
27: * Get the static properties of this expression (other than its type). The result is
28: * bit-significant. These properties are used for optimizations. In general, if
29: * property bit is set, it is true, but if it is unset, the value is unknown.
30: */
31:
32: public int computeSpecialProperties() {
33: int prop = StaticProperty.ORDERED_NODESET
34: | StaticProperty.SINGLE_DOCUMENT_NODESET
35: | StaticProperty.NON_CREATIVE;
36: if ((getNumberOfArguments() == 0)
37: || (argument[0].getSpecialProperties() & StaticProperty.CONTEXT_DOCUMENT_NODESET) != 0) {
38: prop |= StaticProperty.CONTEXT_DOCUMENT_NODESET;
39: }
40: return prop;
41: }
42:
43: /**
44: * Evaluate in a general context
45: */
46:
47: public Item evaluateItem(XPathContext c) throws XPathException {
48: NodeInfo start = (NodeInfo) argument[0].evaluateItem(c);
49: if (start == null) {
50: return null;
51: }
52: return start.getRoot();
53: }
54:
55: }
56:
57: //
58: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
59: // you may not use this file except in compliance with the License. You may obtain a copy of the
60: // License at http://www.mozilla.org/MPL/
61: //
62: // Software distributed under the License is distributed on an "AS IS" basis,
63: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
64: // See the License for the specific language governing rights and limitations under the License.
65: //
66: // The Original Code is: all this file.
67: //
68: // The Initial Developer of the Original Code is Michael H. Kay
69: //
70: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
71: //
72: // Contributor(s): none.
73: //
|