commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [Jelly] Creating Classes
Date Tue, 14 Jan 2003 15:41:52 GMT
From: "Mark R. Diggory" <mdiggory@latte.harvard.edu>
> James Strachan wrote:
> > From: "Mark R. Diggory" <mdiggory@latte.harvard.edu>
> >
> >>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
friendly?
> > e.g. beanutils is DynaBean aware, so if you used that for your
> > introspection, you'd get DynaBean support for free. (Incidentally
reflection
> > & 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
that
> > uses BCEL underneath the covers to generate dynamic bytecode at runtime
> >
> > http://jakarta.apache.org/bcel/
> >
> > 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
DynaBean
> > 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
time.

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"
location="London"/>

<!-- 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"
xmlns:my="myDummyTagLib">

<define:taglib uri="myDummyTagLib">
    <define:bean name="customer"
className="org.apache.commons.jelly.bean.Customer">
    ...

</define:taglib>

then use the tags...

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

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

...

James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Mime
View raw message