KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cpmake > JythonShellInterpreter


1 /*
2  * Copyright (c) 2004, Brian Hawkins
3  * brianhks@activeclickweb.com
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20  
21 package cpmake;
22
23 import org.python.util.PythonInterpreter;
24 import java.io.*;
25
26 class JythonShellInterpreter
27         implements ScriptInterpreter
28     {
29     private PythonInterpreter m_interpreter;
30     
31     public JythonShellInterpreter(CPMake make)
32         {
33         PythonInterpreter.initialize(make.getProperties(), make.getProperties(), null);
34         
35         m_interpreter = new PythonInterpreter();
36         
37         }
38         
39     public void set(String JavaDoc var, Object JavaDoc value)
40             throws CPMakeException
41         {
42         m_interpreter.set(var, value);
43         }
44         
45     public void call(String JavaDoc method, String JavaDoc param1)
46             throws CPMakeException
47         {
48         try
49             {
50             call(method, param1, null);
51             }
52         catch (Exception JavaDoc e)
53             {
54             throw new CPMakeException(e.toString(), -1);
55             }
56         }
57         
58     public void call(String JavaDoc method, String JavaDoc param1, String JavaDoc param2)
59             throws CPMakeException
60         {
61         String JavaDoc cmd;
62         if (param2 == null)
63             cmd = method + "(" + param1 + ")";
64         else
65             cmd = method + "(" + param1 + ", " + param2 + ")";
66             
67         m_interpreter.exec(cmd);
68         }
69         
70     public void source(String JavaDoc file)
71             throws CPMakeException, FileNotFoundException, IOException
72         {
73         try
74             {
75             m_interpreter.execfile(file);
76             }
77         catch (Exception JavaDoc e)
78             {
79             throw new CPMakeException(e.toString(), -1);
80             }
81         }
82         
83     public void cleanup()
84         {
85         m_interpreter.cleanup();
86         }
87     }
88
Popular Tags