KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > Root


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.StaticContext;
4 import net.sf.saxon.expr.StaticProperty;
5 import net.sf.saxon.expr.XPathContext;
6 import net.sf.saxon.om.Item;
7 import net.sf.saxon.om.NodeInfo;
8 import net.sf.saxon.trans.XPathException;
9
10 /**
11 * Implement the XPath 2.0 root() function
12 */

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
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 Michael H. Kay
72
//
73
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
74
//
75
// Contributor(s): none.
76
//
77
Popular Tags