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 org.codehaus.griffon.runtime.core;
017
018 import griffon.core.*;
019 import griffon.core.addon.AddonManager;
020 import griffon.core.artifact.ArtifactHandler;
021 import griffon.core.artifact.ArtifactManager;
022 import griffon.core.controller.ActionManager;
023 import griffon.core.env.Lifecycle;
024 import griffon.core.event.EventHandler;
025 import griffon.core.event.EventRouter;
026 import griffon.core.i18n.MessageSource;
027 import griffon.core.mvc.MVCGroupManager;
028 import griffon.core.resources.ResourceHandler;
029 import griffon.core.resources.ResourceInjector;
030 import griffon.core.resources.ResourceResolver;
031 import griffon.core.threading.UIThreadManager;
032 import griffon.core.view.WindowManager;
033 import griffon.util.CompositeResourceBundleBuilder;
034 import org.codehaus.griffon.runtime.core.addon.DefaultAddonManager;
035 import org.codehaus.griffon.runtime.core.artifact.*;
036 import org.codehaus.griffon.runtime.core.controller.DefaultActionManager;
037 import org.codehaus.griffon.runtime.core.event.DefaultEventHandler;
038 import org.codehaus.griffon.runtime.core.event.DefaultEventRouter;
039 import org.codehaus.griffon.runtime.core.i18n.MessageSourceProvider;
040 import org.codehaus.griffon.runtime.core.injection.AbstractModule;
041 import org.codehaus.griffon.runtime.core.mvc.DefaultMVCGroupManager;
042 import org.codehaus.griffon.runtime.core.resources.DefaultApplicationResourceInjector;
043 import org.codehaus.griffon.runtime.core.resources.DefaultResourceHandler;
044 import org.codehaus.griffon.runtime.core.resources.ResourceResolverProvider;
045 import org.codehaus.griffon.runtime.core.threading.DefaultUIThreadManager;
046 import org.codehaus.griffon.runtime.core.view.NoopWindowManager;
047 import org.codehaus.griffon.runtime.util.DefaultCompositeResourceBundleBuilder;
048 import org.codehaus.griffon.runtime.util.ResourceBundleProvider;
049
050 import javax.inject.Named;
051 import java.util.ResourceBundle;
052
053 import static griffon.util.AnnotationUtils.named;
054
055 /**
056 * @author Andres Almiray
057 * @since 2.0.0
058 */
059 @Named("core")
060 public class DefaultApplicationModule extends AbstractModule {
061 @Override
062 protected void doConfigure() {
063 // tag::bindings[]
064 bind(ApplicationClassLoader.class)
065 .to(DefaultApplicationClassLoader.class)
066 .asSingleton();
067
068 bind(ApplicationConfigurer.class)
069 .to(DefaultApplicationConfigurer.class)
070 .asSingleton();
071
072 bind(ResourceHandler.class)
073 .to(DefaultResourceHandler.class)
074 .asSingleton();
075
076 bind(CompositeResourceBundleBuilder.class)
077 .to(DefaultCompositeResourceBundleBuilder.class)
078 .asSingleton();
079
080 bind(ResourceBundle.class)
081 .withClassifier(named("applicationResourceBundle"))
082 .toProvider(new ResourceBundleProvider("Config"))
083 .asSingleton();
084
085 bind(Configuration.class)
086 .to(DefaultConfiguration.class)
087 .asSingleton();
088
089 bind(ExecutorServiceManager.class)
090 .to(DefaultExecutorServiceManager.class)
091 .asSingleton();
092
093 bind(EventRouter.class)
094 .withClassifier(named("applicationEventRouter"))
095 .to(DefaultEventRouter.class)
096 .asSingleton();
097
098 bind(EventRouter.class)
099 .to(DefaultEventRouter.class);
100
101 bind(ResourceResolver.class)
102 .withClassifier(named("applicationResourceResolver"))
103 .toProvider(new ResourceResolverProvider("resources"))
104 .asSingleton();
105
106 bind(MessageSource.class)
107 .withClassifier(named("applicationMessageSource"))
108 .toProvider(new MessageSourceProvider("messages"))
109 .asSingleton();
110
111 bind(ResourceInjector.class)
112 .withClassifier(named("applicationResourceInjector"))
113 .to(DefaultApplicationResourceInjector.class)
114 .asSingleton();
115
116 bind(UIThreadManager.class)
117 .to(DefaultUIThreadManager.class)
118 .asSingleton();
119
120 bind(MVCGroupManager.class)
121 .to(DefaultMVCGroupManager.class)
122 .asSingleton();
123
124 for (Lifecycle lifecycle : Lifecycle.values()) {
125 bind(LifecycleHandler.class)
126 .withClassifier(named(lifecycle.getName()))
127 .toProvider(new LifecycleHandlerProvider(lifecycle.getName()))
128 .asSingleton();
129 }
130
131 bind(WindowManager.class)
132 .to(NoopWindowManager.class)
133 .asSingleton();
134
135 bind(ActionManager.class)
136 .to(DefaultActionManager.class)
137 .asSingleton();
138
139 bind(ArtifactManager.class)
140 .to(DefaultArtifactManager.class)
141 .asSingleton();
142
143 bind(ArtifactHandler.class)
144 .to(ModelArtifactHandler.class)
145 .asSingleton();
146
147 bind(ArtifactHandler.class)
148 .to(ViewArtifactHandler.class)
149 .asSingleton();
150
151 bind(ArtifactHandler.class)
152 .to(ControllerArtifactHandler.class)
153 .asSingleton();
154
155 bind(ArtifactHandler.class)
156 .to(ServiceArtifactHandler.class)
157 .asSingleton();
158
159 bind(PlatformHandler.class)
160 .toProvider(PlatformHandlerProvider.class)
161 .asSingleton();
162
163 bind(AddonManager.class)
164 .to(DefaultAddonManager.class)
165 .asSingleton();
166
167 bind(EventHandler.class)
168 .to(DefaultEventHandler.class)
169 .asSingleton();
170
171 bind(GriffonExceptionHandler.class)
172 .asSingleton();
173 // end::bindings[]
174 }
175 }
|