01: /*
02: * Copyright 2007 Tim Peierls
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.guice.spring;
17:
18: import com.google.inject.AbstractModule;
19: import com.google.inject.Provider;
20:
21: import static org.directwebremoting.guice.DwrScopes.GLOBAL;
22:
23: import org.springframework.beans.factory.BeanFactory;
24:
25: /**
26: * Ties {@code SpringIntegration.fromSpring} providers
27: * to a BeanFactory whose provider is a {@link java.io.Closeable} in global
28: * application scope, which means that it will be destroyed
29: * when the servlet context is destroyed.
30: */
31: public class SpringModule extends AbstractModule {
32: public SpringModule(BeanFactoryLoader loader) {
33: this .provider = new CloseableBeanFactoryProvider(loader);
34: }
35:
36: /* (non-Javadoc)
37: * @see com.google.inject.AbstractModule#configure()
38: */
39: @Override
40: protected void configure() {
41: bind(BeanFactory.class).toProvider(
42: CloseableBeanFactoryProvider.class).asEagerSingleton();
43:
44: bind(CloseableBeanFactoryProvider.class).toProvider(
45: providerOfProvider).in(GLOBAL);
46: }
47:
48: protected final CloseableBeanFactoryProvider provider;
49:
50: private final Provider<CloseableBeanFactoryProvider> providerOfProvider = new Provider<CloseableBeanFactoryProvider>() {
51: public CloseableBeanFactoryProvider get() {
52: return provider;
53: }
54: };
55: }
|