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.xbean.kernel;
018    
019    import java.util.Set;
020    import java.util.Collections;
021    import java.util.HashSet;
022    
023    /**
024     * AbstractServiceFactory is an implementation of ServiceFactory that handles all of the mundane issues.
025     *
026     * @author Dain Sundstrom
027     * @version $Id$
028     * @since 2.0
029     */
030    public abstract class AbstractServiceFactory implements ServiceFactory {
031        private boolean enabled = true;
032        private final Set startConditions = new HashSet();
033        private final Set stopConditions = new HashSet();
034    
035        /**
036         * {@inheritDoc}
037         */
038        public synchronized boolean isEnabled() {
039            return enabled;
040        }
041    
042        /**
043         * {@inheritDoc}
044         */
045        public synchronized void setEnabled(boolean enabled) {
046            this.enabled = enabled;
047        }
048    
049        /**
050         * {@inheritDoc}
051         */
052        public synchronized Set getStartConditions() {
053            return Collections.unmodifiableSet(new HashSet(startConditions));
054        }
055    
056        /**
057         * {@inheritDoc}
058         */
059        public synchronized void addStartCondition(ServiceCondition startCondition) throws NullPointerException {
060            if (startCondition == null) throw new NullPointerException("startCondition is null");
061            startConditions.add(startCondition);
062        }
063    
064        /**
065         * {@inheritDoc}
066         */
067        public synchronized void removeStartCondition(ServiceCondition startCondition) throws NullPointerException {
068            if (startCondition == null) throw new NullPointerException("startCondition is null");
069            startConditions.remove(startCondition);
070        }
071    
072        /**
073         * {@inheritDoc}
074         */
075        public synchronized Set getStopConditions() {
076            return Collections.unmodifiableSet(new HashSet(stopConditions));
077        }
078    
079        /**
080         * {@inheritDoc}
081         */
082        public synchronized void addStopCondition(ServiceCondition stopCondition) throws NullPointerException {
083            if (stopCondition == null) throw new NullPointerException("stopCondition is null");
084            stopConditions.add(stopCondition);
085        }
086    
087        /**
088         * {@inheritDoc}
089         */
090        public synchronized void removeStopCondition(ServiceCondition stopCondition) throws NullPointerException {
091            if (stopCondition == null) throw new NullPointerException("stopCondition is null");
092            stopConditions.remove(stopCondition);
093        }
094    }