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.ComponentMonitor;
015 import org.picocontainer.Parameter;
016 import org.picocontainer.PicoIntrospectionException;
017 import org.picocontainer.monitors.DefaultComponentMonitor;
018
019 /**
020 * Creates instances of {@link ConstructorInjectionComponentAdapter} decorated by
021 * {@link CachingComponentAdapter}.
022 *
023 * @author Jon Tirsén
024 * @author Aslak Hellesøy
025 * @version $Revision: 2779 $
026 */
027 public class DefaultComponentAdapterFactory extends MonitoringComponentAdapterFactory {
028
029 private final LifecycleStrategy lifecycleStrategy;
030
031 public DefaultComponentAdapterFactory(ComponentMonitor monitor) {
032 super(monitor);
033 this.lifecycleStrategy = new DefaultLifecycleStrategy(monitor);
034 }
035
036 public DefaultComponentAdapterFactory(ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy) {
037 super(monitor);
038 this.lifecycleStrategy = lifecycleStrategy;
039 }
040
041 public DefaultComponentAdapterFactory() {
042 this.lifecycleStrategy = new DefaultLifecycleStrategy(new DefaultComponentMonitor());
043 }
044
045 public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
046 return new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(componentKey, componentImplementation, parameters, false, currentMonitor(), lifecycleStrategy));
047 }
048
049 public void changeMonitor(ComponentMonitor monitor) {
050 super.changeMonitor(monitor);
051 if (lifecycleStrategy instanceof ComponentMonitorStrategy) {
052 ((ComponentMonitorStrategy) lifecycleStrategy).changeMonitor(monitor);
053 }
054 }
055
056 }