AbstractGriffonController.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 org.codehaus.griffon.runtime.core.artifact;
19 
20 import griffon.core.GriffonApplication;
21 import griffon.core.artifact.GriffonController;
22 import griffon.core.artifact.GriffonControllerClass;
23 import griffon.core.controller.Action;
24 import griffon.core.controller.ActionManager;
25 
26 import javax.annotation.Nonnull;
27 import javax.annotation.Nullable;
28 import javax.inject.Inject;
29 
30 import static griffon.util.GriffonNameUtils.requireNonBlank;
31 
32 /**
33  * Base implementation of the GriffonController interface.
34  *
35  @author Andres Almiray
36  @since 2.0.0
37  */
38 public abstract class AbstractGriffonController extends AbstractGriffonMvcArtifact implements GriffonController {
39     public AbstractGriffonController() {
40 
41     }
42 
43     /**
44      * Creates a new instance of this class.
45      *
46      @param application the GriffonApplication that holds this artifact.
47      @deprecated Griffon prefers field injection over constructor injector for artifacts as of 2.1.0
48      */
49     @Inject
50     @Deprecated
51     public AbstractGriffonController(@Nonnull GriffonApplication application) {
52         super(application);
53     }
54 
55     @Nonnull
56     @Override
57     protected String getArtifactType() {
58         return GriffonControllerClass.TYPE;
59     }
60 
61     @Nonnull
62     protected ActionManager getActionManager() {
63         return getApplication().getActionManager();
64     }
65 
66     public void invokeAction(@Nonnull String name, Object... args) {
67         getActionManager().invokeAction(this, requireNonBlank(name, "Argument 'name' must not be blank"), args);
68     }
69 
70     @Nullable
71     protected Action actionFor(@Nonnull String actionName) {
72         return getActionManager().actionFor(this, actionName);
73     }
74 }