001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.runtime.model;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.nuxeo.runtime.service.TimestampedService;
025
026/**
027 * A component that expose a reload method usefull to completely reload the component and preserving already registered
028 * extensions.
029 *
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 * @deprecated since 5.6: services needing a reload should listen to runtime reload events instead. They can also
032 *             implement the {@link TimestampedService} interface in case they should not need to be reloaded when event
033 *             is received.
034 */
035@Deprecated
036public class ReloadableComponent extends DefaultComponent implements Reloadable {
037
038    protected List<Extension> extensions = new ArrayList<Extension>();
039
040    @Override
041    public void registerExtension(Extension extension) {
042        super.registerExtension(extension);
043        extensions.add(extension);
044    }
045
046    @Override
047    public void unregisterExtension(Extension extension) {
048        extensions.remove(extension);
049        super.unregisterExtension(extension);
050    }
051
052    public void reload(ComponentContext context) {
053        deactivate(context);
054        activate(context);
055        for (Extension xt : extensions) {
056            super.registerExtension(xt);
057        }
058    }
059
060    public List<Extension> getExtensions() {
061        return extensions;
062    }
063
064}