wood burning stoves 2.0*
The moose likes Groovy and the fly likes Modular Closures for Builders (FactoryBuilderSupport) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Modular Closures for Builders (FactoryBuilderSupport)" Watch "Modular Closures for Builders (FactoryBuilderSupport)" New topic
Author

Modular Closures for Builders (FactoryBuilderSupport)

John Dee
Greenhorn

Joined: May 13, 2010
Posts: 3
The following is an attempt to modularize my DSL files because
there is a nested closure that is identically defined in
many of these DSL files.


Current (working) Non-Modular Implementation

JAVA CODE:



patient.groovy



The above works, but the problem is that the entire closure drug(){...}
is used in many other DSL files.

So, what I would like to do is pull the drug(){...} closure out of patient.groovy and put it
into a new drugs.groovy. The following is what I modified the above to in order to modularize the
drug closure, but I'm not understanding part of it.



Modified (broken) Modular Implementation

Modified Java Code:



New drugs.groovy




Modified patient.groovy



I think things are breaking down in the new drugs() {...} closure. drugClosure is defined in
a separate file and I'm having a heck of a time trying to find information that explains how to
include/reference/inject that into patient {...}


Any help would be much appreciated.

Thanks,
John
John Dee
Greenhorn

Joined: May 13, 2010
Posts: 3
I found the solution:

The the builder class needs a new method I named as 'include(Closure c, Object args)' method within the builder.

BUILDER Class:



Modified patient.groovy

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Modular Closures for Builders (FactoryBuilderSupport)
 
Similar Threads
immutable stack implementation
WA #1.....word association
Groovy Puzzler
HowTo --> GroovyShell().evaluate("['item1', 'item2', 'item3']")
creating elements