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 * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant * 009 *****************************************************************************/ 010 011 package org.picocontainer.defaults; 012 013 import org.picocontainer.ComponentAdapter; 014 import org.picocontainer.Parameter; 015 import org.picocontainer.PicoIntrospectionException; 016 import org.picocontainer.monitors.DefaultComponentMonitor; 017 018 019 /** 020 * A {@link ComponentAdapterFactory} for JavaBeans. 021 * The factory creates {@link SetterInjectionComponentAdapter}. 022 * 023 * @author Jörg Schaible 024 * @version $Revision: 2768 $ 025 */ 026 public class SetterInjectionComponentAdapterFactory extends MonitoringComponentAdapterFactory { 027 private final boolean allowNonPublicClasses; 028 private LifecycleStrategy lifecycleStrategy; 029 030 public SetterInjectionComponentAdapterFactory(boolean allowNonPublicClasses, 031 LifecycleStrategy lifecycleStrategy) { 032 this.allowNonPublicClasses = allowNonPublicClasses; 033 this.lifecycleStrategy = lifecycleStrategy; 034 } 035 036 public SetterInjectionComponentAdapterFactory(boolean allowNonPublicClasses) { 037 this(allowNonPublicClasses, new DefaultLifecycleStrategy(new DefaultComponentMonitor())); 038 } 039 040 public SetterInjectionComponentAdapterFactory() { 041 this(false); 042 } 043 044 /** 045 * Create a {@link SetterInjectionComponentAdapter}. 046 * 047 * @param componentKey The component's key 048 * @param componentImplementation The class of the bean. 049 * @param parameters Any parameters for the setters. If null the adapter solves the 050 * dependencies for all setters internally. Otherwise the number parameters must match 051 * the number of the setter. 052 * @return Returns a new {@link SetterInjectionComponentAdapter}. 053 * @throws PicoIntrospectionException if dependencies cannot be solved 054 * @throws AssignabilityRegistrationException 055 * if the <code>componentKey</code> is a type 056 * that does not match the implementation 057 * @throws NotConcreteRegistrationException 058 * if the implementation is an interface or an 059 * abstract class. 060 */ 061 public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) 062 throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { 063 return new SetterInjectionComponentAdapter(componentKey, componentImplementation, parameters, 064 allowNonPublicClasses, currentMonitor(), lifecycleStrategy); 065 } 066 }