    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     *****************************************************************************/
    009    package org.picocontainer.containers;
    010
    011    import java.util.Properties;
    012
    013    import org.picocontainer.DefaultPicoContainer;
    014    import org.picocontainer.MutablePicoContainer;
    015    import org.picocontainer.PicoContainer;
    016
    017    /**
    018     * immutable pico container constructed from properties.
    019     * intendet to be used with config parameter
    020     *
    021     * @author k.pribluda
    022     *
    023     */
    024    @SuppressWarnings("serial")
    025    public class PropertiesPicoContainer extends AbstractDelegatingPicoContainer {
    026
    027            /**
    028             * create with parent container and populate from properties
    029             * @param properties
    030             * @param parent
    031             */
    032            public PropertiesPicoContainer(Properties properties, PicoContainer parent) {
    033                    super(new DefaultPicoContainer(parent));
    034                    // populate container from properties
    035                    for(Object key: properties.keySet()) {
    036                            ((MutablePicoContainer)getDelegate()).addComponent(key,properties.get(key));
    037                    }
    038            }
    039
    040        /**
    041             * construct without a parent
    042             * @param properties
    043             */
    044            public PropertiesPicoContainer(Properties properties) {
    045                    this(properties,null);
    046            }
    047
    048        public void setName(String s) {
    049            ((DefaultPicoContainer)getDelegate()).setName(s);
    050        }
    051
    052    }