KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > q2 > lang > Q2Apply


1 package gnu.q2.lang;
2 import gnu.mapping.*;
3 import gnu.lists.*;
4 import gnu.expr.*;
5 import java.util.Vector JavaDoc;
6
7 public class Q2Apply extends MethodProc
8 {
9   public static Q2Apply q2Apply = new Q2Apply();
10
11   public void apply (CallContext ctx) throws Throwable JavaDoc
12   {
13     Object JavaDoc endMarker = Special.dfault;
14     Object JavaDoc arg = ctx.getNextArg(endMarker);
15     if (arg instanceof Procedure)
16       {
17     Procedure proc = (Procedure) arg;
18     Vector JavaDoc vec = new Vector JavaDoc();
19     for (;;)
20       {
21         arg = ctx.getNextArg(endMarker);
22         if (arg == endMarker)
23           break;
24         if (arg instanceof Values)
25           {
26         Object JavaDoc[] vals = ((Values) arg).getValues();
27         for (int i = 0; i < vals.length; i++)
28           vec.add(vals[i]);
29           }
30         else
31           vec.add(arg); // requires collections FIXME
32
}
33     arg = proc.applyN(vec.toArray());
34     if (arg instanceof Consumable)
35       ((Consumable) arg).consume(ctx.consumer);
36     else
37       ctx.writeValue(arg);
38     return;
39       }
40     for (;;)
41       {
42     if (arg == endMarker)
43       break;
44     if (arg instanceof Consumable)
45       ((Consumable) arg).consume(ctx.consumer);
46     else
47       ctx.writeValue(arg);
48     arg = ctx.getNextArg(endMarker);
49       }
50   }
51
52   /*
53   public Object applyN (Object[] args) throws Throwable
54   {
55     if (args.length == 0)
56       return Values.empty;
57     Object arg0 = args[0];
58     if (arg0 instanceof Procedure)
59       {
60     Object[] xargs = new Object[args.length-1];
61     System.arraycopy(args, 1, xargs, 0, xargs.length);
62     return ((Procedure) arg0).applyN(xargs);
63       }
64     return gnu.kawa.functions.AppendValues.appendValues.applyN(args);
65   }
66   */

67 }
68
Popular Tags