1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.DocumentInfo; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.om.NamePool; 5 import net.sf.saxon.om.NodeInfo; 6 import net.sf.saxon.trans.StaticError; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.type.ItemType; 9 import net.sf.saxon.pattern.NodeKindTest; 10 11 import java.io.PrintStream ; 12 13 14 19 20 public class RootExpression extends SingleNodeExpression { 21 22 23 27 28 public Expression simplify(StaticContext env) throws StaticError { 29 return this; 30 } 31 32 35 36 public boolean equals(Object other) { 37 return (other instanceof RootExpression); 38 } 39 40 43 44 public final int computeCardinality() { 45 return StaticProperty.EXACTLY_ONE; 46 } 47 48 53 54 public ItemType getItemType() { 55 return NodeKindTest.DOCUMENT; 56 } 57 58 61 62 public int hashCode() { 63 return "RootExpression".hashCode(); 64 } 65 66 72 73 public NodeInfo getNode(XPathContext context) throws XPathException { 74 Item current = context.getContextItem(); 75 if (current==null) { 76 dynamicError("Finding root of tree: the context item is undefined", "XPDY0002", context); 77 } 78 if (current instanceof NodeInfo) { 79 DocumentInfo doc = ((NodeInfo)current).getDocumentRoot(); 80 if (doc==null) { 81 dynamicError("The root of the tree containing the context item is not a document node", "XPDY0050", context); 82 } 83 return doc; 84 } 85 typeError("Finding root of tree: the context item is not a node", "XPTY0020", context); 86 return null; 88 } 89 90 95 96 public int getIntrinsicDependencies() { 97 return StaticProperty.DEPENDS_ON_CONTEXT_DOCUMENT | 98 StaticProperty.SINGLE_DOCUMENT_NODESET | 99 StaticProperty.CONTEXT_DOCUMENT_NODESET; 100 } 101 102 105 106 public void display(int level, NamePool pool, PrintStream out) { 107 out.println(ExpressionTool.indent(level) + '/'); 108 } 109 110 } 111 112 | Popular Tags |