Announcement Announcement Module
Collapse
No announcement yet.
bean definition using inline scripting languages? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • bean definition using inline scripting languages?

    Probably a bad idea (or again its in Spring already!) but ....

    For diagnostics I created a simple bean that announced its construction
    and property setting very loudly ( a banner in the log file).

    But, despite the other methods of accomplishing this, like tailing the log
    file and redirecting to a grep or using a debugger, this leads to:
    why even have to create these temporary or minor classes?

    What if a bean definition could be implemented inline right in the bean
    descriptor? Sounds horrible, I know. But this is not like Jelly, an XML language, rather its
    just a conveniant well-known approach (very easy to misuse too). Ant and Maven, for example,
    already allow scripting.

    This could be used with AOP, inserting advise via scripting.

    The above creation of a throwaway POJO would be a no brainer. The script
    could be in any script language but the default is a scripted Java syntax
    (there are many Java script compilers such as BeanShell or Janino).
    See http://www.janino.net and http://www.beanshell.org

    Thus a possible bean definition could be:
    Code:
    <bean id="shouter">
       <property name="msg"><value>Hello world!</value></property>
       
       <package>com.........util</package> <!-- optional? -->
    	
       <script language="beanshell"> <!-- or jython,Groovy,Janino,Rhino -->
         <!&#91;CDATA&#91;
            	public class Shout &#123;
            	        protected String msg;
                            //  stuff snipped .....
              	&#125;	
         &#93;&#93;>
       </script>
    </bean>
    -- J. Betancourt

  • #2
    Spring already (in sandbox) supports using beans created with Groovy. You can use Spring intergaration for Groovy as it is, or make some changes to support inline scripts.
    More scripting languages are to be added Jython bean factory
    Last edited by Rod Johnson; Jan 18th, 2006, 11:24 AM.

    Comment


    • #3
      Yes, I saw that there is now support for scripting in Spring,
      in package org.springframework.beans.factory.script. I guess this is the SPI? I wonder if BSF is applicable here to support any language. See
      http://jakarta.apache.org/bsf/

      If I have time I will see how to add a beanShell or Janino implementation also.

      I also mentioned the idea of inline scripting to see if there are any real strong reasons not to have such a capability. But, I guess if someone needs it, why not.


      Originally posted by irbouho
      Spring already (in sandbox) supports using beans created with Groovy. You can use Spring intergaration for Groovy as it is, or make some changes to support inline scripts.
      More scripting languages are to be added Jython bean factory

      Comment


      • #4
        fyi: The JSR 223: Scripting Pages in JavaTM Web Applications

        Is now in early draft review. The title is a little misleading, it started out that way, but now seems to cover scripting in Java in general.

        Link: http://jcp.org/en/jsr/detail?id=223

        Comment


        • #5
          Have you checked out the current scripting support in the sandbox. Supports Groovy and Beanshell and it would be easy to support other languages.

          I've looked at BSF but I'm not convinced in adds that much value here. There is also a pretty clear way to support arbitrary languages in Spring's support, more customized for the needs of DI. (Scripts configured via DI and other objects depending on them.)

          Comment

          Working...
          X