Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CommonsInject |
|
| 3.0;3 |
1 | /** | |
2 | Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | contributor license agreements. See the NOTICE file distributed with | |
4 | this work for additional information regarding copyright ownership. | |
5 | The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | (the "License"); you may not use this file except in compliance with | |
7 | the License. You may obtain a copy of the License at | |
8 | ||
9 | http://www.apache.org/licenses/LICENSE-2.0 | |
10 | ||
11 | Unless required by applicable law or agreed to in writing, software | |
12 | distributed under the License is distributed on an "AS IS" BASIS, | |
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | See the License for the specific language governing permissions and | |
15 | limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.inject.api; | |
18 | ||
19 | import java.util.Arrays; | |
20 | import java.util.Collection; | |
21 | ||
22 | import org.apache.commons.inject.api.bind.IModule; | |
23 | import org.apache.commons.inject.impl.DefaultInjectorBuilder; | |
24 | ||
25 | /** | |
26 | * This class provides the anchor point to create {@link IInjector injectors} via | |
27 | * factory methods. | |
28 | */ | |
29 | 0 | public class CommonsInject { |
30 | /** | |
31 | * Creates a new {@link IInjector injector}, which is configured by invoking | |
32 | * the given modules. | |
33 | * @param pModules The modules, which provide the injectors bindings. | |
34 | * @return A new {@link IInjector injector}. | |
35 | * @see #build(Collection) | |
36 | */ | |
37 | public static IInjector build(IModule... pModules) { | |
38 | 9 | if (pModules == null) { |
39 | 0 | throw new NullPointerException("The module list must not be null."); |
40 | } | |
41 | 9 | final Collection<IModule> modules = Arrays.asList(pModules); |
42 | 9 | return build(modules); |
43 | } | |
44 | /** | |
45 | * Creates a new {@link IInjector injector}, which is configured by invoking | |
46 | * the given modules. | |
47 | * @param pModules The modules, which provide the injectors bindings. | |
48 | * @return A new {@link IInjector injector}. | |
49 | * @see #build(IModule...) | |
50 | */ | |
51 | public static IInjector build(Collection<IModule> pModules) { | |
52 | 9 | if (pModules == null) { |
53 | 0 | throw new NullPointerException("The module list must not be null."); |
54 | } | |
55 | 9 | if (pModules.isEmpty()) { |
56 | 0 | throw new IllegalArgumentException("The module list must not be empty."); |
57 | } | |
58 | 9 | return new DefaultInjectorBuilder(pModules).build(); |
59 | } | |
60 | /** | |
61 | * An alternative to {@link #build(IModule...)}, which provides additional | |
62 | * control on the injectors configuration. Rather than directly returning | |
63 | * an {@link IInjector injector}, this method returns an {@link IInjectorBuilder | |
64 | * injector builder}. | |
65 | * @return A new {@link IInjectorBuilder injector builder}. | |
66 | * @see #build(IModule...) | |
67 | * @see #build(Collection) | |
68 | */ | |
69 | public static IInjectorBuilder newBuilder() { | |
70 | 0 | return new DefaultInjectorBuilder(); |
71 | } | |
72 | } |