GriffonApplication.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 griffon.core;
019 
020 import griffon.core.addon.AddonManager;
021 import griffon.core.artifact.ArtifactManager;
022 import griffon.core.configuration.ConfigurationManager;
023 import griffon.core.controller.ActionManager;
024 import griffon.core.env.ApplicationPhase;
025 import griffon.core.event.EventRouter;
026 import griffon.core.i18n.MessageSource;
027 import griffon.core.injection.Injector;
028 import griffon.core.mvc.MVCGroupManager;
029 import griffon.core.resources.ResourceHandler;
030 import griffon.core.resources.ResourceInjector;
031 import griffon.core.resources.ResourceResolver;
032 import griffon.core.threading.UIThreadManager;
033 import griffon.core.view.WindowManager;
034 import org.slf4j.Logger;
035 
036 import javax.annotation.Nonnull;
037 import javax.annotation.Nullable;
038 import java.util.Locale;
039 import java.util.Map;
040 
041 /**
042  * Defines the basic contract of a Griffon application.<p>
043  *
044  @author Danno Ferrin
045  @author Andres Almiray
046  @since 0.0.0
047  */
048 public interface GriffonApplication extends Observable {
049     String PROPERTY_LOCALE = "locale";
050     String PROPERTY_PHASE = "phase";
051 
052     @Nonnull
053     Object createApplicationContainer(@Nonnull Map<String, Object> attributes);
054 
055     @Nonnull
056     ApplicationClassLoader getApplicationClassLoader();
057 
058     @Nonnull
059     Configuration getConfiguration();
060 
061     @Nonnull
062     UIThreadManager getUIThreadManager();
063 
064     @Nonnull
065     EventRouter getEventRouter();
066 
067     @Nonnull
068     ConfigurationManager getConfigurationManager();
069 
070     @Nonnull
071     ArtifactManager getArtifactManager();
072 
073     @Nonnull
074     ActionManager getActionManager();
075 
076     @Nonnull
077     AddonManager getAddonManager();
078 
079     @Nonnull
080     MVCGroupManager getMvcGroupManager();
081 
082     @Nonnull
083     MessageSource getMessageSource();
084 
085     @Nonnull
086     ResourceResolver getResourceResolver();
087 
088     @Nonnull
089     ResourceHandler getResourceHandler();
090 
091     @Nonnull
092     ResourceInjector getResourceInjector();
093 
094     @Nonnull
095     Injector<?> getInjector();
096 
097     @Nonnull
098     Context getContext();
099 
100     @Nonnull
101     <W> WindowManager<W> getWindowManager();
102 
103     // --== Lifecycle ==--
104 
105     /**
106      * Executes the 'Initialize' life cycle phase.
107      */
108     void initialize();
109 
110     /**
111      * Executes the 'Startup' life cycle phase.
112      */
113     void startup();
114 
115     /**
116      * Executes the 'Ready' life cycle phase.
117      */
118     void ready();
119 
120     /**
121      * Executes the 'Shutdown' life cycle phase.
122      *
123      @return false if the shutdown sequence was aborted
124      */
125     boolean shutdown();
126 
127     /**
128      * Queries any available ShutdownHandlers.
129      *
130      @return true if the shutdown sequence can proceed, false otherwise
131      */
132     boolean canShutdown();
133 
134     /**
135      * Registers a ShutdownHandler on this application
136      *
137      @param handler the shutdown handler to be registered; null and/or
138      *                duplicated values should be ignored
139      */
140     void addShutdownHandler(@Nonnull ShutdownHandler handler);
141 
142     /**
143      * Removes a ShutdownHandler from this application
144      *
145      @param handler the shutdown handler to be removed; null and/or
146      *                duplicated values should be ignored
147      */
148     void removeShutdownHandler(@Nonnull ShutdownHandler handler);
149 
150     // --== Properties ==--
151 
152     /**
153      * Gets the application locale.
154      *
155      @return the current Locale used by the application. Never returns null.
156      */
157     @Nonnull
158     Locale getLocale();
159 
160     /**
161      * Sets the application locale.<p>
162      * This is a bound property.
163      *
164      @param locale the Locale value to use
165      */
166     void setLocale(@Nonnull Locale locale);
167 
168     /**
169      * Sets the application locale.<p>
170      * This is a bound property.
171      *
172      @param locale a literal representation of a Locale
173      */
174     void setLocaleAsString(@Nullable String locale);
175 
176     /**
177      * Returns the current phase.
178      *
179      @return returns the current ApplicationPhase. Never returns null.
180      */
181     @Nonnull
182     ApplicationPhase getPhase();
183 
184     /**
185      * Returns the arguments set on the command line (if any).<p>
186      *
187      @return an array of command line arguments. Never returns null.
188      */
189     @Nonnull
190     String[] getStartupArgs();
191 
192     /**
193      * Returns a Logger instance suitable for this application.
194      *
195      @return a Logger instance.
196      */
197     @Nonnull
198     Logger getLog();
199 }