001// Copyright 2004, 2005 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.hivemind.impl;
016
017import java.util.AbstractMap;
018import java.util.Map;
019import java.util.Set;
020
021import org.apache.hivemind.HiveMind;
022import org.apache.hivemind.events.RegistryShutdownListener;
023
024/**
025 * The Map implementation visible to the client code. It defers to another inner implementation of
026 * Map; initially this is a {@link org.apache.hivemind.impl.ElementsInnerProxyMap}, but the inner
027 * proxy replaces itself with a real Map implementation containing the actual configuration
028 * elements.
029 * 
030 * @author Knut Wannheden
031 * @since 1.1
032 */
033public final class ElementsProxyMap extends AbstractMap implements RegistryShutdownListener
034{
035    private Map _inner;
036
037    private boolean _shutdown;
038
039    public void registryDidShutdown()
040    {
041        _shutdown = true;
042        _inner = null;
043    }
044
045    private void checkShutdown()
046    {
047        if (_shutdown)
048            throw HiveMind.createRegistryShutdownException();
049    }
050
051    public Set entrySet()
052    {
053        checkShutdown();
054
055        return _inner.entrySet();
056    }
057
058    public String toString()
059    {
060        return _inner.toString();
061    }
062
063    public boolean equals(Object o)
064    {
065        return _inner.equals(o);
066    }
067
068    public int hashCode()
069    {
070        return _inner.hashCode();
071    }
072
073    public void setInner(Map map)
074    {
075        _inner = map;
076    }
077
078}