KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > utils > UploadHandlerFactory


1 package com.sslexplorer.vfs.utils;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
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 JavaDoc handlers;
16     
17     public UploadHandlerFactory() {
18         handlers = new HashMap JavaDoc();
19         handlers.put(RepositoryUploadHandler.TYPE_REPOSITORY, RepositoryUploadHandler.class);
20         handlers.put(ExtensionUploadHandler.TYPE_EXTENSION, ExtensionUploadHandler.class);
21     }
22     
23     public void addHandler(String JavaDoc id, Class JavaDoc 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 JavaDoc type) throws Exception JavaDoc {
35         Class JavaDoc clazz = (Class JavaDoc)handlers.get(type);
36         if(clazz == null) {
37             throw new Exception JavaDoc("No registered upload handler of type " + type + ".");
38         }
39         return (UploadHandler)clazz.newInstance();
40     }
41
42     public void removeHandler(String JavaDoc id) {
43         handlers.remove(id);
44     }
45 }
46
Popular Tags