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