001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 * Original code by * 009 *****************************************************************************/ 010 package org.picocontainer.injectors; 011 012 import org.picocontainer.ComponentAdapter; 013 import org.picocontainer.ComponentMonitor; 014 import org.picocontainer.LifecycleStrategy; 015 import org.picocontainer.Parameter; 016 import org.picocontainer.PicoCompositionException; 017 import org.picocontainer.Characteristics; 018 import org.picocontainer.behaviors.AbstractBehaviorFactory; 019 import org.picocontainer.annotations.Inject; 020 021 import java.util.Properties; 022 import java.lang.annotation.Annotation; 023 024 /** 025 * A {@link org.picocontainer.InjectionFactory} for Guice-style annotated fields. 026 * The factory creates {@link AnnotatedFieldInjector}. 027 * 028 * @author Paul Hammant 029 */ 030 @SuppressWarnings("serial") 031 public class AnnotatedFieldInjection extends AbstractInjectionFactory { 032 033 private final Class<? extends Annotation> injectionAnnotation; 034 035 public AnnotatedFieldInjection(Class<? extends Annotation> injectionAnnotation) { 036 this.injectionAnnotation = injectionAnnotation; 037 } 038 039 public AnnotatedFieldInjection() { 040 this(Inject.class); 041 } 042 043 public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor monitor, 044 LifecycleStrategy lifecycleStrategy, 045 Properties componentProperties, 046 Object componentKey, 047 Class<T> componentImplementation, 048 Parameter... parameters) throws PicoCompositionException { 049 boolean useNames = AbstractBehaviorFactory.arePropertiesPresent(componentProperties, Characteristics.USE_NAMES, true); 050 return wrapLifeCycle(monitor.newInjector(new AnnotatedFieldInjector(componentKey, componentImplementation, parameters, monitor, 051 injectionAnnotation, useNames)), lifecycleStrategy); 052 } 053 }