KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > shell > Kawa


1 // $Id: Kawa.java,v 1.1.1.1 2000/09/26 11:20:35 ramsdell Exp $
2

3 // The implementation of the Kawa Scheme operator.
4

5 /*
6  * Copyright 1998 by John D. Ramsdell
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 package edu.neu.ccs.jmk.shell;
24
25 import kawa.standard.Scheme;
26 import edu.neu.ccs.jmk.Operator;
27 import edu.neu.ccs.jmk.CommandFailedException;
28
29 /**
30  * JPython as an Operator.
31  * <pre>
32  * scheme = "edu.neu.ccs.jmk.shell.Kawa";
33  *
34  * "all":;
35  * {
36  * forname scheme "(+ 1 4)";
37  * }
38  * </pre>
39  */

40 public class Kawa
41 implements Operator
42 {
43   public String JavaDoc getName() {
44     return "Kawa";
45   }
46
47   /**
48    * Execute the operation by concatenating the arguments
49    * and executing the string using Kawa Scheme.
50    * @param args parameters to the operation
51    * @param out place to write messages
52    * @exception CommandFailedException if operation failed
53    */

54   public void exec(String JavaDoc[] args, java.io.PrintWriter JavaDoc out)
55        throws CommandFailedException
56   {
57     if (args.length == 0)
58       throw new CommandFailedException("No args to " + getName());
59     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(args[0]);
60     for (int i = 1; i < args.length; i++)
61       sb.append(args[i]);
62     Scheme scheme = new Scheme();
63     try {
64       scheme.eval(sb.toString());
65     }
66     catch (Exception JavaDoc schex) {
67       out.println(schex);
68       throw new CommandFailedException(getName() + " threw an exception");
69     }
70   }
71 }
72
Popular Tags