1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.expr.*; 4 5 import java.util.*; 6 9 public class Concat extends Function { 10 11 14 15 public String getName() { 16 return "concat"; 17 }; 18 19 23 24 public int getDataType() { 25 return Value.STRING; 26 } 27 28 32 33 public Expression simplify() throws XPathException { 34 int numArgs = checkArgumentCount(2, Integer.MAX_VALUE); 35 boolean allKnown = true; 36 for (int i=0; i<numArgs; i++) { 37 argument[i] = argument[i].simplify(); 38 if (!(argument[i] instanceof Value)) { 39 allKnown = false; 40 } 41 } 42 if (allKnown) { 43 return evaluate(null); 44 } 45 return this; 46 } 47 48 51 52 public String evaluateAsString(Context c) throws XPathException { 53 int numArgs = getNumberOfArguments(); 54 55 StringBuffer sb = new StringBuffer (); 56 for (int i=0; i<numArgs; i++) { 57 sb.append(argument[i].evaluateAsString(c)); 58 } 59 60 return sb.toString(); 61 } 62 63 66 67 public Value evaluate(Context c) throws XPathException { 68 return new StringValue(evaluateAsString(c)); 69 } 70 71 74 75 public int getDependencies() { 76 int numArgs = getNumberOfArguments(); 77 int dep = 0; 78 for (int i=0; i<numArgs; i++) { 79 dep |= argument[i].getDependencies(); 80 } 81 return dep; 82 } 83 84 87 88 public Expression reduce(int dep, Context c) throws XPathException { 89 Concat f = new Concat(); 90 int numArgs = getNumberOfArguments(); 91 for (int i=0; i<numArgs; i++) { 92 f.addArgument(argument[i].reduce(dep, c)); 93 } 94 f.setStaticContext(getStaticContext()); 95 return f.simplify(); 96 } 97 98 } 99 100 101 102 | Popular Tags |