1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.expr.*; 5 6 import java.util.*; 7 8 9 public class FunctionAvailable extends Function { 10 11 14 15 public String getName() { 16 return "function-available"; 17 }; 18 19 23 24 public int getDataType() { 25 return Value.BOOLEAN; 26 } 27 28 32 33 public Expression simplify() throws XPathException { 34 checkArgumentCount(1, 1); 35 argument[0] = argument[0].simplify(); 36 if (argument[0] instanceof Value) { 37 return evaluate(null); 38 } 39 return this; 40 } 41 42 45 46 public boolean evaluateAsBoolean(Context c) throws XPathException { 47 String qname = argument[0].evaluateAsString(c); 48 return getStaticContext().isFunctionAvailable(qname); 49 } 50 51 52 55 56 public Value evaluate(Context c) throws XPathException { 57 return new BooleanValue(evaluateAsBoolean(c)); 58 } 59 60 63 64 public int getDependencies() { 65 return argument[0].getDependencies(); 66 } 67 68 71 72 public Expression reduce(int dep, Context c) throws XPathException { 73 FunctionAvailable f = new FunctionAvailable(); 74 f.addArgument(argument[0].reduce(dep, c)); 75 f.setStaticContext(getStaticContext()); 76 return f.simplify(); 77 } 78 79 80 } 81 82 83 84 | Popular Tags |