1 22 package org.jboss.net.protocol; 23 24 import java.net.URL ; 25 import java.net.MalformedURLException ; 26 import java.util.HashMap ; 27 28 public class URLListerFactory { 29 private static HashMap defaultClasses = new HashMap (); 30 static { 31 defaultClasses.put("file", "org.jboss.net.protocol.file.FileURLLister"); 32 defaultClasses.put("http", "org.jboss.net.protocol.http.DavURLLister"); 33 defaultClasses.put("https", "org.jboss.net.protocol.http.DavURLLister"); 34 } 35 36 private HashMap classes; 37 38 42 public URLListerFactory() { 43 classes = (HashMap ) defaultClasses.clone(); 44 } 45 46 52 public URLLister createURLLister(URL url) throws MalformedURLException { 53 return createURLLister(url.getProtocol()); 54 } 55 56 62 public URLLister createURLLister(String protocol) throws MalformedURLException { 63 try { 64 String className = (String ) classes.get(protocol); 65 if (className == null) { 66 throw new MalformedURLException ("No lister class defined for protocol "+protocol); 67 } 68 69 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className); 70 return (URLLister) clazz.newInstance(); 71 } catch (ClassNotFoundException e) { 72 throw new MalformedURLException (e.getMessage()); 73 } catch (InstantiationException e) { 74 throw new MalformedURLException (e.getMessage()); 75 } catch (IllegalAccessException e) { 76 throw new MalformedURLException (e.getMessage()); 77 } 78 } 79 80 85 public void registerListener(String protocol, String className) { 86 classes.put(protocol, className); 87 } 88 } 89 | Popular Tags |