jastrachan | 26 May 19:15 2004
Picon

Re: Groovy Markup BeanBuilder

On 25 May 2004, at 00:13, Mike Henderson wrote:
> Hi,
>   After my earlier attempt at configuring Spring with Groovy I looked 
> at the Groovy Markup and developed a builder for connecting beans 
> together:
>
> http://www.behindthesite.com/blog/C663408438/E876434710/index.html

Pretty cool! :)

I've wondered a few time about such a thing. I guess it all depends on 
how/what you're doing. e.g. if you're creating a graph of beans, you 
can just use constructors...

import com.foo.*
b = new Customer(name:'James', address:new Address(city:'London'))

etc

which is quite neat and can be used anywhere in code - though gets 
messy for large bean trees. So if you're just constructing small-ish 
beans & maps & lists, then normal syntax works - though its not always 
ideal. e.g. its a little cleaner to use a more declarative...

c = builder.customer (name:'James') {
     addresss(city:'London')
     orders {
	order(amount:1000, price:12.99)
     }
}

etc

Then map the names to bean types maybe. e.g. via a static helper 
method...

builder = BeanBuilder.make(customer:Customer.class, 
address:Address.class, order:Order.class)
c = builder.customer { ... }

What I wasn't as sure about was using markup to define Maps & Lists. I 
guess there's no reason why not; its just there's a pretty concise 
syntax for those things already - its maybe better to focus purely on 
the problem of creating beans & wiring up properties than worrying too 
much about creating lists/maps in a markup syntax (as they can be valid 
expressions inside markup anyways)

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

Gmane