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.html file.                                                    *
007 *                                                                           *
008 * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
009 *****************************************************************************/
010package org.picocontainer.gems.util;
011
012
013import java.util.Properties;
014import java.io.IOException;
015import java.io.InputStream;
016
017/**
018 * constructable properties. 
019 *
020 * @author Konstantin Pribluda
021 */
022@SuppressWarnings("serial")
023public class ConstructableProperties extends Properties {
024
025        /**
026     * create properties from classpath resource using context classloader
027     *
028     * @param resource         resource name
029     * @exception IOException passed from Properties.load()
030     */
031    public ConstructableProperties(final String resource) throws IOException {
032        super();
033        load(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource));
034    }
035    /**
036     * 
037     * @param resource resource name
038     * @param defaults default properties
039     * @throws IOException can be thrown if something goes wrong
040     */
041    public ConstructableProperties(final String resource, final Properties defaults) throws IOException {
042        super(defaults);
043        load(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource));   
044    }
045    
046    /**
047     * create properties from input stream
048     * @param stream to read from 
049     * @throws IOException can be thrown by properties objkect
050     */
051    public ConstructableProperties(final InputStream stream) throws IOException {
052        super();
053        load(stream);
054    }
055    /**
056     * create from inpiut stream with default properties
057     * @param stream to read from 
058     * @param defaults default properties
059     * @throws IOException can be thrown by properties object
060     */
061    public ConstructableProperties(final InputStream stream, final Properties defaults) throws IOException {
062        super(defaults);
063        load(stream);
064    }
065}