Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Jython bean factory?

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Hollis, NH, US
    Posts
    4

    Default Jython bean factory?

    I see the thread about Groovy integration. Has anyone worked on a Jython version of this? I would like to be able to configure Jython beans from Spring.

    Preferably the JythonFactory would understand Jython introspection so the bean would not have to implement an interface in order to be configurable from Spring.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Currently it assumes that the script can implement one or more interfaces, or be cast to an interface (in the case of Beanshell, where it may not formally implement the interface).

    The approach is pretty flexible, so I would like to know more about the capabilities of Jython in this respect. It would be great to be able to support Jython in 1.2 also.

    I did have a quick look at Jython material when working on it a few weeks ago, but I haven't used Jython before and didn't have enough time to really get into it.

    R

  3. #3
    Join Date
    Aug 2004
    Location
    Hollis, NH, US
    Posts
    4

    Default

    Jython classes can implement Java interfaces, so the current approach would work. It is more restrictive than I would like, though.

    There are two aspects to this - the interface the Jython bean presents to the BeanFactory (the setters that are configured by Spring) and the interface the bean presents to clients.

    In the first case, it would be very nice if the Jython bean did not have to present a Java interface for Spring to be able to set properties on it. This requires that the Spring factory class understands how to use Jython's introspection. This is not hard to do with the Jython api, it is just different from native Java introspection.

    In the second case, if the bean is going to be given to Java clients, it will have to implement a Java interface. If it is going to be given to Jython clients, no interface is needed. I'm not sure if Spring needs to care about this at all?

  4. #4
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Yes, I don't thing that Spring needs to worry about the second case. The aim of this mechanism is to provide beans actually written in a scripting language so that they look like Java objects to beans that depends on them,

    The first case: using Jython introspection, might need to be handled in the core IoC container. However, a relatively simple extensibility mechanism could provide this.

    If you are interesting in contributing a JythonScript and JythonScriptFactory implementation (initially not supporting DI for except by Java properties) I'll look at the issues with Jython introspection when I get time.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  5. #5
    Join Date
    Aug 2004
    Location
    Hollis, NH, US
    Posts
    4

    Default

    I'll give it a try.

  6. #6
    Join Date
    Aug 2004
    Location
    Hollis, NH, US
    Posts
    4

    Default

    I have successfully made JythonFactory and JythonScript classes by cloning GroovyFactory and GroovyScript. I also cloned the Groovy unit tests and accompanying scripts. The tests all pass.

    Setter injection is extremely awkward for Jython scripts. To get the propertySingleton and propertyPrototype beans to work, I had to define a Message interface (containing setMessage() and getMessage() methods) and have PropertyHello implement Message. This is because Jython methods are not visible to Java introspection unless they are implementing a Java interface.

    So, although the code is working, I don't think it is usable in its present form. It's a bit much to expect that beans implement interfaces for their configuration methods. If the IoC container could be extended to use Jython introspection this would be much more usable.

    The classes depend on jython.jar in your classpath, and the Jython Lib directory in the same directory as jython.jar.

    Where should I go from here? How can I contribute the code?

    Kent

  7. #7
    Join Date
    Aug 2004
    Posts
    1

    Default

    This may also be of interest:
    http://jdocs.com/cglib/2.0.2/api/net...faceMaker.html

    Chris

  8. #8
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Kent

    I'd be interested to see the Jython introspection code. Please email it to me. I'll think about whether the core container could be opened up a little to allow non-Java reflection population strategies.

    Rgds
    Rod
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  9. #9
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Chris

    Thanks--InterfaceMaker is cool. I've just used it to create a config interface with the necessary setters for any bean definitions for BeanShell. The code is generic, and should work with other scripting languages also. With Groovy it's not necessary, as the Groovy class will actually implement the setters, but of course with BeanShell you just get a dynamic proxy.

    Rgds
    Rod
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  10. #10
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Just doing a ping on this topic. Would it be possible to get a copy of the Jython integration code? Any chance it could get committed to the sandbox?

    Our beanshell code is working great, and would love to compare to the Jython code.

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •