commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: [Jelly] Creating Classes
Date Tue, 14 Jan 2003 15:41:52 GMT
From: "Mark R. Diggory" <>
> James Strachan wrote:
> > From: "Mark R. Diggory" <>
> >
> >>The struggle I have is that the new class/object needs to be
> >>introspectable using native java.lang.reflection utilities, I don't know
> >>if DynaBean can do this. Can it?
> >
> >
> > No it can't. Can you patch the introspection code to be DynaBean
> > e.g. beanutils is DynaBean aware, so if you used that for your
> > introspection, you'd get DynaBean support for free. (Incidentally
> > & introspection are slightly different things).
> >

Incidentally, creating beans on the fly could be useful when performing
other dynamic operations like SQL as well... It might be nice to have a
simple bean factory around BCEL for creating real beans with BCEL from an
existing DynaBean etc.

> The code is in another projects package, I'd really want to stay away
> from manipulating it.

OK I understand.

> > Another approach could be to build something like the dynabean library
> > uses BCEL underneath the covers to generate dynamic bytecode at runtime
> >
> >
> >
> > Indeed maybe you could create a special kind of DynaClass which could
> > actually use BCEL to generate a real bean class which could then be
> > instantiated inside a DynaBean, so that it could still be used as a
> > but which the real, underlying Java object could be extracted and passed
> > into your reflection/introspection code. That'd be kinda cool :-).
> >
> Cool, this is right up my alley. Thanks for the pointer. I let you know
> how it goes.

BTW it might make sense to seperate the definition/creation of the bean
types from the instantiation of the beans. Then you could just turn the XML
that defines the beans into Java code using XSLT (or whatever) at build

Once you have the bean classes created & compiled, you can instantiate beans
in Jelly as follows...

<!-- create a bean and set properties on it -->
<j:customer var="c" class="com.acme.CustomerBean" name="James"

<!-- set a specific bean property -->
<j:set target="${c}" property="role" value="hacker"/>

Or you could use the bean library to generate a new TagLibrary at build time
to bind the beans to XML tags.

Another option is to use the define library to define a tag library
dynamically in Jelly which binds tags to beans. e.g.

<j:jelly xmlns:j="jelly:core" xmlns:define="jelly:define"

<define:taglib uri="myDummyTagLib">
    <define:bean name="customer"


then use the tags...

<my:customer var="c1" name="James"/>

<my:customer var="c2" name="Bob" location="US"/>



Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

View raw message