Reputation: 11645
I am extending the MarkupSanitizerService from the sanitizer plugin.
Can I just override one of the functions - getSanitizer() which has my custome implementation or do I need to copy over the other functions in my service class from the MarkupSanitizerService ?
Thanks in advance..
Upvotes: 0
Views: 938
Reputation: 749
Another route to take would be to extend the Service, and then override the name of the sanitizer service in your grails-app/config/spring/resources.groovy That should have the desired effect.
Upvotes: 1
Reputation: 2349
grail inheritance works the same as java inheritance. You just need to supply your new function with the custom implementation
or you can get fancy and use metaprogramming.
a good article on metaprogramming in groovy
http://www.ibm.com/developerworks/java/library/j-pg06239/index.html
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually, or it gives programs greater flexibility to efficiently handle new situations without recompilation
groovy supplies 2 types of metaprogramming techniques: compile time metaprogramming, and runtime metaprogramming.
you can do something like the following in boot strap calls that should work
def grailsApplication
def init = { servletContext ->
soSomethingWithAService()
}
def destroy = {
}
private def doSomethingWithAService() {
grailsApplication.serviceClasses.each { serviceClass ->
// do something
def result
return result
}
}
}
}
Upvotes: 1