KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > Guice


1 /*
2  * Copyright (C) 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package com.google.inject;
18
19 import java.util.Arrays JavaDoc;
20
21 /**
22  * The entry point to the Guice framework. Creates {@link Injector}s from
23  * {@link Module}s.
24  */

25 public final class Guice {
26
27   private Guice() {}
28
29   /**
30    * Creates an injector with no explicit bindings.
31    */

32   static Injector createEmptyInjector() {
33     return createInjector();
34   }
35
36   /**
37    * Creates an injector for the given set of modules.
38    *
39    * @throws CreationException from which you can retrieve the individual error
40    * messages
41    */

42   public static Injector createInjector(Module... modules) {
43     return createInjector(Arrays.asList(modules));
44   }
45
46   /**
47    * Creates an injector for the given set of modules.
48    *
49    * @throws CreationException from which you can retrieve the individual error
50    * messages
51    */

52   public static Injector createInjector(Iterable JavaDoc<Module> modules) {
53     return createInjector(Stage.DEVELOPMENT, modules);
54   }
55
56   /**
57    * Creates an injector for the given set of modules, in a given development
58    * stage.
59    *
60    * @throws CreationException from which you can retrieve the individual error
61    * messages.
62    */

63   public static Injector createInjector(Stage stage, Module... modules) {
64     return createInjector(stage, Arrays.asList(modules));
65   }
66
67   /**
68    * Creates an injector for the given set of modules, in a given development
69    * stage.
70    *
71    * @throws CreationException from which you can retrieve the individual error
72    * messages.
73    */

74   public static Injector createInjector(Stage stage, Iterable JavaDoc<Module> modules) {
75     BinderImpl binder = new BinderImpl(stage);
76     for (Module module : modules) {
77       binder.install(module);
78     }
79     return binder.createInjector();
80   }
81 }
82
Popular Tags