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