KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > FunctionCallNut


1 package jfun.yan.xml.nuts;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Arrays JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import jfun.yan.xml.NutsFunction;
8 import jfun.yan.xml.NutsUtils;
9 import jfun.yan.xml.nut.Nut;
10
11 /**
12  * The Nut class for <call> tag.
13  * <p>
14  * @author Ben Yu
15  * Nov 23, 2005 1:05:23 AM
16  */

17 public class FunctionCallNut extends Nut {
18   private NutsFunction function;
19   private Object JavaDoc[] args;
20   private Map JavaDoc with;
21   
22   public Map JavaDoc getWith() {
23     return with;
24   }
25   public void setWith(Map JavaDoc with) {
26     checkDuplicate("args", this.args);
27     this.with = with;
28   }
29   public Object JavaDoc[] getArgs() {
30     return args;
31   }
32   public void setArgs(Object JavaDoc[] 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 JavaDoc[] a){
43     checkDuplicate("with", this.with);
44     if(args==null)
45       this.args = a;
46     else{
47       final ArrayList JavaDoc buf = new ArrayList JavaDoc(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 JavaDoc 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