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    
015    package org.apache.hivemind.impl;
016    
017    import java.util.AbstractList;
018    import java.util.List;
019    
020    import org.apache.hivemind.HiveMind;
021    import org.apache.hivemind.events.RegistryShutdownListener;
022    
023    /**
024     * The List implementation visible to the client code. It defers
025     * to another inner implementation of List; initially this is
026     * a {@link org.apache.hivemind.impl.ElementsInnerProxyList}, but the
027     * inner proxy replaces itself with a real List implementation containing
028     * the actual configuration elements.
029     *
030     * @author Howard Lewis Ship
031     */
032    public final class ElementsProxyList extends AbstractList implements RegistryShutdownListener
033    {
034        private List _inner;
035        private boolean _shutdown;
036    
037        public void registryDidShutdown()
038        {
039            _shutdown = true;
040            _inner = null;
041        }
042    
043        private void checkShutdown()
044        {
045            if (_shutdown)
046                throw HiveMind.createRegistryShutdownException();
047        }
048    
049        public Object get(int index)
050        {
051            checkShutdown();
052    
053            return _inner.get(index);
054        }
055    
056        public int size()
057        {
058            checkShutdown();
059    
060            return _inner.size();
061        }
062    
063        public String toString()
064        {
065            return _inner.toString();
066        }
067    
068        public boolean equals(Object o)
069        {
070            return _inner.equals(o);
071        }
072    
073        public int hashCode()
074        {
075            return _inner.hashCode();
076        }
077    
078        public void setInner(List list)
079        {
080            _inner = list;
081        }
082    
083    }