/*
 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Nuxeo - initial API and implementation
 *
 * $Id$
 */

package org.nuxeo.ecm.platform.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.runtime.model.ComponentName;
import org.nuxeo.runtime.model.DefaultComponent;
import org.nuxeo.runtime.model.Extension;

/**
 * @author Thierry Delprat
 *
 */
public class LocationManagerService extends DefaultComponent {

    public static final ComponentName NAME =
        new ComponentName("org.nuxeo.ecm.platform.util.LocationManagerService");

    private static final Log log = LogFactory.getLog(LocationManagerService.class);

    private Map<String, RepositoryLocation> locations = new HashMap<String, RepositoryLocation>();

    @Override
    public void registerExtension(Extension extension) throws Exception {
        Object[] contribs = extension.getContributions();
        for (Object contrib : contribs) {
            log.info("registering LocationManager Plugin ... ");
            LocationManagerPluginExtension locationManagerPlugin
                    = (LocationManagerPluginExtension) contrib;
            register(locationManagerPlugin);
        }
    }

    private void register(LocationManagerPluginExtension pluginExtension) {
        String locationName = pluginExtension.getLocationName();
        Boolean locationEnabled = pluginExtension.getLocationEnabled();

        RepositoryLocation locationTempPlugin = new RepositoryLocation(locationName);

        if (locations.containsKey(locationName)) {
            if (!locationEnabled) {
                locations.remove(locationName);
            }
        } else {
            locations.put(locationName, locationTempPlugin);
        }
    }

    @Override
    public void unregisterExtension(Extension extension) throws Exception {
        locations.clear();
        locations = null;
    }

/*    @Override
    public void activate(RuntimeContext context) throws Exception {
        super.activate(context);
    }

    @Override
    public void deactivate(RuntimeContext context) throws Exception {
        super.deactivate(context);
    }
  */
    public Map<String, RepositoryLocation> getAvailableLocations() {
        return locations;
    }

}

@@ -1134,24 +1134,16 @@
 e NAME =
-%0A       
  new Com
@@ -1153,16 +1153,29 @@
 entName(
+%0A            
 %22org.nux
@@ -1611,232 +1611,57 @@
     
-log.info(%22registering LocationManager Plugin ... %22);%0A            LocationManagerPluginExtension locationManagerPlugin%0A                    = (LocationManagerPluginExtension) contrib;%0A            register(locationManagerPlugin
+register((LocationManagerPluginExtension) contrib
 );%0A 
@@ -1825,17 +1825,17 @@
         
-B
+b
 oolean l
@@ -1886,24 +1886,149 @@
 Enabled();%0A%0A
+        log.info(%22Registering location manager: %22 + locationName +%0A                (locationEnabled ? %22%22 : %22 (disabled)%22));%0A%0A
         Repo
@@ -2086,16 +2086,33 @@
 ocation(
+%0A                
 location
@@ -2517,262 +2517,8 @@
  %7D%0A%0A
-/*    @Override%0A    public void activate(RuntimeContext context) throws Exception %7B%0A        super.activate(context);%0A    %7D%0A%0A    @Override%0A    public void deactivate(RuntimeContext context) throws Exception %7B%0A        super.deactivate(context);%0A    %7D%0A  */%0A
     

Clean up registration message