commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc DeXeT (JIRA)" <commons-...@jakarta.apache.org>
Subject [jira] Updated: (JELLY-195) Janino compiler tag library
Date Tue, 11 Jan 2005 18:11:13 GMT
     [ 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


Mime
View raw message