| 
01 /*02  * Copyright 2008-2015 the original author or authors.
 03  *
 04  * Licensed under the Apache License, Version 2.0 (the "License");
 05  * you may not use this file except in compliance with the License.
 06  * You may obtain a copy of the License at
 07  *
 08  *     http://www.apache.org/licenses/LICENSE-2.0
 09  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16 package griffon.core.controller;
 17
 18 import javax.annotation.Nonnull;
 19 import java.lang.reflect.Method;
 20
 21 /**
 22  * @author Andres Almiray
 23  * @since 2.1.0
 24  */
 25 public interface ActionHandler {
 26     String SUFFIX = "ActionHandler";
 27
 28     /**
 29      * Update the action's properties.
 30      * <p/>
 31      *
 32      * @param action the action to be updated
 33      */
 34     void update(@Nonnull Action action);
 35
 36     /**
 37      * Inspect the action during the configuration phase.
 38      * <p/>
 39      * This is the perfect time to search for annotations or any other information
 40      * required by the action. handlers have the option to cache such inspections
 41      * and recall them during {@code before()}, {@code after()} and {@code exception()}.
 42      *
 43      * @param action the action to be configured
 44      * @param method the method that represents the action itself
 45      */
 46     void configure(@Nonnull Action action, @Nonnull Method method);
 47
 48     /**
 49      * Called before an action is executed.
 50      * <p/>
 51      * Implementors have the choice of throwing an {@code AbortActionExecution} in
 52      * order to signal that the action should not be invoked. In any case this method
 53      * returns the arguments to be sent to the action, thus allowing the interceptor
 54      * to modify the arguments as it deem necessary. Failure to return an appropriate
 55      * value will most likely cause an error during the action's execution.
 56      *
 57      * @param action the action to execute
 58      * @param args   the action's arguments
 59      * @return arguments to be sent to the action
 60      * @throws griffon.core.controller.AbortActionExecution if action execution should be aborted.
 61      */
 62     @Nonnull
 63     Object[] before(@Nonnull Action action, @Nonnull Object[] args);
 64
 65     /**
 66      * Called after the action has been aborted or executed, even if an exception
 67      * occurred during execution.
 68      * <p/>
 69      *
 70      * @param status a flag that indicates the execution status of the action
 71      * @param action the action to execute
 72      * @param args   the arguments sent to the action
 73      */
 74     void after(@Nonnull ActionExecutionStatus status, @Nonnull Action action, @Nonnull Object[] args);
 75
 76     /**
 77      * Called after the action has been executed when an exception occurred
 78      * during execution.
 79      * <p/>
 80      * The exception will be rethrown by the ActionManager if is not handled by
 81      * any interceptor.
 82      *
 83      * @param exception the exception thrown during the action's execution
 84      * @param action    the action to execute
 85      * @param args      the arguments sent to the action during execution
 86      * @return <code>true</code> if the exception was handled successfully,
 87      * <code>false</code> otherwise.
 88      */
 89     boolean exception(@Nonnull Exception exception, @Nonnull Action action, @Nonnull Object[] args);
 90 }
 |