0

I want to do AOP in Griffon's controller by using invokeMethod(), for example: add begin transaction advice to 'before' joint point and commit transaction advice to 'after' joint point in particular methods of all Griffon's controller.

I haven't verify this yet but I am afraid that the framework already has invokeMethod() for controller classes. Can I add a new invokeMethod() without affecting the previously defined invokeMethod() in a Groovy class? How to do that?

jocki
  • 1,728
  • 16
  • 26

1 Answers1

2

Griffon does enforce controllers to implement invokeMethod, you can provide your own. Another alternative would be to provide a custom implementation of the GriffonControllerActionManagerinterface

http://griffon.codehaus.org/guide/latest/api/griffon/core/controller/GriffonControllerActionManager.html

More information about this feature can be found at the Griffon Guide

http://griffon.codehaus.org/guide/latest/guide/single.html#actionManager

http://griffon.codehaus.org/guide/latest/guide/applicationOverview.html#managerConfiguration

Andres Almiray
  • 3,236
  • 18
  • 28
  • How to provide my own `invokeMethod` in Griffon controllers? Is it okay if I'm doing it like this: `app.artifactManager.getClassOfType('controller').each { GriffonClass gc -> gc.metaClass.invokeMethod = newInvokeMethodWithWrapper }` ? – jocki Jan 28 '13 at 11:18
  • Thanks for your help. I've examined another alternative mentioned in your answer, `GriffonControllerActionManager`. It seems to be tied directly with view, I will need to provide an instance of `javax.swing.AbstractAction` for every action in controller (if using swing-plugin). That will solve my question, though I just want to provide automatic db transaction to controller's actions, regardless of ui toolkit. Or maybe I should do AST transformation for each annotated closure and methods in controller? – jocki Jan 28 '13 at 18:46
  • 1
    One option would be to wrap the GriffonControllerActionManager provided by the UI toolkit. Another would be use AST transformations, either local or global. If going with the AST option be aware of threading injection performed by https://github.com/griffon/griffon/blob/master/subprojects/griffon-cli/src/main/groovy/org/codehaus/griffon/ast/ThreadingASTTransformation.java – Andres Almiray Jan 28 '13 at 21:03