Nicholas
Nicholas

Reputation: 16066

Looking for Convenience Factory To Create GroovyObjectSupport Instances

I want to be able to create instances of GroovyObjectSupport (in Java) that wrap simple pojos (of any class) on the fly. I was hoping to find something that examined the class type of a provided pojo and implemented the GroovyObjectSupport constructs in AOP/ByteCode, but I'm open to any good ideas.

Ideally it would look something like this:

GroovyObjectSupport gos = GroovyObjectSupportFactory.generate(myPojo);

Cheers.

Upvotes: 3

Views: 327

Answers (1)

tim_yates
tim_yates

Reputation: 171154

Could you get away with wrapping it in a Proxy?

ie: you can do this:

import groovy.util.Proxy

...

String s = new String( "tim" )
Proxy p = new Proxy().wrap( s )

...
// Then in Groovy, you can do:

println p.length() // 3
println p.adaptee.class.name // "java.lang.String"

The Proxy class extends GroovyObjectSupport

Upvotes: 1

Related Questions