Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
added jython scripting support to spring
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Coppola  
View profile  
 More options Mar 18 2007, 2:14 pm
From: "John Coppola" <johnny...@gmail.com>
Date: Sun, 18 Mar 2007 14:14:59 -0400
Local: Sun, Mar 18 2007 2:14 pm
Subject: [Springframework-developer] added jython scripting support to spring
I felt it was important to add jython support since the python
following is still strong.

Also looks like the jython project is becoming more active with
ambitions to sync up to the latest version of c python.

i still like python... call me old school.

so anyway this is what I did:

I created an extension to the spring-lang-2.0.xsd:

        <xsd:element name="jython" type="dynamicScriptType">
                <xsd:annotation>
                        <xsd:documentation><![CDATA[
        A Spring bean backed by a Jython class definition.
                        ]]></xsd:documentation>
                </xsd:annotation>
        </xsd:element>

Then added a package org.springframework.scripting.jython with the
following sources added: JythonScriptFactory.java

In "getScriptedObject" perform the following:

        public Object getScriptedObject(ScriptSource actualScriptSource,
Class[] actualInterfaces)
                        throws IOException, ScriptCompilationException {
                try {
                        PythonInterpreter.initialize(System.getProperties(),null, new String[] {});
                        PythonInterpreter interpreter = new PythonInterpreter();
                        interpreter.exec(actualScriptSource.getScriptAsString());
                        PyStringMap locals = (PyStringMap) interpreter.getLocals();
                        PyList list = locals.values();
                        PyClass clazz = null;
                        for (int i=0; i < list.__len__(); i++) {
                                PyObject py = list.__getitem__(i);
                                if ((py instanceof PyClass) && !(py instanceof PyJavaClass)) {
                                        if (clazz != null) throw new PyException(new PyString("multiple
python class declarations present"));
                                        clazz = (PyClass) py;
                                }
                        }
                        PyInstance instance = (PyInstance) clazz.__call__();
                        return instance.__tojava__(actualInterfaces[0]);
                }
                catch (PyException ex) {
                        throw new ScriptCompilationException("Could not compile Jython
script: " + actualScriptSource, ex);
                }
        }

This is just a POC.  It would be nice if we could specify the class
name as part of the ScriptSource object so we don't have to guess
which in the locals namespace class we are interested in.

Also in the org.springframework.scripting.config.LangNamespaceHandler
I add to the init method:

                if (ClassUtils.isPresent("org.python.core.PyObject")) {
                        registerBeanDefinitionParser("jython", new
ScriptBeanDefinitionParser(JythonScriptFactory.class));
                }

So here is an excerpt from a beans file:

        <bean id="SPAM" class="jcoppola.atsi.application.SetRunnableTest">
                <property name="runnable" ref="runnable1"/>
        </bean>

        <bean id="EGGS" class="jcoppola.atsi.application.SetRunnableTest">
                <property name="runnable" ref="runnable2"/>
        </bean>

        <lang:jython id="runnable1" script-interfaces="java.lang.Runnable">
                <lang:inline-script>
from java.lang import Runnable

class JythonRunnable(Runnable):
        def __init__(self):
                print "__init__: JythonRunnable1"
        def run(self):
                print "run: JythonRunnable1"                          
                </lang:inline-script>
        </lang:jython>

        <lang:jython id="runnable2" script-interfaces="java.lang.Runnable">
                <lang:inline-script>
from java.lang import Runnable

class JythonRunnable(Runnable):
        def __init__(self):
                print "__init__: JythonRunnable2"
        def run(self):
                print "run: JythonRunnable2"                          
                </lang:inline-script>
        </lang:jython>

I'll provide a patch if this gains traction.

Cheers,
John Coppola

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DE...
_______________________________________________
Springframework-developer mailing list
Springframework-develo...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/springframework-developer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ja...@tikalsky.com  
View profile  
 More options Mar 18 2007, 10:45 pm
From: ja...@tikalsky.com
Date: Sun, 18 Mar 2007 21:45:42 -0500 (CDT)
Local: Sun, Mar 18 2007 10:45 pm
Subject: Re: [Springframework-developer] added jython scripting support to spring
Hi John,

I haven't had a chance to play with your code yet. Have you seen this
version by Yan Weng?:
http://yanweng.blogspot.com/2006/02/prototype-of-jython-scriptfactory...

James Tikalsky

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DE...
_______________________________________________
Springframework-developer mailing list
Springframework-develo...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/springframework-developer

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »