001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.util; 021 022import java.util.HashMap; 023import java.util.Map; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.nuxeo.runtime.model.ComponentName; 028import org.nuxeo.runtime.model.DefaultComponent; 029import org.nuxeo.runtime.model.Extension; 030 031/** 032 * @author Thierry Delprat 033 */ 034public class LocationManagerService extends DefaultComponent { 035 036 public static final ComponentName NAME = new ComponentName("org.nuxeo.ecm.platform.util.LocationManagerService"); 037 038 private static final Log log = LogFactory.getLog(LocationManagerService.class); 039 040 private Map<String, RepositoryLocation> locations = new HashMap<String, RepositoryLocation>(); 041 042 @Override 043 public void registerExtension(Extension extension) { 044 Object[] contribs = extension.getContributions(); 045 for (Object contrib : contribs) { 046 register((LocationManagerPluginExtension) contrib); 047 } 048 } 049 050 private void register(LocationManagerPluginExtension pluginExtension) { 051 String locationName = pluginExtension.getLocationName(); 052 boolean locationEnabled = pluginExtension.getLocationEnabled(); 053 054 log.info("Registering location manager: " + locationName + (locationEnabled ? "" : " (disabled)")); 055 056 RepositoryLocation locationTempPlugin = new RepositoryLocation(locationName); 057 058 if (locations.containsKey(locationName)) { 059 if (!locationEnabled) { 060 locations.remove(locationName); 061 } 062 } else { 063 locations.put(locationName, locationTempPlugin); 064 } 065 } 066 067 @Override 068 public void unregisterExtension(Extension extension) { 069 locations.clear(); 070 locations = null; 071 } 072 073 public Map<String, RepositoryLocation> getAvailableLocations() { 074 return locations; 075 } 076 077}