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