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