001/* 002 * (C) Copyright 2012 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.FileSystemItemAdapterService; 029import org.nuxeo.drive.service.TopLevelFolderItemFactory; 030 031/** 032 * XMap descriptor for factories contributed to the {@code topLevelFolderItemFactory} extension point of the 033 * {@link FileSystemItemAdapterService}. 034 * 035 * @author Antoine Taillefer 036 */ 037@XObject("topLevelFolderItemFactory") 038public class TopLevelFolderItemFactoryDescriptor implements Serializable { 039 040 private static final long serialVersionUID = -7837197812448232426L; 041 042 @XNode("@class") 043 protected Class<? extends TopLevelFolderItemFactory> factoryClass; 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 TopLevelFolderItemFactory getFactory() throws InstantiationException, IllegalAccessException { 049 TopLevelFolderItemFactory factory = factoryClass.newInstance(); 050 factory.setName(factory.getClass().getName()); 051 factory.handleParameters(parameters); 052 return factory; 053 } 054 055 public Class<? extends TopLevelFolderItemFactory> getFactoryClass() { 056 return factoryClass; 057 } 058 059 public void setFactoryClass(Class<? extends TopLevelFolderItemFactory> factoryClass) { 060 this.factoryClass = factoryClass; 061 } 062 063 public Map<String, String> getParameters() { 064 return parameters; 065 } 066 067 public String getparameter(String name) { 068 return parameters.get(name); 069 } 070 071 public void setParameters(Map<String, String> parameters) { 072 this.parameters = parameters; 073 } 074 075 public void setParameter(String name, String value) { 076 parameters.put(name, value); 077 } 078 079 public String getName() { 080 return factoryClass.getName(); 081 } 082 083 @Override 084 public boolean equals(Object obj) { 085 if (this == obj) { 086 return true; 087 } 088 if (!(obj instanceof TopLevelFolderItemFactoryDescriptor)) { 089 return false; 090 } 091 return this.factoryClass.getName().equals(((TopLevelFolderItemFactoryDescriptor) obj).factoryClass.getName()); 092 } 093 094 @Override 095 public int hashCode() { 096 return factoryClass.getName().hashCode(); 097 } 098 099}