commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc DeXeT (JIRA)" <>
Subject [jira] Created: (JELLY-195) Janino compiler tag library
Date Tue, 11 Jan 2005 17:38:16 GMT
Janino compiler tag library

         Key: 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 (<>).
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) { = str; }
    public String getName() { return; }    			
    public void setPrice(double p) { 
           if ( p &gt; 0 ) {
                this.price = p; 
    public double getPrice() {return this.price; }
<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;
<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();
 return list;

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

<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
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 name="Customer" extends="Human">
    			<property name="society"/>

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 name="sex" getter="true"/>

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

<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} ${} dressed in ${} and 
  ${jane.prefix} ${jane.forname} ${} in ${} have enlighted this party

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:
If you want more information on JIRA, or have a bug to report see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message