miércoles, 5 de mayo de 2010

Getting annotations in Grails Domain Classes

A quickie post, I've disappeared for a while, but I'll be back with tons of new posts, for now, here is a quick way to get annotations on Grails Domain Classes, it might be helpful for doing some post processing of your domain model with the help of a plugin

For this example I'm getting the field annotations of all declared fields in my declared domain classes, using the doWithApplicationContext closure that comes with all plugins:

def doWithApplicationContext = { applicationContext ->
for(GrailsDomainClass domainClass in application.domainClasses) {
println "DOMAIN CLASS ${domainClass}: "
field ->
println "${field.name} has the following annotations: ${field.declaredAnnotations} "
//Do some more processing