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