KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > scripting > interpreter > JythonInterpreter


1 /*
2   The contents of this file are subject to the Mozilla Public License Version 1.1
3   (the "License"); you may not use this file except in compliance with the
4   License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5   
6   Software distributed under the License is distributed on an "AS IS" basis,
7   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8   for the specific language governing rights and
9   limitations under the License.
10
11   The Original Code is "The Columba Project"
12   
13   The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
14   Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
15   
16   All Rights Reserved.
17 */

18 package org.columba.core.scripting.interpreter;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.columba.core.scripting.model.ColumbaScript;
24 import org.python.util.PythonInterpreter;
25
26 /**
27     @author Celso Pinto (cpinto@yimports.com)
28  */

29 public class JythonInterpreter
30     extends ScriptInterpreter
31 {
32
33     private final static String JavaDoc[] EXTENSIONS = new String JavaDoc[]{"py", "jython"};
34
35     public String JavaDoc getName()
36     {
37         return "Jython Interpreter";
38     }
39
40     public String JavaDoc[] getSupportedExtensions()
41     {
42         return EXTENSIONS;
43     }
44
45     public void execute(ColumbaScript script, Map JavaDoc vars)
46     {
47         /*
48         * it's the script responsability to define the "metadata" by invoking
49         * .setName(), .setAuthor() and .setDescription()
50         */

51         logger.append("Executing jython: " + script.getPath());
52
53         PythonInterpreter jython = new PythonInterpreter();
54
55         for (Iterator JavaDoc it = vars.entrySet().iterator(); it.hasNext();)
56         {
57             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
58             jython.set(entry.getKey().toString(), entry.getValue());
59         }
60
61         jython.execfile(script.getPath());
62         jython.cleanup();
63
64     }
65
66 }
67
Popular Tags