ControllerActionTransformer (Grails 2.3.8)
Date: 2014-04-24

Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.grails.compiler.web
[Java] Class ControllerActionTransformer

    java.lang.Object
      org.codehaus.groovy.grails.compiler.web.ControllerActionTransformer

All Implemented Interfaces:
  AnnotatedClassInjector, GrailsArtefactClassInjector

    @AstTransformer
    public class ControllerActionTransformer
    extends java.lang.Object

Enhances controller classes by converting closures actions to method actions and binding request parameters to action arguments.

Field Summary
`static org.codehaus.groovy.ast.AnnotationNode` | `ACTION_ANNOTATION_NODE`
`static java.lang.String` | `EXCEPTION_HANDLER_META_DATA_FIELD_NAME`
`static java.lang.String` | `VOID_TYPE`

Constructor Summary
`ControllerActionTransformer()`

Method Summary
`protected void` | `addMethodToInvokeClosure(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.PropertyNode closureProperty, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
`protected void` | `annotateActionMethod(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.Parameter[] parameters, org.codehaus.groovy.ast.MethodNode methodNode)`
`java.lang.String[]` | `getArtefactTypes()`
`protected java.util.Collection` | `getExceptionHandlerMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceUnit)`
`protected org.codehaus.groovy.ast.expr.Expression` | `getRejectValueExpression(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodParamName)`
`protected org.codehaus.groovy.ast.stmt.BlockStatement` | `initializeActionParameters(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter[] actionParameters, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
`protected void` | `initializeAndValidateCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode controllerNode, org.codehaus.groovy.ast.ClassNode commandObjectNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
`protected void` | `initializeCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode commandObjectNode, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source)`
`protected void` | `initializeMethodParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter param, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
`protected void` | `initializePrimitiveOrTypeWrapperParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)`
`protected void` | `initializeStringParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)`
`protected boolean` | `methodShouldBeConfiguredAsControllerAction(org.codehaus.groovy.ast.MethodNode method)` @param method a potential controller action method
`void` | `performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)`
`void` | `performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)`
`void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)`
`void` | `performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)`
`boolean` | `shouldInject(java.net.URL url)`
`protected void` | `transformClosureToMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.ClosureExpression closureAction, org.codehaus.groovy.ast.PropertyNode property, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)`
`protected void` | `wrapMethodBodyWithExceptionHandling(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)` This will wrap the method body in a try catch block which does something like this:
     try {
         // original method body here
     } catch (Exception $caughtException) {
         Method $method = getExceptionHandlerMethod($caughtException.getClass())
         if($method) {
             return $method.invoke(this, $caughtException)
         } else {
             throw $caughtException
         }
     }

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### ACTION_ANNOTATION_NODE

    public static final org.codehaus.groovy.ast.AnnotationNode ACTION_ANNOTATION_NODE

### EXCEPTION_HANDLER_META_DATA_FIELD_NAME

    public static final java.lang.String EXCEPTION_HANDLER_META_DATA_FIELD_NAME

### VOID_TYPE

    public static final java.lang.String VOID_TYPE

Constructor Detail

### ControllerActionTransformer

    public ControllerActionTransformer()

Method Detail

### addMethodToInvokeClosure

    protected void addMethodToInvokeClosure(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.PropertyNode closureProperty, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

### annotateActionMethod

    protected void annotateActionMethod(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.Parameter[] parameters, org.codehaus.groovy.ast.MethodNode methodNode)

### getArtefactTypes

    public java.lang.String[] getArtefactTypes()

### getExceptionHandlerMethods

    protected java.util.Collection getExceptionHandlerMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceUnit)

### getRejectValueExpression

    protected org.codehaus.groovy.ast.expr.Expression getRejectValueExpression(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodParamName)

### initializeActionParameters

    protected org.codehaus.groovy.ast.stmt.BlockStatement initializeActionParameters(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter[] actionParameters, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

### initializeAndValidateCommandObjectParameter

    protected void initializeAndValidateCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode controllerNode, org.codehaus.groovy.ast.ClassNode commandObjectNode, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

### initializeCommandObjectParameter

    protected void initializeCommandObjectParameter(org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ClassNode commandObjectNode, java.lang.String paramName, org.codehaus.groovy.control.SourceUnit source)

### initializeMethodParameter

    protected void initializeMethodParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.ASTNode actionNode, java.lang.String actionName, org.codehaus.groovy.ast.Parameter param, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

### initializePrimitiveOrTypeWrapperParameter

    protected void initializePrimitiveOrTypeWrapperParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)

### initializeStringParameter

    protected void initializeStringParameter(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.stmt.BlockStatement wrapper, org.codehaus.groovy.ast.Parameter param, java.lang.String requestParameterName)

### methodShouldBeConfiguredAsControllerAction

    protected boolean methodShouldBeConfiguredAsControllerAction(org.codehaus.groovy.ast.MethodNode method)

  Parameters:
    `method` - a potential controller action method
  Returns:
    true if the method should be configured as a controller action, false otherwise

### performInjection

    public void performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)

### performInjection

    public void performInjection(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)

### performInjectionOnAnnotatedClass

    @java.lang.Overridepublic void performInjectionOnAnnotatedClass(SourceUnit source, GeneratorContext context, ClassNode classNode) {
    public void performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context, org.codehaus.groovy.ast.ClassNode classNode)

### performInjectionOnAnnotatedClass

    @java.lang.Overridepublic void performInjectionOnAnnotatedClass(SourceUnit source, ClassNode classNode) {
    public void performInjectionOnAnnotatedClass(org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.ast.ClassNode classNode)

### shouldInject

    public boolean shouldInject(java.net.URL url)

### transformClosureToMethod

    protected void transformClosureToMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.ClosureExpression closureAction, org.codehaus.groovy.ast.PropertyNode property, org.codehaus.groovy.control.SourceUnit source, org.codehaus.groovy.classgen.GeneratorContext context)

### wrapMethodBodyWithExceptionHandling

    protected void wrapMethodBodyWithExceptionHandling(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)

  This will wrap the method body in a try catch block which does something like this:

       try {
           // original method body here
       } catch (Exception $caughtException) {
           Method $method = getExceptionHandlerMethod($caughtException.getClass())
           if($method) {
               return $method.invoke(this, $caughtException)
           } else {
               throw $caughtException
           }
       }

  Parameters:
    `methodNode` - the method to add the try catch block to

Groovy Documentation