import org.codehaus.groovy.grails.plugins.support.* import org.codehaus.groovy.grails.commons.GrailsClassUtils import org.codehaus.groovy.runtime.InvokerHelper import org.grails.rest.Serializer class AutoRestGrailsPlugin { def version = GrailsPluginUtils.getGrailsVersion() def dependsOn = [hibernate:version] def loadAfter = ['hibernate'] def watchedResources = ["**/grails-app/domain/*.groovy"] def doWithSpring = { } def doWithApplicationContext = { applicationContext -> // TODO Implement post initialization spring config (optional) } def doWithDynamicMethods = { applicationContext -> def xs = Serializer.get() application.domainClasses.each { dc -> xs.alias(dc.propertyName, dc.getClazz()) dc.metaClass."toXML" = { -> return Serializer.get().toXML(delegate) } dc.metaClass."fromXML" = { InputStream ins -> delegate.properties = ConversionUtils.xmlToMap(ins) } dc.metaClass."fromXML" << { Map params -> delegate.properties = params } } } def doWithWebDescriptor = { xml -> } def onChange = { event -> // TODO Implement code that is executed when this class plugin class is changed // the event contains: event.application and event.applicationContext objects } def onApplicationChange = { event -> // TODO Implement code that is executed when any class in a GrailsApplication changes // the event contain: event.source, event.application and event.applicationContext objects } }