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.containers;
010
011import java.util.Properties;
012
013import org.picocontainer.DefaultPicoContainer;
014import org.picocontainer.MutablePicoContainer;
015import org.picocontainer.PicoContainer;
016
017/**
018 * immutable pico container constructed from properties.
019 * intendet to be used with config parameter
020 * 
021 * @author Konstantin Pribluda
022 *
023 */
024@SuppressWarnings("serial")
025public 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    @Override
053    public String toString() {
054        return "[Properties]:" + super.getDelegate().toString();
055    }
056
057
058}