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