package client.net.sf.saxon.ce.functions; import client.net.sf.saxon.ce.expr.*; import client.net.sf.saxon.ce.om.Item; import client.net.sf.saxon.ce.om.NodeInfo; import client.net.sf.saxon.ce.trans.XPathException; /** * Implement the XPath 2.0 root() function */ public class Root extends SystemFunction { public Root newInstance() { return new Root(); } /** * Simplify and validate. * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { useContextItemAsDefault(); return simplifyArguments(visitor); } /** * Get the static properties of this expression (other than its type). The result is * bit-significant. These properties are used for optimizations. In general, if * property bit is set, it is true, but if it is unset, the value is unknown. */ public int computeSpecialProperties() { int prop = StaticProperty.ORDERED_NODESET | StaticProperty.SINGLE_DOCUMENT_NODESET | StaticProperty.NON_CREATIVE; if ((getNumberOfArguments() == 0) || (argument[0].getSpecialProperties() & StaticProperty.CONTEXT_DOCUMENT_NODESET) != 0) { prop |= StaticProperty.CONTEXT_DOCUMENT_NODESET; } return prop; } /** * Evaluate in a general context */ public Item evaluateItem(XPathContext c) throws XPathException { NodeInfo start = (NodeInfo)argument[0].evaluateItem(c); if (start==null) { return null; } return start.getRoot(); } } // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.