001/* 002 * (C) Copyright 2015 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 java.io.Serializable; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeMap; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.drive.service.FileSystemChangeFinder; 029import org.nuxeo.drive.service.NuxeoDriveManager; 030 031/** 032 * XMap descriptor for contributions to the {@code changeFinder} extension point of the {@link NuxeoDriveManager}. 033 * 034 * @author Antoine Taillefer 035 * @since 7.3 036 */ 037@XObject("changeFinder") 038public class ChangeFinderDescriptor implements Serializable { 039 040 private static final long serialVersionUID = 1L; 041 042 @XNode("@class") 043 protected Class<? extends FileSystemChangeFinder> changeFinderClass; 044 045 @XNodeMap(value = "parameters/parameter", key = "@name", type = HashMap.class, componentType = String.class) 046 protected Map<String, String> parameters = new HashMap<String, String>(); 047 048 public FileSystemChangeFinder getChangeFinder() throws InstantiationException, IllegalAccessException { 049 FileSystemChangeFinder changeFinder = changeFinderClass.newInstance(); 050 changeFinder.handleParameters(parameters); 051 return changeFinder; 052 } 053 054 public Class<? extends FileSystemChangeFinder> getChangeFinderClass() { 055 return changeFinderClass; 056 } 057 058 public void setChangeFinderClass(Class<? extends FileSystemChangeFinder> changeFinderClass) { 059 this.changeFinderClass = changeFinderClass; 060 } 061 062 public Map<String, String> getParameters() { 063 return parameters; 064 } 065 066 public void setParameters(Map<String, String> parameters) { 067 this.parameters = parameters; 068 } 069 070 public String getparameter(String name) { 071 return parameters.get(name); 072 } 073 074 public void setParameter(String name, String value) { 075 parameters.put(name, value); 076 } 077 078 @Override 079 public boolean equals(Object obj) { 080 if (this == obj) { 081 return true; 082 } 083 if (!(obj instanceof ChangeFinderDescriptor)) { 084 return false; 085 } 086 return changeFinderClass.getName().equals(((ChangeFinderDescriptor) obj).changeFinderClass.getName()); 087 } 088 089 @Override 090 public int hashCode() { 091 return changeFinderClass.getName().hashCode(); 092 } 093 094 @Override 095 public String toString() { 096 return changeFinderClass.getName(); 097 } 098 099}