1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.expr.*; 4 import com.icl.saxon.om.NodeInfo; 5 import java.util.*; 6 import java.text.*; 7 8 9 10 public class StringFn extends Function { 11 12 15 16 public String getName() { 17 return "string"; 18 }; 19 20 24 25 public int getDataType() { 26 return Value.STRING; 27 } 28 29 33 34 public Expression simplify() throws XPathException { 35 int numArgs = checkArgumentCount(0, 1); 36 if (numArgs==1) { 37 argument[0] = argument[0].simplify(); 38 if (argument[0].getDataType()==Value.STRING) { 39 return argument[0]; 40 } 41 if (argument[0] instanceof Value) { 42 return new StringValue(((Value)argument[0]).asString()); 43 } 44 } 45 return this; 46 } 47 48 51 52 public String evaluateAsString(Context c) throws XPathException { 53 if (getNumberOfArguments()==1) { 54 return argument[0].evaluateAsString(c); 55 } else { 56 return (c.getContextNodeInfo()).getStringValue(); 57 } 58 } 59 60 63 64 public Value evaluate(Context c) throws XPathException { 65 return new StringValue(evaluateAsString(c)); 66 } 67 68 71 72 public int getDependencies() { 73 if (getNumberOfArguments()==1) { 74 return argument[0].getDependencies(); 75 } else { 76 return Context.CONTEXT_NODE; 77 } 78 } 79 80 83 84 public Expression reduce(int dep, Context c) throws XPathException { 85 if (getNumberOfArguments()==1) { 86 StringFn f = new StringFn(); 87 f.addArgument(argument[0].reduce(dep, c)); 88 f.setStaticContext(getStaticContext()); 89 return f.simplify(); 90 } else { 91 if ((dep & Context.CONTEXT_NODE) != 0) { 92 return evaluate(c); 93 } else { 94 return this; 95 } 96 } 97 } 98 99 100 } 101 102 103 | Popular Tags |