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