Grails bean factory + method with parameters

 
class MyObjectFactory {
    static final int TYPE_ONE = 1
    static final int TYPE_TWO = 2
 
    def produce(int type){
         if (type == TYPE_ONE){
              return ... // type one
         }
 
         if (type == TYPE_TWO){
              return ... // type two
         }
 
         throw new IllegalArgumentException()
    }
} 
 
...
 
beans {
 
    myObjectFactoryBean(MyObjectFactory)
 
    myObjectBean(myObjectFactoryBean:'produce'){bean->
         bean.constructorArgs = [MyObjectFactory.TYPE_ONE ]
    }
}
 

No Comments yet »

RSS feed for comments on this post.

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.