Results 1 to 5 of 5

Thread: bean definition using inline scripting languages?

  1. #1
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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 at 10:24 AM.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    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.


    Quote 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

  4. #4
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    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

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

    Default

    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.)
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  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
  •