001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.configuration;
018    
019    import org.apache.commons.configuration.reloading.Reloadable;
020    
021    /**
022     * <p>A base class for hierarchical configurations with specific reloading
023     * requirements.</p>
024     * <p>This class manages a lock object which can be used for synchronization.</p>
025     *
026     * @author <a
027     *         href="http://commons.apache.org/configuration/team-list.html">Commons
028     *         Configuration team</a>
029     * @since 1.7
030     * @version $Id: HierarchicalReloadableConfiguration.java 1162387 2011-08-27 16:05:20Z oheger $
031     */
032    public class HierarchicalReloadableConfiguration extends HierarchicalConfiguration
033        implements Reloadable
034    {
035        /** Constant for the name used for the lock object. */
036        private static final String LOCK_NAME = "HierarchicalReloadableConfigurationLock";
037    
038        /** The lock object used by this instance. */
039        private final Object reloadLock;
040    
041        /**
042         * Creates a new instance of <code>HierarchicalReloadableConfiguration</code>.
043         */
044        public HierarchicalReloadableConfiguration()
045        {
046            super();
047            reloadLock = new Lock(LOCK_NAME);
048        }
049    
050        /**
051         * Creates a new instance of
052         * <code>HierarchicalReloadableConfiguration</code> and initializes it with
053         * the given lock object.
054         *
055         * @param lock the lock object
056         */
057        public HierarchicalReloadableConfiguration(Object lock)
058        {
059            super();
060            reloadLock = lock == null ? new Lock(LOCK_NAME) : lock;
061        }
062    
063        /**
064         * Creates a new instance of <code>HierarchicalConfiguration</code> and
065         * copies all data contained in the specified configuration into the new
066         * one.
067         *
068         * @param c the configuration that is to be copied (if <b>null</b>, this
069         * constructor will behave like the standard constructor)
070         */
071        public HierarchicalReloadableConfiguration(HierarchicalConfiguration c)
072        {
073            super(c);
074            reloadLock = new Lock(LOCK_NAME);
075        }
076    
077        public Object getReloadLock()
078        {
079            return reloadLock;
080        }
081    }