Sorry for the delay in response.  I agree with Jim, the object factory implementations contained within the PlyJy project are quite usable, but could still use some tweaking.  I've actually been using the JythonObjectFactory implementation for quite a while now and it does a fine job.  However, the PySystemObjectFactory does perform better due to the implementation as it does not use the PythonInterpreter. 

If anyone interested in trying out the current implementations, simply download the JAR file or compile the source and include in your java project as-is.  

Josh Juneau
juneau001@gmail.com
http://jj-blogger.blogspot.com
Twitter ID:  javajuneau


On Tue, Jul 21, 2009 at 6:57 AM, Tobias Ivarsson <thobes@gmail.com> wrote:
Gabriel,

I would rather say that there currently is no way of defining interfaces for Java code from Jython. You can still use Python code from Java, you just need to define the interfaces (or base classes) in Java and provide the implementation in Python. The object factory pattern is very useful for accessing these implementations from Java.

Jim Baker and Josh Juneau have a library over at Kenai that makes Jython object factories as easy as "new JythonObjectFactory(...);" (or something like that): http://kenai.com/projects/plyjy, I don't know if this is production ready yet, but you can at least look at their code to find out how to implement an object factory, it's less than a page of code (I've included the code in presentation slides from time to time).

So, a summary of the best way to use Python code from Java at the moment:

1. Define the interface(s) for the Python code in Java:
    package com.pany.package;
    public interface MyCodeThingy {
          String someMethod(int value);
    }

2. Implement the interface(s) in Python:
    from com.pany.package import MyCodeThingy
    class MyImplementation(MyCodeThingy):
        def __init__(self, prefix):
            self.prefix = prefix
        def someMethod(self, value):
            return "%s - %s" % (self.prefix, value) # Really advanced code - you could NEVER do this in Java

3. Instantiate an object factory for the Python code in Java:
    ObjectFactory<MyCodeThingy> codeThingyFactory = new JythonObjectFactory<>(...); // Not sure about the actual interface here

4. Use the object factory to create instances of your Python class in Java:
    String prefix = "The answer to the question about life, universe and everything";
    MyCodeThingy thing = codeThingyFactory.create(prefix);
    String result = thingy.someMethod(42);
    assert result.equals("The answer to the question about life, universe and everything - 42");

Jim, Josh - How close to being usable like this example is PlyJy at the moment?

Happy hacking,
Tobias


On Tue, Jul 21, 2009 at 12:53 PM, Gabriel Rossetti <gabriel.rossetti@arimaz.com> wrote:
Hello Tobias,

So if I understand it correctly there is currently no way to use python code in Java (since jythonc is gone and the current proposal not being implemented)?

Cheers,
Gabriel

Tobias Ivarsson wrote:
Hi Gabriel,

These are not examples of how to do it in the current Jython 2.5 release, but a suggestion for what this could could look like when the Jythonc replacement is done. The Jythonc replacement is still in an early draft stage and will likely be tentatively introduced in some 2.5.x release, we had originally planned to introduce a first version for people to play with in 2.5.1, but it is starting to look like we will have to push out 2.5.1 earlier than planned due to some recent bug fixes.

Cheers,
Tobias

On Tue, Jul 21, 2009 at 11:06 AM, Gabriel Rossetti <gabriel.rossetti@arimaz.com <mailto:gabriel.rossetti@arimaz.com>> wrote:

   Hello everyone,

   I instaled Jython 2.5 and tried the example on this page :
   http://wiki.python.org/jython/ReplaceJythonc and it doesn't work,
   I get :

   NameError: name 'javamethod' is not defined

   does anyone know how to fix this, I can't find much concerning this on
   google.

   Thank you,
   Gabriel

   ------------------------------------------------------------------------------
   Enter the BlackBerry Developer Challenge
   This is your chance to win up to $100,000 in prizes! For a limited
   time,
   vendors submitting new applications to BlackBerry App World(TM)
   will have
   the opportunity to enter the BlackBerry Developer Challenge. See
   full prize
   details at: http://p.sf.net/sfu/Challenge
   _______________________________________________
   Jython-users mailing list
   Jython-users@lists.sourceforge.net
   <mailto:Jython-users@lists.sourceforge.net>


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users