AbstractActionInterceptor.java
01 /*
02  * Copyright 2008-2014 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 org.codehaus.griffon.runtime.core.controller;
17 
18 import griffon.core.artifact.GriffonController;
19 import griffon.core.controller.AbortActionExecution;
20 import griffon.core.controller.ActionExecutionStatus;
21 import griffon.core.controller.ActionInterceptor;
22 
23 import javax.annotation.Nonnull;
24 import java.lang.reflect.Method;
25 
26 import static griffon.util.GriffonNameUtils.requireNonBlank;
27 import static java.util.Objects.requireNonNull;
28 
29 /**
30  @author Andres Almiray
31  @since 2.0.0
32  */
33 public class AbstractActionInterceptor implements ActionInterceptor {
34     private static final String ERROR_CONTROLLER_NULL = "Argument 'controller' must not be null";
35     private static final String ERROR_ACTION_NAME_BLANK = "Argument 'actionName' must not be blank";
36 
37     @Override
38     public void configure(@Nonnull GriffonController controller, @Nonnull String actionName, @Nonnull Method method) {
39     }
40 
41     @Nonnull
42     @Override
43     public Object[] before(@Nonnull GriffonController controller, @Nonnull String actionName, @Nonnull Object[] args) {
44         return new Object[0];
45     }
46 
47     @Override
48     public void after(@Nonnull ActionExecutionStatus status, @Nonnull GriffonController controller, @Nonnull String actionName, @Nonnull Object[] args) {
49     }
50 
51     @Override
52     public boolean exception(@Nonnull Exception exception, @Nonnull GriffonController controller, @Nonnull String actionName, @Nonnull Object[] args) {
53         return false;
54     }
55 
56     @Nonnull
57     protected AbortActionExecution abortActionExecution() throws AbortActionExecution {
58         throw new AbortActionExecution();
59     }
60 
61     @Nonnull
62     protected String qualifyActionName(@Nonnull GriffonController controller, @Nonnull String actionName) {
63         requireNonNull(controller, ERROR_CONTROLLER_NULL);
64         requireNonBlank(actionName, ERROR_ACTION_NAME_BLANK);
65         return controller.getClass().getName() "." + actionName;
66     }
67 }