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 *****************************************************************************/
009package org.picocontainer.injectors;
010
011import org.picocontainer.ComponentMonitor;
012import org.picocontainer.ComponentAdapter;
013import org.picocontainer.LifecycleStrategy;
014import org.picocontainer.Parameter;
015import org.picocontainer.PicoCompositionException;
016import org.picocontainer.Characteristics;
017import org.picocontainer.behaviors.AbstractBehaviorFactory;
018
019import java.util.Properties;
020
021/** @author Paul Hammant */
022@SuppressWarnings("serial")
023public class MultiInjection extends AbstractInjectionFactory {
024    private final String setterPrefix;
025
026    public MultiInjection(String setterPrefix) {
027        this.setterPrefix = setterPrefix;
028    }
029
030    public MultiInjection() {
031        this("set");
032    }
033
034    public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor monitor,
035                                                          LifecycleStrategy lifecycleStrategy,
036                                                          Properties componentProperties,
037                                                          Object componentKey,
038                                                          Class<T> componentImplementation,
039                                                          Parameter... parameters) throws PicoCompositionException {
040        boolean useNames = AbstractBehaviorFactory.arePropertiesPresent(componentProperties, Characteristics.USE_NAMES, true);
041        return wrapLifeCycle(new MultiInjector(componentKey, componentImplementation, parameters, monitor, setterPrefix, useNames), lifecycleStrategy);
042    }
043}