jep
Class Jep

java.lang.Object
  extended by jep.Jep

public final class Jep
extends java.lang.Object

 Jep.java - Embeds CPython in Java.

 Copyright (c) 2004, 2005 Mike Johnson.

 This file is licenced under the the zlib/libpng License.

 This software is provided 'as-is', without any express or implied
 warranty. In no event will the authors be held liable for any
 damages arising from the use of this software.
 
 Permission is granted to anyone to use this software for any
 purpose, including commercial applications, and to alter it and
 redistribute it freely, subject to the following restrictions:
 
     1. The origin of this software must not be misrepresented; you
     must not claim that you wrote the original software. If you use
     this software in a product, an acknowledgment in the product
     documentation would be appreciated but is not required.
 
     2. Altered source versions must be plainly marked as such, and
     must not be misrepresented as being the original software.
 
     3. This notice may not be removed or altered from any source
     distribution.

 Created: Fri Apr 30 10:35:03 2004

 

Version:
$Id: Jep.html 357 2006-09-18 03:26:54Z mrjohnson0 $
Author:
[mrjohnson0 at sourceforge.net] Mike Johnson

Constructor Summary
Jep()
          Creates a new Jep instance.
Jep(boolean interactive)
          Creates a new Jep instance.
Jep(boolean interactive, java.lang.String includePath)
          Creates a new Jep instance.
Jep(boolean interactive, java.lang.String includePath, java.lang.ClassLoader cl)
          Creates a new Jep instance.
 
Method Summary
 void close()
          Shutdown python interpreter.
 jep.python.PyModule createModule(java.lang.String name)
          Create a python module on the interpreter.
 boolean eval(java.lang.String str)
           Evaluate python statements.
protected  void finalize()
          Describe finalize method here.
 java.lang.Object getValue(java.lang.String str)
           Retrieves a value from python.
 boolean isInteractive()
          get interactive
 void isValidThread()
          all calls must check thread
 void runScript(java.lang.String script)
          run a python script.
 void runScript(java.lang.String script, java.lang.ClassLoader cl)
          run a python script.
 void set(java.lang.String name, boolean v)
          Describe set method here.
 void set(java.lang.String name, byte b)
          Describe set method here.
 void set(java.lang.String name, char v)
          Describe set method here.
 void set(java.lang.String name, char[] v)
          Describe set method here.
 void set(java.lang.String name, double v)
          Describe set method here.
 void set(java.lang.String name, float v)
          Describe set method here.
 void set(java.lang.String name, int v)
          Describe set method here.
 void set(java.lang.String name, long v)
          Describe set method here.
 void set(java.lang.String name, java.lang.Object v)
          Describe set method here.
 void set(java.lang.String name, short v)
          Describe set method here.
 void set(java.lang.String name, java.lang.String v)
          Describe set method here.
 void setClassLoader(java.lang.ClassLoader cl)
          set default classloader
 void setInteractive(boolean v)
          changes behavior of eval()
 jep.python.PyObject trackObject(jep.python.PyObject obj)
           Track Python objects we create so they can be smoothly shutdown with no risk of crashes due to bad reference counting.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jep

public Jep()
    throws JepException
Creates a new Jep instance.

Throws:
JepException - if an error occurs

Jep

public Jep(boolean interactive)
    throws JepException
Creates a new Jep instance.

Parameters:
interactive - a boolean value
Throws:
JepException - if an error occurs

Jep

public Jep(boolean interactive,
           java.lang.String includePath)
    throws JepException
Creates a new Jep instance.

Parameters:
interactive - a boolean value
includePath - a ':' delimited String of directories
Throws:
JepException - if an error occurs

Jep

public Jep(boolean interactive,
           java.lang.String includePath,
           java.lang.ClassLoader cl)
    throws JepException
Creates a new Jep instance.

Parameters:
interactive - a boolean value
includePath - a String value
cl - a ClassLoader value
Throws:
JepException - if an error occurs
Method Detail

isValidThread

public void isValidThread()
                   throws JepException
all calls must check thread

Throws:
JepException - if an error occurs

runScript

public void runScript(java.lang.String script)
               throws JepException
run a python script.

Parameters:
script - a String absolute path to script file.
Throws:
JepException - if an error occurs

runScript

public void runScript(java.lang.String script,
                      java.lang.ClassLoader cl)
               throws JepException
run a python script.

Parameters:
script - a String absolute path to script file.
cl - a ClassLoader value, may be null.
Throws:
JepException - if an error occurs

eval

public boolean eval(java.lang.String str)
             throws JepException
 Evaluate python statements.

 In interactive mode, Jep may not immediately execute the given lines of code.
 In that case, eval() returns false and the statement is remembered and
 is appended to the next incoming string.

 If you're running an unknown number of statements, finish with
 eval(null) to flush the statement buffer.

 Interactive mode is slower than a straight eval call since it has to
 compile the code strings to detect the end of the block.
 Non-interactive mode is faster, but code blocks must be complete.

 For Example:
 
eval("if(Test):\n\tprint 'w00t'")
This is a limitation on the Python interpreter and unlikely to change. Also, Python does not readly return object values from eval(). Use getValue(java.lang.String) instead.

Parameters:
str - a String value
Returns:
true if statement complete and was executed.
Throws:
JepException - if an error occurs

getValue

public java.lang.Object getValue(java.lang.String str)
                          throws JepException
 Retrieves a value from python. If the result is not a java object,
 the implementation currently returns a String.

 Python is pretty picky about what it excepts here. The general syntax:
 
eval("a = 5") String a = (String) getValue("a")
will work.

Parameters:
str - a String value
Returns:
an Object value
Throws:
JepException - if an error occurs

trackObject

public jep.python.PyObject trackObject(jep.python.PyObject obj)
                                throws JepException
 Track Python objects we create so they can be smoothly shutdown
 with no risk of crashes due to bad reference counting.

 Internal use only.
 

Returns:
same object, for inlining stuff
Throws:
JepException - if an error occurs

createModule

public jep.python.PyModule createModule(java.lang.String name)
                                 throws JepException
Create a python module on the interpreter. If the given name is valid, imported module, this method will return that module.

Parameters:
name - a String value
Returns:
a PyModule value
Throws:
JepException - if an error occurs

setClassLoader

public void setClassLoader(java.lang.ClassLoader cl)
set default classloader

Parameters:
cl - a ClassLoader value

setInteractive

public void setInteractive(boolean v)
changes behavior of eval()

Parameters:
v - a boolean value

isInteractive

public boolean isInteractive()
get interactive

Returns:
a boolean value

set

public void set(java.lang.String name,
                java.lang.Object v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - an Object value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                java.lang.String v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a String value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                boolean v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a boolean value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                int v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - an int value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                short v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - an int value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                char[] v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a char[] value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                char v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a char value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                byte b)
         throws JepException
Describe set method here.

Parameters:
name - a String value
b - a byte value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                long v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a long value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                double v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a double value
Throws:
JepException - if an error occurs

set

public void set(java.lang.String name,
                float v)
         throws JepException
Describe set method here.

Parameters:
name - a String value
v - a float value
Throws:
JepException - if an error occurs

close

public void close()
Shutdown python interpreter. Make sure you call this.


finalize

protected void finalize()
Describe finalize method here.

Overrides:
finalize in class java.lang.Object