| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.Negatable; |
| 12 |
import net.sf.saxon.expr.SystemFunctionCall; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.expr.parser.ContextItemStaticInfo; |
| 15 |
import net.sf.saxon.expr.parser.ExpressionTool; |
| 16 |
import net.sf.saxon.expr.parser.ExpressionVisitor; |
| 17 |
import net.sf.saxon.expr.parser.TypeChecker; |
| 18 |
import net.sf.saxon.om.Sequence; |
| 19 |
import net.sf.saxon.pattern.NodeTest; |
| 20 |
import net.sf.saxon.trans.XPathException; |
| 21 |
import net.sf.saxon.type.TypeHierarchy; |
| 22 |
import net.sf.saxon.value.BooleanValue; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class NotFn extends SystemFunction { |
| 30 |
|
| 31 |
|
| 32 |
@Override |
| 33 |
public void supplyTypeInformation(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType, Expression[] arguments) throws XPathException { |
| 34 |
XPathException err = TypeChecker.ebvError(arguments[0], visitor.getConfiguration().getTypeHierarchy()); |
| 35 |
if (err != null) { |
| 36 |
throw err; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public BooleanValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 50 |
return BooleanValue.get(!ExpressionTool.effectiveBooleanValue(arguments[0].iterate())); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@Override |
| 62 |
public Expression makeFunctionCall(Expression[] arguments) { |
| 63 |
return new SystemFunctionCall(this, arguments) { |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public boolean effectiveBooleanValue(XPathContext c) throws XPathException { |
| 69 |
try { |
| 70 |
return !getArg(0).effectiveBooleanValue(c); |
| 71 |
} catch (XPathException e) { |
| 72 |
e.maybeSetLocation(getLocation()); |
| 73 |
e.maybeSetContext(c); |
| 74 |
throw e; |
| 75 |
} |
| 76 |
} |
| 77 |
}; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
@Override |
| 91 |
public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { |
| 92 |
TypeHierarchy th = visitor.getStaticContext().getConfiguration().getTypeHierarchy(); |
| 93 |
if (arguments[0] instanceof Negatable && ((Negatable) arguments[0]).isNegatable(th)) { |
| 94 |
return ((Negatable) arguments[0]).negate(); |
| 95 |
} |
| 96 |
if (arguments[0].getItemType() instanceof NodeTest) { |
| 97 |
SystemFunction empty = SystemFunction.makeFunction("empty", getRetainedStaticContext(), 1); |
| 98 |
return empty.makeFunctionCall(arguments[0]).optimize(visitor, contextInfo); |
| 99 |
} |
| 100 |
return null; |
| 101 |
} |
| 102 |
|
| 103 |
public String getCompilerName() { |
| 104 |
return "NotFnCompiler"; |
| 105 |
} |
| 106 |
|
| 107 |
public String getStreamerName() { |
| 108 |
return "NotFn"; |
| 109 |
} |
| 110 |
} |
| 111 |
|