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