AbstractMVCHandler.java
001 /*
002  * Copyright 2008-2014 the original author or authors.
003  *
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  *
008  *     http://www.apache.org/licenses/LICENSE-2.0
009  *
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 package org.codehaus.griffon.runtime.core.mvc;
017 
018 import griffon.core.artifact.GriffonController;
019 import griffon.core.artifact.GriffonModel;
020 import griffon.core.artifact.GriffonMvcArtifact;
021 import griffon.core.artifact.GriffonView;
022 import griffon.core.mvc.MVCCallable;
023 import griffon.core.mvc.MVCGroup;
024 import griffon.core.mvc.MVCGroupManager;
025 import griffon.core.mvc.MVCHandler;
026 
027 import javax.annotation.Nonnull;
028 import javax.inject.Inject;
029 import java.util.List;
030 import java.util.Map;
031 
032 import static java.util.Objects.requireNonNull;
033 
034 /**
035  * Base implementation of the MVCHandler interface.
036  *
037  @author Andres Almiray
038  @since 2.0.0
039  */
040 public abstract class AbstractMVCHandler implements MVCHandler {
041     private final MVCGroupManager mvcGroupManager;
042 
043     @Inject
044     public AbstractMVCHandler(@Nonnull MVCGroupManager mvcGroupManager) {
045         this.mvcGroupManager = requireNonNull(mvcGroupManager, "Argument 'mvcGroupManager' must not be null");
046     }
047 
048     @Nonnull
049     public MVCGroup buildMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType) {
050         return mvcGroupManager.buildMVCGroup(args, mvcType);
051     }
052 
053     @Nonnull
054     public MVCGroup buildMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType, @Nonnull String mvcId) {
055         return mvcGroupManager.buildMVCGroup(args, mvcType, mvcId);
056     }
057 
058     @Nonnull
059     public MVCGroup buildMVCGroup(@Nonnull String mvcType) {
060         return mvcGroupManager.buildMVCGroup(mvcType);
061     }
062 
063     @Nonnull
064     public MVCGroup buildMVCGroup(@Nonnull String mvcType, @Nonnull Map<String, Object> args) {
065         return mvcGroupManager.buildMVCGroup(mvcType, args);
066     }
067 
068     @Nonnull
069     public MVCGroup buildMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId) {
070         return mvcGroupManager.buildMVCGroup(mvcType, mvcId);
071     }
072 
073     @Nonnull
074     public MVCGroup buildMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId, @Nonnull Map<String, Object> args) {
075         return mvcGroupManager.buildMVCGroup(mvcType, mvcId, args);
076     }
077 
078     @Nonnull
079     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType) {
080         return mvcGroupManager.createMVCGroup(args, mvcType);
081     }
082 
083     @Nonnull
084     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType, @Nonnull String mvcId) {
085         return mvcGroupManager.createMVCGroup(args, mvcType, mvcId);
086     }
087 
088     @Nonnull
089     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull String mvcType) {
090         return mvcGroupManager.createMVCGroup(mvcType);
091     }
092 
093     @Nonnull
094     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull String mvcType, @Nonnull Map<String, Object> args) {
095         return mvcGroupManager.createMVCGroup(mvcType, args);
096     }
097 
098     @Nonnull
099     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId) {
100         return mvcGroupManager.createMVCGroup(mvcType, mvcId);
101     }
102 
103     @Nonnull
104     public List<? extends GriffonMvcArtifact> createMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId, @Nonnull Map<String, Object> args) {
105         return mvcGroupManager.createMVCGroup(mvcType, mvcId, args);
106     }
107 
108     public void destroyMVCGroup(@Nonnull String mvcId) {
109         mvcGroupManager.destroyMVCGroup(mvcId);
110     }
111 
112     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId, @Nonnull MVCCallable<M, V, C> handler) {
113         mvcGroupManager.withMVCGroup(mvcType, mvcId, handler);
114     }
115 
116     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType, @Nonnull MVCCallable<M, V, C> handler) {
117         mvcGroupManager.withMVCGroup(args, mvcType, handler);
118     }
119 
120     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull Map<String, Object> args, @Nonnull String mvcType, @Nonnull String mvcId, @Nonnull MVCCallable<M, V, C> handler) {
121         mvcGroupManager.withMVCGroup(args, mvcType, mvcId, handler);
122     }
123 
124     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull String mvcType, @Nonnull Map<String, Object> args, @Nonnull MVCCallable<M, V, C> handler) {
125         mvcGroupManager.withMVCGroup(mvcType, args, handler);
126     }
127 
128     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull String mvcType, @Nonnull MVCCallable<M, V, C> handler) {
129         mvcGroupManager.withMVCGroup(mvcType, handler);
130     }
131 
132     public <M extends GriffonModel, V extends GriffonView, C extends GriffonController> void withMVCGroup(@Nonnull String mvcType, @Nonnull String mvcId, @Nonnull Map<String, Object> args, @Nonnull MVCCallable<M, V, C> handler) {
133         mvcGroupManager.withMVCGroup(mvcType, mvcId, args, handler);
134     }
135 }