You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2002/12/07 19:54:01 UTC

Implementing my project in Jelly.

Here's my project (currently being developed in Ant).

I have a set of tasks that map to a set of classes available in a 
package used for random number generation.

For example

"cern.jet.random.Uniform.java"

gets wrapped by

"org.mrd.ant.distributions.Uniform.java"

so that a Uniform random number generator gets created and the value of 
uniform.nextDouble() gets loaded into the Ant project properties.

project.setProperty(this.getName(), Double.toString(uniform.nextDouble()));

This gets used in an ant script like this:


<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="pva_analysis" name="PVA Batch Example">
         <taskdef name="uniform" 
classname="org.mrd.ant.distributions.Uniform">
	...
	</taskdef>

	<target name="xxx">
	   <batch ...>
		<uniform name="rngSeed" min="0"/>
	...

which sets a property in the project (I built a batch task that 
basically is a for-loop to increment this value).



My reasons for wanting to move to Jelly are that I actually want to make 
the random number generator itself available in the project and be able 
to draw random numbers from it more like this:

<j:jelly xmlns:j="jelly:core" 
xmlns:dist="jelly:org.mrd.ant.distributions.MyTagLibrary">

   <dist:uniform name="rngSeed" min="0"/>

   <j:set var="cnt1" value="0"/>
   <j:while test="${cnt1 != 5}">
        <j:set var="cnt1" value="${cnt1 + 1}"/>
        <foo:simulation seed="${rngSeed.nextDouble()}">
   	   ...
        </foo:simulation>
   </j:while>

</j:jelly>

I see an example of this in the swing demo, but what I also see is that 
the name of the bean is also the name of the tag.

<frame title="This...">
...
</frame>

${frame.show()}

instead of an attribute value (which is what I'm trying to do).

<dist:uniform name="rngSeed" min="0"/>

${rngSeed.nextDouble()}


My question is: Is this possible?

Also, I notice that the SwingTagLibrary uses a Bean Factory to create 
the "frame" class behind the frame tag using these methods...

     /**
      * Register a widget factory for the given element name
      */
     protected void registerFactory(String name, Factory factory) {
         getFactoryMap().put(name, factory);
     }

     /**
      * Register a bean factory for the given element name and class
      */
     protected void registerBeanFactory(String name, Class beanClass) {
         registerFactory(name, new BeanFactory(beanClass));
     }

How does the "frame" get made available in the script?

-Mark




Re: Implementing my project in Jelly.

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Paul Libbrecht wrote:
> Mark,
> 
> 
> On Samedi, décembre 7, 2002, at 07:54 , Mark R. Diggory wrote:
> 
>> I see an example of this in the swing demo, but what I also see is 
>> that the name of the bean is also the name of the tag.
>> <frame title="This..."></frame>
>> ${frame.show()}
>> instead of an attribute value (which is what I'm trying to do).
> 
> 
> "frame" in the ${} expression is the name of the variable as declared by 
> the value of the var attribute...
> 
> Paul
> 

Thanks. Caught that after some rooting around in some examples in the 
source.

-Mark


Re: Implementing my project in Jelly.

Posted by Paul Libbrecht <pa...@activemath.org>.
Mark,


On Samedi, décembre 7, 2002, at 07:54 , Mark R. Diggory wrote:

> I see an example of this in the swing demo, but what I also see is that 
> the name of the bean is also the name of the tag.
> <frame title="This..."></frame>
> ${frame.show()}
> instead of an attribute value (which is what I'm trying to do).

"frame" in the ${} expression is the name of the variable as declared by 
the value of the var attribute...

Paul