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