1 package jfun.yan.xml.nuts; 2 3 import java.util.ArrayList ; 4 import java.util.Arrays ; 5 import java.util.Map ; 6 7 import jfun.yan.xml.NutsFunction; 8 import jfun.yan.xml.NutsUtils; 9 import jfun.yan.xml.nut.Nut; 10 11 17 public class FunctionCallNut extends Nut { 18 private NutsFunction function; 19 private Object [] args; 20 private Map with; 21 22 public Map getWith() { 23 return with; 24 } 25 public void setWith(Map with) { 26 checkDuplicate("args", this.args); 27 this.with = with; 28 } 29 public Object [] getArgs() { 30 return args; 31 } 32 public void setArgs(Object [] args) { 33 checkDuplicate("with", this.with); 34 this.args = args; 35 } 36 public NutsFunction getFunction() { 37 return function; 38 } 39 public void setFunction(NutsFunction function) { 40 this.function = function; 41 } 42 public void set(Object [] a){ 43 checkDuplicate("with", this.with); 44 if(args==null) 45 this.args = a; 46 else{ 47 final ArrayList buf = new ArrayList (a.length+args.length); 48 buf.addAll(Arrays.asList(args)); 49 buf.addAll(Arrays.asList(a)); 50 this.args = buf.toArray(); 51 } 52 } 53 public Object eval(){ 54 checkMandatory("function", function); 55 if(this.with==null){ 56 checkMandatory("args", args); 57 return NutsUtils.callFunction(function, args); 58 } 59 else{ 60 return NutsUtils.callFunction(function, with); 61 } 62 } 63 } 64 | Popular Tags |