AbstractGriffonAddon.java
001 /*
002  * SPDX-License-Identifier: Apache-2.0
003  *
004  * Copyright 2008-2017 the original author or authors.
005  *
006  * Licensed under the Apache License, Version 2.0 (the "License");
007  * you may not use this file except in compliance with the License.
008  * You may obtain a copy of the License at
009  *
010  *     http://www.apache.org/licenses/LICENSE-2.0
011  *
012  * Unless required by applicable law or agreed to in writing, software
013  * distributed under the License is distributed on an "AS IS" BASIS,
014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015  * See the License for the specific language governing permissions and
016  * limitations under the License.
017  */
018 package org.codehaus.griffon.runtime.core.addon;
019 
020 import griffon.core.GriffonApplication;
021 import griffon.core.addon.GriffonAddon;
022 import griffon.core.artifact.GriffonController;
023 import griffon.core.artifact.GriffonModel;
024 import griffon.core.artifact.GriffonView;
025 import griffon.core.mvc.MVCGroup;
026 import griffon.util.CollectionUtils;
027 import org.slf4j.Logger;
028 import org.slf4j.LoggerFactory;
029 
030 import javax.annotation.Nonnull;
031 import javax.inject.Inject;
032 import java.util.Collections;
033 import java.util.List;
034 import java.util.Map;
035 
036 import static griffon.util.AnnotationUtils.nameFor;
037 import static java.util.Objects.requireNonNull;
038 
039 /**
040  @author Andres Almiray
041  @since 2.0.0
042  */
043 public class AbstractGriffonAddon implements GriffonAddon {
044     private final Logger log;
045 
046     @Inject
047     public AbstractGriffonAddon() {
048         log = LoggerFactory.getLogger("griffon.addon." + getClass().getSimpleName());
049     }
050 
051     @Nonnull
052     @Override
053     public Logger getLog() {
054         return log;
055     }
056 
057     @Override
058     public void init(@Nonnull GriffonApplication application) {
059         // empty
060     }
061 
062     @Nonnull
063     @Override
064     public Map<String, Map<String, Object>> getMvcGroups() {
065         return Collections.emptyMap();
066     }
067 
068     @Nonnull
069     @Override
070     public List<String> getStartupGroups() {
071         return Collections.emptyList();
072     }
073 
074     @Override
075     public boolean canShutdown(@Nonnull GriffonApplication application) {
076         return true;
077     }
078 
079     @Override
080     public void onShutdown(@Nonnull GriffonApplication application) {
081         // empty
082     }
083 
084     @Nonnull
085     public static Map<String, Map<String, Object>> mvcgroup(@Nonnull Class<? extends MVCGroup> g,
086                                                             @Nonnull Class<? extends GriffonModel> m,
087                                                             @Nonnull Class<? extends GriffonView> v,
088                                                             @Nonnull Class<? extends GriffonController> c) {
089         requireNonNull(g, "Argument 'g' must not be null");
090         requireNonNull(v, "Argument 'm' must not be null");
091         requireNonNull(c, "Argument 'v' must not be null");
092         requireNonNull(g, "Argument 'c' must not be null");
093 
094         return CollectionUtils.<String, Map<String, Object>>map()
095             .e(nameFor(g, true), CollectionUtils.<String, Object>map()
096                 .e("model", m.getName())
097                 .e("view", v.getName())
098                 .e("controller", c.getName())
099             );
100     }
101 }