You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Marc DeXeT (JIRA)" <co...@jakarta.apache.org> on 2005/01/11 18:38:16 UTC

[jira] Created: (JELLY-195) Janino compiler tag library

Janino compiler tag library
---------------------------

         Key: JELLY-195
         URL: http://issues.apache.org/jira/browse/JELLY-195
     Project: jelly
        Type: New Feature
  Components: submissions  
    Versions: 1.0    
    Reporter: Marc DeXeT


Janino is a pretty embedded compiler for run-time compilation purposes designed by Arno Unkrig under Apache License (<http://www.janino.net>).
It can be a very usefull tool to create java function, entry point (main), class and package on run time.
I would submit to jelly people a new jelly-tag library overview before getting in sandbox processus. This library implements janino compiler in jelly way.

Janino jelly-tag library implements compilation, class body and scriptlet like janino evaluator.

A - compilation

For exemple you can define classes like :

<compile var="janinoClassLoader">
<!-- java source code -->
  public class Item {
    private String name;
    private double price;
    			
    public void setName(String str) { this.name = str; }
    public String getName() { return this.name; }    			
    public void setPrice(double p) { 
           if ( p &gt; 0 ) {
                this.price = p; 
           }
    public double getPrice() {return this.price; }
}
</compile>
<j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/>
<j:set target="${customer}" property="name" value="Charles"/>

B - ClassBody -

<classBody var="clazz">
 import java.util.*;
		
 static private int a = 1;
 private int b = 2;
		
 public int func(int c, int d) { return func2(c, d); }

 private static int func2(int e, int f) {
		       return e * f;
 }   
</classBody>
    	
<j:useBean class="${clazz}" var="b"/>
<j:set var="result" value="${b.func(2,3)}"/>

C - scriptlet 
<script var="script" result="s" returnType="java.util.ArrayList" execute="true">
 <!-- define expected parameters -->
 <parameter name="a" type="java.lang.String"/>
 <parameter name="b" type="java.util.ArrayList"/>    		
    		
 <!-- pass argument reference -->
 <j:arg value="foo"/>
 <j:arg value="${l}"/>
    		
 <!-- java scrip itself -->
 import java.util.ArrayList;
 ArrayList list = new ArrayList();
 list.add(a);
 list.add(b);    		
 return list;
</script>

<evaluate script="${script}" result="myList">
  <j:arg value="item0"/>
  <j:arg value="item1"/>
</evaluate>

<j:forEach var="item" items=="${mylist}">...

D - compilation support - 

A light compilation log writer help you to get through compilation error

Exemple :
11 janv. 2005 18:21:51 org.apache.commons.jelly.janino.JaninoHelper throwDocumentedExcpetion
GRAVE: 0001:import java.util.fooArrayList;
0002:ArrayList list = new ArrayList();
---------------------^
Line 2, Column 17: Expression "ArrayList" is not a type
0003:list.add(a);
0004:list.add(b);
0005:return list;


E - Xml customizable bean definition - 
A lot of jelly-tag library can do a lot for bean definition.
In janino tag library, high customizable run time bean definition is a included :

Exemples :

    	<compile var="cl" mapName="classes" packageName="foo.test">
    		<class name="Human">
    			<property name="name"/>
    			<property name="age" type="int"/>
    		</class>    		
    		<class name="Customer" extends="Human">
    			<property name="society"/>
    		</class>
    	</compile>

generate simple beans.

But you can go further :

<classBody var="Person">
 <property name="name"/>
 <property name="forname"/>
 <property name="prefix"/>

 <property name="sex" setter="true" declaration="true">
   if ( string.equals("female") ) { 
     this.prefix = "Ms";
   } else {
     this.prefix = "Mr";
   }
  </property>
  <property name="sex" getter="true"/>

  
  <property name="clothing" getter="true" override="true" declaration="true">
    if ( this.prefix.equals("Ms") ) {
      return "wedding gown";
    } else {
      return "smoking";
    }				
  </property>
</classBody>

<j:useBean class ="${Person}" var="jane" name="Doo" forname="Jane" sex="female"/>
<j:useBean class ="${Person}" var="john" name="Doo" forname="John" sex="male"/>

<j:file var="gossip">
  ${john.prefix} ${john.forname} ${john.name} dressed in ${john.clothing} and 
  ${jane.prefix} ${jane.forname} ${jane.name} in ${jane.clothing} have enlighted this party !
</j:file>



F - of course you can use <compile> to load java class from a source file 
<compile var="cl" uri="./mySources.txt"/>


As I have said, this library is for jelly people interest evaluation. It's rather an alpha library, but I think it can be a great feature for more supple jelly scripting.

Thank for your time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (JELLY-195) Janino compiler tag library

Posted by "Marc DeXeT (JIRA)" <co...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/JELLY-195?page=history ]

Marc DeXeT updated JELLY-195:
-----------------------------

    Attachment: janino-alpha.2005.01.21.19h00.zip

New janino tag implementation. Reproduces jelly-tag bean suite test. Includes new (alpha) Design   framework to generate java structures (as classs, accessor, common method by familly (as List.add, List.remove or Map.put). This framework use new Pattern library ( alpha too).
Requirement to use this library :
junit-3.8.1.jar; commons-logging-1.0.3.jar;
commons-collections-3.1.jar;
commons-lang-2.0.jar;
commons-beanutils-1.7.0.jar;
janino-2.2.0.jar;
commons-jelly-1.0-RC2-SNAPSHOT.jar (patched with http://issues.apache.org/jira/browse/JELLY-196)
commons-jelly-tags-junit-1.0.jar;
jaxen-1.1-beta-2.jar;
commons-jexl-1.0.jar;
commons-jelly-tags-xmlunit-1.0.jar;
xmlunit-0.8.jar;
commons-jelly-tags-log-1.0.jar;
commons-jelly-tags-bean-1.0.jar.

Run unit following tests :
- src/test/org/apache/commons/jelly/janino/TestSuiteJaninoTag.java ( for basic janino tag library features).
- src/test/org/apache/commons/jelly/janino/designer/tag/TestDesignLibrary.java ( for java code generation ).
- src/test/org/apache/commons/jelly/janino/TestJSPLike.java ( for JSP-like jelly tag mixing inside java code)
- src/test/org/apache/commons/jelly/janino/TestSuiteBeanJanino.java ( show case reproducing jelly-tag bean test suite with java code generation and compilation)
- src/test/org/apache/commons/jelly/pattern/tag/TagLibraryTest.java( for pattern library framework ).


Added : a eclipse .classpath file 'myClasspathAtEclipseFormat.xml'

More pretty details furthermore.
It's a very very alpha library, but I think all raw stuff is here.

Thank for feedback.

> Janino compiler tag library
> ---------------------------
>
>          Key: JELLY-195
>          URL: http://issues.apache.org/jira/browse/JELLY-195
>      Project: jelly
>         Type: New Feature
>   Components: submissions
>     Versions: 1.0
>     Reporter: Marc DeXeT
>  Attachments: janino-0.0.zip, janino-alpha.2005.01.21.19h00.zip
>
> Janino is a pretty embedded compiler for run-time compilation purposes designed by Arno Unkrig under Apache License (<http://www.janino.net>).
> It can be a very usefull tool to create java function, entry point (main), class and package on run time.
> I would submit to jelly people a new jelly-tag library overview before getting in sandbox processus. This library implements janino compiler in jelly way.
> Janino jelly-tag library implements compilation, class body and scriptlet like janino evaluator.
> A - compilation
> For exemple you can define classes like :
> <compile var="janinoClassLoader">
> <!-- java source code -->
>   public class Item {
>     private String name;
>     private double price;
>     			
>     public void setName(String str) { this.name = str; }
>     public String getName() { return this.name; }    			
>     public void setPrice(double p) { 
>            if ( p &gt; 0 ) {
>                 this.price = p; 
>            }
>     public double getPrice() {return this.price; }
> }
> </compile>
> <j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/>
> <j:set target="${customer}" property="name" value="Charles"/>
> B - ClassBody -
> <classBody var="clazz">
>  import java.util.*;
> 		
>  static private int a = 1;
>  private int b = 2;
> 		
>  public int func(int c, int d) { return func2(c, d); }
>  private static int func2(int e, int f) {
> 		       return e * f;
>  }   
> </classBody>
>     	
> <j:useBean class="${clazz}" var="b"/>
> <j:set var="result" value="${b.func(2,3)}"/>
> C - scriptlet 
> <script var="script" result="s" returnType="java.util.ArrayList" execute="true">
>  <!-- define expected parameters -->
>  <parameter name="a" type="java.lang.String"/>
>  <parameter name="b" type="java.util.ArrayList"/>    		
>     		
>  <!-- pass argument reference -->
>  <j:arg value="foo"/>
>  <j:arg value="${l}"/>
>     		
>  <!-- java scrip itself -->
>  import java.util.ArrayList;
>  ArrayList list = new ArrayList();
>  list.add(a);
>  list.add(b);    		
>  return list;
> </script>
> <evaluate script="${script}" result="myList">
>   <j:arg value="item0"/>
>   <j:arg value="item1"/>
> </evaluate>
> <j:forEach var="item" items=="${mylist}">...
> D - compilation support - 
> A light compilation log writer help you to get through compilation error
> Exemple :
> 11 janv. 2005 18:21:51 org.apache.commons.jelly.janino.JaninoHelper throwDocumentedExcpetion
> GRAVE: 0001:import java.util.fooArrayList;
> 0002:ArrayList list = new ArrayList();
> ---------------------^
> Line 2, Column 17: Expression "ArrayList" is not a type
> 0003:list.add(a);
> 0004:list.add(b);
> 0005:return list;
> E - Xml customizable bean definition - 
> A lot of jelly-tag library can do a lot for bean definition.
> In janino tag library, high customizable run time bean definition is a included :
> Exemples :
>     	<compile var="cl" mapName="classes" packageName="foo.test">
>     		<class name="Human">
>     			<property name="name"/>
>     			<property name="age" type="int"/>
>     		</class>    		
>     		<class name="Customer" extends="Human">
>     			<property name="society"/>
>     		</class>
>     	</compile>
> generate simple beans.
> But you can go further :
> <classBody var="Person">
>  <property name="name"/>
>  <property name="forname"/>
>  <property name="prefix"/>
>  <property name="sex" setter="true" declaration="true">
>    if ( string.equals("female") ) { 
>      this.prefix = "Ms";
>    } else {
>      this.prefix = "Mr";
>    }
>   </property>
>   <property name="sex" getter="true"/>
>   
>   <property name="clothing" getter="true" override="true" declaration="true">
>     if ( this.prefix.equals("Ms") ) {
>       return "wedding gown";
>     } else {
>       return "smoking";
>     }				
>   </property>
> </classBody>
> <j:useBean class ="${Person}" var="jane" name="Doo" forname="Jane" sex="female"/>
> <j:useBean class ="${Person}" var="john" name="Doo" forname="John" sex="male"/>
> <j:file var="gossip">
>   ${john.prefix} ${john.forname} ${john.name} dressed in ${john.clothing} and 
>   ${jane.prefix} ${jane.forname} ${jane.name} in ${jane.clothing} have enlighted this party !
> </j:file>
> F - of course you can use <compile> to load java class from a source file 
> <compile var="cl" uri="./mySources.txt"/>
> As I have said, this library is for jelly people interest evaluation. It's rather an alpha library, but I think it can be a great feature for more supple jelly scripting.
> Thank for your time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (JELLY-195) Janino compiler tag library

Posted by "Marc DeXeT (JIRA)" <co...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/JELLY-195?page=comments#action_57568 ]
     
Marc DeXeT commented on JELLY-195:
----------------------------------

Jelly needs JSP processing java block instruction scriptlet-like mixed XML and java code.

			<%  for (int i=0; i < 2; i++) { %>
				     <content>
				       <some/><xml/><elements/>
				     </content>
                         <% } %>


can be written as :

			<ja:script execute="true">
				  for (int i=0; i &lt; 2; i++) {
				   <ja:do>
				     <content>
				       <some/><xml/><elements/>
				     </content>
				    </ja:do>
				}
			</ja:script>


This new Feature in janino tag library is added.

Next Unit test is running OK :

<xu:assertDocumentsEqual>
    <xu:actual>
        <ROOT>
            <ja:script execute="true">
                for (int i=0; i &lt; 2; i++) {
               <ja:do>
                 <content>
                    <some/><xml/><elements/>
                 </content>
              </ja:do>
              }
         </ja:script>
     </ROOT>
   </xu:actual>
   <xu:expected>
   <ROOT>
         <content>
              <some/><xml/><elements/>
          </content>
          <content>
              <some/><xml/><elements/>
          </content>
     </ROOT>
  </xu:expected>
</xu:assertDocumentsEqual>

PS : Jar file will be attached after light cleaning tomorrow (  01 AM it's too late )




> Janino compiler tag library
> ---------------------------
>
>          Key: JELLY-195
>          URL: http://issues.apache.org/jira/browse/JELLY-195
>      Project: jelly
>         Type: New Feature
>   Components: submissions
>     Versions: 1.0
>     Reporter: Marc DeXeT
>  Attachments: janino-0.0.zip
>
> Janino is a pretty embedded compiler for run-time compilation purposes designed by Arno Unkrig under Apache License (<http://www.janino.net>).
> It can be a very usefull tool to create java function, entry point (main), class and package on run time.
> I would submit to jelly people a new jelly-tag library overview before getting in sandbox processus. This library implements janino compiler in jelly way.
> Janino jelly-tag library implements compilation, class body and scriptlet like janino evaluator.
> A - compilation
> For exemple you can define classes like :
> <compile var="janinoClassLoader">
> <!-- java source code -->
>   public class Item {
>     private String name;
>     private double price;
>     			
>     public void setName(String str) { this.name = str; }
>     public String getName() { return this.name; }    			
>     public void setPrice(double p) { 
>            if ( p &gt; 0 ) {
>                 this.price = p; 
>            }
>     public double getPrice() {return this.price; }
> }
> </compile>
> <j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/>
> <j:set target="${customer}" property="name" value="Charles"/>
> B - ClassBody -
> <classBody var="clazz">
>  import java.util.*;
> 		
>  static private int a = 1;
>  private int b = 2;
> 		
>  public int func(int c, int d) { return func2(c, d); }
>  private static int func2(int e, int f) {
> 		       return e * f;
>  }   
> </classBody>
>     	
> <j:useBean class="${clazz}" var="b"/>
> <j:set var="result" value="${b.func(2,3)}"/>
> C - scriptlet 
> <script var="script" result="s" returnType="java.util.ArrayList" execute="true">
>  <!-- define expected parameters -->
>  <parameter name="a" type="java.lang.String"/>
>  <parameter name="b" type="java.util.ArrayList"/>    		
>     		
>  <!-- pass argument reference -->
>  <j:arg value="foo"/>
>  <j:arg value="${l}"/>
>     		
>  <!-- java scrip itself -->
>  import java.util.ArrayList;
>  ArrayList list = new ArrayList();
>  list.add(a);
>  list.add(b);    		
>  return list;
> </script>
> <evaluate script="${script}" result="myList">
>   <j:arg value="item0"/>
>   <j:arg value="item1"/>
> </evaluate>
> <j:forEach var="item" items=="${mylist}">...
> D - compilation support - 
> A light compilation log writer help you to get through compilation error
> Exemple :
> 11 janv. 2005 18:21:51 org.apache.commons.jelly.janino.JaninoHelper throwDocumentedExcpetion
> GRAVE: 0001:import java.util.fooArrayList;
> 0002:ArrayList list = new ArrayList();
> ---------------------^
> Line 2, Column 17: Expression "ArrayList" is not a type
> 0003:list.add(a);
> 0004:list.add(b);
> 0005:return list;
> E - Xml customizable bean definition - 
> A lot of jelly-tag library can do a lot for bean definition.
> In janino tag library, high customizable run time bean definition is a included :
> Exemples :
>     	<compile var="cl" mapName="classes" packageName="foo.test">
>     		<class name="Human">
>     			<property name="name"/>
>     			<property name="age" type="int"/>
>     		</class>    		
>     		<class name="Customer" extends="Human">
>     			<property name="society"/>
>     		</class>
>     	</compile>
> generate simple beans.
> But you can go further :
> <classBody var="Person">
>  <property name="name"/>
>  <property name="forname"/>
>  <property name="prefix"/>
>  <property name="sex" setter="true" declaration="true">
>    if ( string.equals("female") ) { 
>      this.prefix = "Ms";
>    } else {
>      this.prefix = "Mr";
>    }
>   </property>
>   <property name="sex" getter="true"/>
>   
>   <property name="clothing" getter="true" override="true" declaration="true">
>     if ( this.prefix.equals("Ms") ) {
>       return "wedding gown";
>     } else {
>       return "smoking";
>     }				
>   </property>
> </classBody>
> <j:useBean class ="${Person}" var="jane" name="Doo" forname="Jane" sex="female"/>
> <j:useBean class ="${Person}" var="john" name="Doo" forname="John" sex="male"/>
> <j:file var="gossip">
>   ${john.prefix} ${john.forname} ${john.name} dressed in ${john.clothing} and 
>   ${jane.prefix} ${jane.forname} ${jane.name} in ${jane.clothing} have enlighted this party !
> </j:file>
> F - of course you can use <compile> to load java class from a source file 
> <compile var="cl" uri="./mySources.txt"/>
> As I have said, this library is for jelly people interest evaluation. It's rather an alpha library, but I think it can be a great feature for more supple jelly scripting.
> Thank for your time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (JELLY-195) Janino compiler tag library

Posted by "Marc DeXeT (JIRA)" <co...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/JELLY-195?page=comments#action_57522 ]
     
Marc DeXeT commented on JELLY-195:
----------------------------------

Correction to message :
It is :

<compile var="janinoClassLoader">
<!-- java source code -->
>>>>>>>>>>>>>>  package foo.Test; <<<<<<<<<<<<<<<<<<<

  public class Item {
    private String name;
    private double price;
    			
    public void setName(String str) { this.name = str; }
    public String getName() { return this.name; }    			
    public void setPrice(double p) { 
           if ( p &gt; 0 ) {
                this.price = p; 
           }
    public double getPrice() {return this.price; }
}
</compile>
<j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/> <j:set target="${customer}" property="name" value="Charles"/>


> Janino compiler tag library
> ---------------------------
>
>          Key: JELLY-195
>          URL: http://issues.apache.org/jira/browse/JELLY-195
>      Project: jelly
>         Type: New Feature
>   Components: submissions
>     Versions: 1.0
>     Reporter: Marc DeXeT
>  Attachments: janino-0.0.zip
>
> Janino is a pretty embedded compiler for run-time compilation purposes designed by Arno Unkrig under Apache License (<http://www.janino.net>).
> It can be a very usefull tool to create java function, entry point (main), class and package on run time.
> I would submit to jelly people a new jelly-tag library overview before getting in sandbox processus. This library implements janino compiler in jelly way.
> Janino jelly-tag library implements compilation, class body and scriptlet like janino evaluator.
> A - compilation
> For exemple you can define classes like :
> <compile var="janinoClassLoader">
> <!-- java source code -->
>   public class Item {
>     private String name;
>     private double price;
>     			
>     public void setName(String str) { this.name = str; }
>     public String getName() { return this.name; }    			
>     public void setPrice(double p) { 
>            if ( p &gt; 0 ) {
>                 this.price = p; 
>            }
>     public double getPrice() {return this.price; }
> }
> </compile>
> <j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/>
> <j:set target="${customer}" property="name" value="Charles"/>
> B - ClassBody -
> <classBody var="clazz">
>  import java.util.*;
> 		
>  static private int a = 1;
>  private int b = 2;
> 		
>  public int func(int c, int d) { return func2(c, d); }
>  private static int func2(int e, int f) {
> 		       return e * f;
>  }   
> </classBody>
>     	
> <j:useBean class="${clazz}" var="b"/>
> <j:set var="result" value="${b.func(2,3)}"/>
> C - scriptlet 
> <script var="script" result="s" returnType="java.util.ArrayList" execute="true">
>  <!-- define expected parameters -->
>  <parameter name="a" type="java.lang.String"/>
>  <parameter name="b" type="java.util.ArrayList"/>    		
>     		
>  <!-- pass argument reference -->
>  <j:arg value="foo"/>
>  <j:arg value="${l}"/>
>     		
>  <!-- java scrip itself -->
>  import java.util.ArrayList;
>  ArrayList list = new ArrayList();
>  list.add(a);
>  list.add(b);    		
>  return list;
> </script>
> <evaluate script="${script}" result="myList">
>   <j:arg value="item0"/>
>   <j:arg value="item1"/>
> </evaluate>
> <j:forEach var="item" items=="${mylist}">...
> D - compilation support - 
> A light compilation log writer help you to get through compilation error
> Exemple :
> 11 janv. 2005 18:21:51 org.apache.commons.jelly.janino.JaninoHelper throwDocumentedExcpetion
> GRAVE: 0001:import java.util.fooArrayList;
> 0002:ArrayList list = new ArrayList();
> ---------------------^
> Line 2, Column 17: Expression "ArrayList" is not a type
> 0003:list.add(a);
> 0004:list.add(b);
> 0005:return list;
> E - Xml customizable bean definition - 
> A lot of jelly-tag library can do a lot for bean definition.
> In janino tag library, high customizable run time bean definition is a included :
> Exemples :
>     	<compile var="cl" mapName="classes" packageName="foo.test">
>     		<class name="Human">
>     			<property name="name"/>
>     			<property name="age" type="int"/>
>     		</class>    		
>     		<class name="Customer" extends="Human">
>     			<property name="society"/>
>     		</class>
>     	</compile>
> generate simple beans.
> But you can go further :
> <classBody var="Person">
>  <property name="name"/>
>  <property name="forname"/>
>  <property name="prefix"/>
>  <property name="sex" setter="true" declaration="true">
>    if ( string.equals("female") ) { 
>      this.prefix = "Ms";
>    } else {
>      this.prefix = "Mr";
>    }
>   </property>
>   <property name="sex" getter="true"/>
>   
>   <property name="clothing" getter="true" override="true" declaration="true">
>     if ( this.prefix.equals("Ms") ) {
>       return "wedding gown";
>     } else {
>       return "smoking";
>     }				
>   </property>
> </classBody>
> <j:useBean class ="${Person}" var="jane" name="Doo" forname="Jane" sex="female"/>
> <j:useBean class ="${Person}" var="john" name="Doo" forname="John" sex="male"/>
> <j:file var="gossip">
>   ${john.prefix} ${john.forname} ${john.name} dressed in ${john.clothing} and 
>   ${jane.prefix} ${jane.forname} ${jane.name} in ${jane.clothing} have enlighted this party !
> </j:file>
> F - of course you can use <compile> to load java class from a source file 
> <compile var="cl" uri="./mySources.txt"/>
> As I have said, this library is for jelly people interest evaluation. It's rather an alpha library, but I think it can be a great feature for more supple jelly scripting.
> Thank for your time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (JELLY-195) Janino compiler tag library

Posted by "Marc DeXeT (JIRA)" <co...@jakarta.apache.org>.
     [ http://issues.apache.org/jira/browse/JELLY-195?page=history ]

Marc DeXeT updated JELLY-195:
-----------------------------

    Attachment: janino-0.0.zip

Source and unit tests.
You can get janino library at http://www.janino.net/download/janino-2.2.0.zip
IMPORTANT : note you need BeanUtils version 1.7.0 or upper !!

> Janino compiler tag library
> ---------------------------
>
>          Key: JELLY-195
>          URL: http://issues.apache.org/jira/browse/JELLY-195
>      Project: jelly
>         Type: New Feature
>   Components: submissions
>     Versions: 1.0
>     Reporter: Marc DeXeT
>  Attachments: janino-0.0.zip
>
> Janino is a pretty embedded compiler for run-time compilation purposes designed by Arno Unkrig under Apache License (<http://www.janino.net>).
> It can be a very usefull tool to create java function, entry point (main), class and package on run time.
> I would submit to jelly people a new jelly-tag library overview before getting in sandbox processus. This library implements janino compiler in jelly way.
> Janino jelly-tag library implements compilation, class body and scriptlet like janino evaluator.
> A - compilation
> For exemple you can define classes like :
> <compile var="janinoClassLoader">
> <!-- java source code -->
>   public class Item {
>     private String name;
>     private double price;
>     			
>     public void setName(String str) { this.name = str; }
>     public String getName() { return this.name; }    			
>     public void setPrice(double p) { 
>            if ( p &gt; 0 ) {
>                 this.price = p; 
>            }
>     public double getPrice() {return this.price; }
> }
> </compile>
> <j:new classLoader="${cl}" className="foo.test.Customer" var="customer"/>
> <j:set target="${customer}" property="name" value="Charles"/>
> B - ClassBody -
> <classBody var="clazz">
>  import java.util.*;
> 		
>  static private int a = 1;
>  private int b = 2;
> 		
>  public int func(int c, int d) { return func2(c, d); }
>  private static int func2(int e, int f) {
> 		       return e * f;
>  }   
> </classBody>
>     	
> <j:useBean class="${clazz}" var="b"/>
> <j:set var="result" value="${b.func(2,3)}"/>
> C - scriptlet 
> <script var="script" result="s" returnType="java.util.ArrayList" execute="true">
>  <!-- define expected parameters -->
>  <parameter name="a" type="java.lang.String"/>
>  <parameter name="b" type="java.util.ArrayList"/>    		
>     		
>  <!-- pass argument reference -->
>  <j:arg value="foo"/>
>  <j:arg value="${l}"/>
>     		
>  <!-- java scrip itself -->
>  import java.util.ArrayList;
>  ArrayList list = new ArrayList();
>  list.add(a);
>  list.add(b);    		
>  return list;
> </script>
> <evaluate script="${script}" result="myList">
>   <j:arg value="item0"/>
>   <j:arg value="item1"/>
> </evaluate>
> <j:forEach var="item" items=="${mylist}">...
> D - compilation support - 
> A light compilation log writer help you to get through compilation error
> Exemple :
> 11 janv. 2005 18:21:51 org.apache.commons.jelly.janino.JaninoHelper throwDocumentedExcpetion
> GRAVE: 0001:import java.util.fooArrayList;
> 0002:ArrayList list = new ArrayList();
> ---------------------^
> Line 2, Column 17: Expression "ArrayList" is not a type
> 0003:list.add(a);
> 0004:list.add(b);
> 0005:return list;
> E - Xml customizable bean definition - 
> A lot of jelly-tag library can do a lot for bean definition.
> In janino tag library, high customizable run time bean definition is a included :
> Exemples :
>     	<compile var="cl" mapName="classes" packageName="foo.test">
>     		<class name="Human">
>     			<property name="name"/>
>     			<property name="age" type="int"/>
>     		</class>    		
>     		<class name="Customer" extends="Human">
>     			<property name="society"/>
>     		</class>
>     	</compile>
> generate simple beans.
> But you can go further :
> <classBody var="Person">
>  <property name="name"/>
>  <property name="forname"/>
>  <property name="prefix"/>
>  <property name="sex" setter="true" declaration="true">
>    if ( string.equals("female") ) { 
>      this.prefix = "Ms";
>    } else {
>      this.prefix = "Mr";
>    }
>   </property>
>   <property name="sex" getter="true"/>
>   
>   <property name="clothing" getter="true" override="true" declaration="true">
>     if ( this.prefix.equals("Ms") ) {
>       return "wedding gown";
>     } else {
>       return "smoking";
>     }				
>   </property>
> </classBody>
> <j:useBean class ="${Person}" var="jane" name="Doo" forname="Jane" sex="female"/>
> <j:useBean class ="${Person}" var="john" name="Doo" forname="John" sex="male"/>
> <j:file var="gossip">
>   ${john.prefix} ${john.forname} ${john.name} dressed in ${john.clothing} and 
>   ${jane.prefix} ${jane.forname} ${jane.name} in ${jane.clothing} have enlighted this party !
> </j:file>
> F - of course you can use <compile> to load java class from a source file 
> <compile var="cl" uri="./mySources.txt"/>
> As I have said, this library is for jelly people interest evaluation. It's rather an alpha library, but I think it can be a great feature for more supple jelly scripting.
> Thank for your time.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org