import java.io.*;
import org.python.util.PythonInterpreter; 
import org.python.core.*; 

/***
 * Tiny example of using JPython in a java environment
 * @author mitch fincher, mitch[at]fincher[dot]org
 * Feb 2000
**/
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
public class JPythonTest
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
{
    private String name = "";
    public void setName(String name) {this.name = name;}
    public String getName() {return name;}

///////////////////////////////////////////////////////////////
public static void main(String argv[])
////////////////////////////////////////////////////////////////
    {
	JPythonTest jPythonTest = null;
	try {
	    // create any object based on a String name.
	   jPythonTest = 
		(JPythonTest)(Class.forName("JPythonTest")).newInstance();
	   jPythonTest.setName("ImATest");
	   PythonInterpreter pythonInterpreter = new PythonInterpreter();

	   pythonInterpreter.set("r", new PyString("")); //create internal variable
	   //equate a java variable to a variable in the jpython namespace 
	   pythonInterpreter.set("jPythonTest", jPythonTest); 
	   //exec the command and stash result in temp variable
	   pythonInterpreter.exec("r = jPythonTest.getName()");
	   String string = (String)pythonInterpreter.get("r",
		 Class.forName("java.lang.String"));
	   
	   System.out.println("name = " + string);
	} catch (Exception e) {
	    System.out.println("exception: " + e);
	}

	
    }
    
    

} // JPythonTest
