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 griffon.core.mvc;
019
020 import griffon.core.Context;
021 import griffon.core.GriffonApplication;
022 import griffon.core.artifact.GriffonController;
023 import griffon.core.artifact.GriffonModel;
024 import griffon.core.artifact.GriffonView;
025 import griffon.exceptions.ArtifactNotFoundException;
026
027 import javax.annotation.Nonnull;
028 import javax.annotation.Nullable;
029 import java.util.Map;
030
031 /**
032 * Manages the configuration and instantiation of MVC groups.
033 *
034 * @author Andres Almiray
035 * @since 2.0.0
036 */
037 public interface MVCGroupManager extends MVCHandler {
038 /**
039 * Creates an MVCConfiguration instance with the given arguments.
040 *
041 * @param mvcType the name of the MVC group
042 * @param members members of the group
043 * @param config additional configuration required by the group
044 * @return a ready-to-use MVCGroupConfiguration instance
045 */
046 @Nonnull
047 MVCGroupConfiguration newMVCGroupConfiguration(@Nonnull String mvcType, @Nonnull Map<String, String> members, @Nonnull Map<String, Object> config);
048
049 /**
050 * Clones an existing MVCGroupConfiguration, optionally overriding additional config values.
051 *
052 * @param mvcType the name of the configuration to clone
053 * @param config additional config parameters to be set on the configuration
054 * @return a ready-to-use MVCGroupConfiguration instance
055 */
056 @Nonnull
057 MVCGroupConfiguration cloneMVCGroupConfiguration(@Nonnull String mvcType, @Nonnull Map<String, Object> config);
058
059 /**
060 * Creates a new MVCGroup instance.
061 *
062 * @param configuration the configuration of the group
063 * @param mvcId the id to use for the group
064 * @param members the instance members of the group
065 * @param parentGroup the parent group (if any)
066 * @return a ready-to-use MVCGroup instance
067 */
068 @Nonnull
069 MVCGroup newMVCGroup(@Nonnull MVCGroupConfiguration configuration, @Nullable String mvcId, @Nonnull Map<String, Object> members, @Nullable MVCGroup parentGroup);
070
071 @Nonnull
072 Context newContext(@Nullable MVCGroup parentGroup);
073
074 /**
075 * Initializes this manager with the group configurations provided by the application and addons.
076 *
077 * @param configurations available group configurations
078 */
079 void initialize(@Nonnull Map<String, MVCGroupConfiguration> configurations);
080
081 void addConfiguration(@Nonnull MVCGroupConfiguration configuration);
082
083 void removeConfiguration(@Nonnull MVCGroupConfiguration configuration);
084
085 void removeConfiguration(@Nonnull String name);
086
087 @Nonnull
088 Map<String, MVCGroupConfiguration> getConfigurations();
089
090 @Nonnull
091 Map<String, MVCGroup> getGroups();
092
093 @Nonnull
094 MVCGroupConfiguration findConfiguration(@Nonnull String mvcType);
095
096 @Nullable
097 MVCGroup findGroup(@Nonnull String mvcId);
098
099 @Nullable
100 MVCGroup getAt(@Nonnull String mvcId);
101
102 /**
103 * Returns all currently available model instances, keyed by group name.<p>
104 *
105 * @return a Map of all currently instantiated models.
106 */
107 @Nonnull
108 Map<String, ? extends GriffonModel> getModels();
109
110 /**
111 * Returns all currently available view instances, keyed by group name.<p>
112 *
113 * @return a Map of all currently instantiated views.
114 */
115 @Nonnull
116 Map<String, ? extends GriffonView> getViews();
117
118 /**
119 * Returns all currently available controller instances, keyed by group name.<p>
120 *
121 * @return a Map of all currently instantiated controllers.
122 */
123 @Nonnull
124 Map<String, ? extends GriffonController> getControllers();
125
126 GriffonApplication getApplication();
127
128 /**
129 * Finds a named controller.
130 *
131 * @param name the name of the group that holds the controller
132 * @param type the type of the controller
133 * @return the controller instance if found
134 * @throws ArtifactNotFoundException if the named controller could not be found
135 * @since 2.1.0
136 */
137 @Nonnull
138 <C extends GriffonController> C getController(@Nonnull String name, @Nonnull Class<C> type) throws ArtifactNotFoundException;
139
140 /**
141 * Finds a named model.
142 *
143 * @param name the name of the group that holds the model
144 * @param type the type of the model
145 * @return the model instance if found
146 * @throws ArtifactNotFoundException if the named model could not be found
147 * @since 2.1.0
148 */
149 @Nonnull
150 <M extends GriffonModel> M getModel(@Nonnull String name, @Nonnull Class<M> type) throws ArtifactNotFoundException;
151
152 /**
153 * Finds a named view.
154 *
155 * @param name the name of the group that holds the view
156 * @param type the type of the view
157 * @return the view instance if found
158 * @throws ArtifactNotFoundException if the named view could not be found
159 * @since 2.1.0
160 */
161 @Nonnull
162 <V extends GriffonView> V getView(@Nonnull String name, @Nonnull Class<V> type) throws ArtifactNotFoundException;
163
164 /**
165 * Finds a named controller.
166 *
167 * @param name the name of the group that holds the controller
168 * @param type the type of the controller
169 * @return the controller instance if found
170 * @since 2.1.0
171 */
172 @Nullable
173 <C extends GriffonController> C findController(@Nonnull String name, @Nonnull Class<C> type);
174
175 /**
176 * Finds a named model.
177 *
178 * @param name the name of the group that holds the model
179 * @param type the type of the model
180 * @return the model instance if found
181 * @since 2.1.0
182 */
183 @Nullable
184 <M extends GriffonModel> M findModel(@Nonnull String name, @Nonnull Class<M> type);
185
186 /**
187 * Finds a named view.
188 *
189 * @param name the name of the group that holds the view
190 * @param type the type of the view
191 * @return the view instance if found
192 * @since 2.1.0
193 */
194 @Nullable
195 <V extends GriffonView> V findView(@Nonnull String name, @Nonnull Class<V> type);
196 }
|