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.geronimo.system.configuration;
018    
019    import java.io.IOException;
020    import java.util.Collections;
021    import java.util.List;
022    
023    import org.apache.geronimo.gbean.GBeanInfo;
024    import org.apache.geronimo.gbean.GBeanInfoBuilder;
025    import org.apache.geronimo.kernel.config.Configuration;
026    import org.apache.geronimo.kernel.config.SwitchablePersistentConfigurationList;
027    import org.apache.geronimo.kernel.repository.Artifact;
028    import org.apache.geronimo.system.serverinfo.ServerInfo;
029    
030    /**
031     *
032     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
033     */
034    public class SwitchableLocalAttributeManager extends LocalAttributeManager implements SwitchablePersistentConfigurationList {
035        private boolean online;
036        
037        public SwitchableLocalAttributeManager(String configFile, String substitutionsFile, String configSubstitutionsPrefix, boolean readOnly, ServerInfo serverInfo) {
038            super(configFile, substitutionsFile, configSubstitutionsPrefix, readOnly, serverInfo);
039        }
040    
041        @Override
042        public synchronized List<Artifact> restore() throws IOException {
043            return Collections.emptyList();
044        }
045    
046        public synchronized void setOnline(boolean online) {
047            this.online = online;
048        }
049    
050        public synchronized boolean isOnline() {
051            return online;
052        }
053    
054        @Override
055        public synchronized void addConfiguration(Artifact configurationName) {
056            if (online) {
057                super.addConfiguration(configurationName);
058            }
059        }
060        
061        @Override
062        public void startConfiguration(Artifact configurationName) {
063            if (online) {
064                super.startConfiguration(configurationName);
065            }
066        }
067        
068        @Override
069        public void stopConfiguration(Artifact configName) {
070            if (online) {
071                super.stopConfiguration(configName);
072            }
073        }
074        
075        @Override
076        public synchronized void removeConfiguration(Artifact configName) {
077            if (online) {
078                super.removeConfiguration(configName);
079            }
080        }
081        
082        @Override
083        public void migrateConfiguration(Artifact oldName, Artifact newName, Configuration configuration) {
084            if (online) {
085                super.migrateConfiguration(oldName, newName, configuration);
086            }
087        }
088        
089        public static final GBeanInfo GBEAN_INFO;
090    
091        static {
092            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(SwitchableLocalAttributeManager.class, LocalAttributeManager.GBEAN_INFO);
093    
094            infoFactory.addInterface(SwitchablePersistentConfigurationList.class);
095            
096            GBEAN_INFO = infoFactory.getBeanInfo();
097        }
098    
099        public static GBeanInfo getGBeanInfo() {
100            return GBEAN_INFO;
101        }
102    
103    }