2 * Copyright 2005-2010 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.cdi;
18 import java.util.logging.Logger;
20 import javax.enterprise.inject.spi.BeanManager;
22 import org.wamblee.inject.Injector;
23 import org.wamblee.inject.InjectorFactory;
26 * Factory that creates CDI injectors. In case no beanmanager is found then
27 * injectors will do nothing. This class may be subclassed for testing to
28 * override the injectors that are returned.
30 * @author Erik Brakkee
32 public class CdiInjectorFactory implements InjectorFactory {
34 private static final Logger LOGGER = Logger
35 .getLogger(CdiInjectorFactory.class.getName());
37 private BeanManager beanManager;
40 * Constructs the factory using a default bean manager.
42 * @throws IllegalArgumentException If bean manager is null.
44 public CdiInjectorFactory() {
45 this(BeanManagerLookup.lookup());
49 * Constructs the factory using an explicit bean manager.
52 * @throws IllegalArgumentException If bean manager is null.
54 public CdiInjectorFactory(BeanManager aBeanManager) {
55 if ( aBeanManager == null ) {
56 throw new IllegalArgumentException("Bean manager is null");
58 beanManager = aBeanManager;
62 public Injector create(Class aClass) {
63 return new CdiInjector(beanManager, aClass);