001/* 002 * (C) Copyright 2013 Nuxeo SA (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-2.1.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 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.service.impl; 018 019import org.apache.commons.lang.StringUtils; 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.nuxeo.runtime.model.ContributionFragmentRegistry; 023 024/** 025 * Registry for the {@code activeTopLevelFolderItemFactory} contributions. 026 * 027 * @author Antoine Taillefer 028 * @see FileSystemItemAdapterServiceImpl 029 */ 030public class ActiveTopLevelFolderItemFactoryRegistry extends 031 ContributionFragmentRegistry<ActiveTopLevelFolderItemFactoryDescriptor> { 032 033 private static final Log log = LogFactory.getLog(ActiveTopLevelFolderItemFactoryRegistry.class); 034 035 protected static final String CONTRIBUTION_ID = "activeTopLevelFolderItemFactoriesContrib"; 036 037 protected String activeFactory; 038 039 @Override 040 public String getContributionId(ActiveTopLevelFolderItemFactoryDescriptor contrib) { 041 return CONTRIBUTION_ID; 042 } 043 044 @Override 045 public void contributionUpdated(String id, ActiveTopLevelFolderItemFactoryDescriptor contrib, 046 ActiveTopLevelFolderItemFactoryDescriptor newOrigContrib) { 047 if (log.isTraceEnabled()) { 048 log.trace(String.format("Updating activeTopLevelFolderItemFactory contribution %s.", contrib)); 049 log.trace(String.format("Setting active factory to %s.", contrib.getName())); 050 } 051 activeFactory = contrib.getName(); 052 } 053 054 @Override 055 public void contributionRemoved(String id, ActiveTopLevelFolderItemFactoryDescriptor origContrib) { 056 log.trace("Clearing active factory."); 057 activeFactory = null; 058 } 059 060 @Override 061 public ActiveTopLevelFolderItemFactoryDescriptor clone(ActiveTopLevelFolderItemFactoryDescriptor orig) { 062 if (log.isTraceEnabled()) { 063 log.trace(String.format("Cloning contribution %s.", orig)); 064 } 065 ActiveTopLevelFolderItemFactoryDescriptor clone = new ActiveTopLevelFolderItemFactoryDescriptor(); 066 clone.name = orig.name; 067 return clone; 068 } 069 070 @Override 071 public void merge(ActiveTopLevelFolderItemFactoryDescriptor src, ActiveTopLevelFolderItemFactoryDescriptor dst) { 072 if (log.isTraceEnabled()) { 073 log.trace(String.format("Merging contribution %s to contribution %s.", src, dst)); 074 } 075 if (!StringUtils.isEmpty(src.getName()) && !src.getName().equals(dst.getName())) { 076 dst.setName(src.getName()); 077 } 078 } 079}