1 package com.sslexplorer.vfs.utils; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import com.sslexplorer.core.RepositoryUploadHandler; 7 import com.sslexplorer.core.UploadHandler; 8 import com.sslexplorer.extensions.ExtensionUploadHandler; 9 10 11 public class UploadHandlerFactory { 12 13 private static UploadHandlerFactory instance; 14 15 private Map handlers; 16 17 public UploadHandlerFactory() { 18 handlers = new HashMap (); 19 handlers.put(RepositoryUploadHandler.TYPE_REPOSITORY, RepositoryUploadHandler.class); 20 handlers.put(ExtensionUploadHandler.TYPE_EXTENSION, ExtensionUploadHandler.class); 21 } 22 23 public void addHandler(String id, Class clazz) { 24 handlers.put(id, clazz); 25 } 26 27 public static UploadHandlerFactory getInstance() { 28 if(instance == null) { 29 instance = new UploadHandlerFactory(); 30 } 31 return instance; 32 } 33 34 public UploadHandler getUploader(String type) throws Exception { 35 Class clazz = (Class )handlers.get(type); 36 if(clazz == null) { 37 throw new Exception ("No registered upload handler of type " + type + "."); 38 } 39 return (UploadHandler)clazz.newInstance(); 40 } 41 42 public void removeHandler(String id) { 43 handlers.remove(id); 44 } 45 } 46 | Popular Tags |