1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.NamePool; 4 import net.sf.saxon.om.SequenceIterator; 5 import net.sf.saxon.om.SingletonIterator; 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.type.Type; 10 11 import java.io.PrintStream ; 12 13 14 18 19 public final class ContextItemExpression extends ComputedExpression { 20 21 ItemType itemType = Type.ITEM_TYPE; 22 23 public ContextItemExpression() {} 24 25 28 29 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 30 if (contextItemType == null) { 31 StaticError err = new StaticError("The context item is undefined at this point"); 32 err.setErrorCode("XPDY0002"); 33 err.setIsTypeError(true); 34 err.setLocator(this); 35 throw err; 36 } 37 itemType = contextItemType; 38 return this; 39 } 40 41 58 59 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 60 return typeCheck(env, contextItemType); 63 } 64 65 68 69 public ItemType getItemType() { 70 return itemType; 71 } 72 73 76 77 public int computeCardinality() { 78 return StaticProperty.EXACTLY_ONE; 79 } 80 81 85 86 public int computeSpecialProperties() { 87 int p = super.computeSpecialProperties(); 88 return p | StaticProperty.NON_CREATIVE; 89 } 90 91 94 95 public boolean equals(Object other) { 96 return (other instanceof ContextItemExpression); 97 } 98 99 102 103 public int hashCode() { 104 return "ContextItemExpression".hashCode(); 105 } 106 107 public int getIntrinsicDependencies() { 108 return StaticProperty.DEPENDS_ON_CONTEXT_ITEM; 109 } 110 111 114 115 public SequenceIterator iterate(XPathContext context) throws XPathException { 116 Item item = context.getContextItem(); 117 if (item==null) { 118 dynamicError("The context item is not set", context); 119 } 120 return SingletonIterator.makeIterator(item); 121 } 122 123 126 127 public Item evaluateItem(XPathContext context) throws XPathException { 128 Item item = context.getContextItem(); 129 if (item==null) { 130 dynamicError("The context item is not set", context); 131 } 132 return item; 133 } 134 135 138 139 public void display(int level, NamePool pool, PrintStream out) { 140 out.println(ExpressionTool.indent(level) + '.'); 141 } 142 143 } 144 145 | Popular Tags |