1 package jodd.bean; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.Map; 6 7 import jodd.bean.loaders.MapLoader; 8 import jodd.bean.loaders.MultipartRequestLoader; 9 import jodd.bean.loaders.RequestLoader; 10 import jodd.bean.loaders.ResultSetLoader; 11 12 28 public class LoadersManager { 29 30 32 private static HashMap loaders = new HashMap(); 33 34 39 public static Map getMap() { 40 return loaders; 41 } 42 43 static { 44 registerDefaults(); 45 } 46 47 57 public static void registerDefaults() { 58 loaders.clear(); 59 register(java.util.Map.class, new MapLoader()); 60 register(java.sql.ResultSet.class, new ResultSetLoader()); 61 try { 62 Class.forName("javax.servlet.http.HttpServletRequest"); 63 register(javax.servlet.http.HttpServletRequest.class, new RequestLoader()); 64 register(jodd.servlet.MultipartRequest.class, new MultipartRequestLoader()); 65 } catch (ClassNotFoundException cnfex) { 66 } 67 } 68 69 77 public static void register(Class key, Loader load) { 78 loaders.put(key, load); 79 } 80 81 82 90 public static Loader get(Class key) { 91 return (Loader) loaders.get(key); 92 } 93 94 96 104 public static Loader get(Object obj) { 105 Class objclass = obj.getClass(); 106 Loader load = LoadersManager.get(objclass); 107 if (load == null) { Iterator it = LoadersManager.getMap().keySet().iterator(); 109 while (it.hasNext()) { 110 Class key = (Class) it.next(); 111 if (key.isInstance(obj)) { 112 load = LoadersManager.get(key); 113 break; 114 } 115 } 116 } 117 return load; 118 } 119 120 121 122 123 124 125 } 126 | Popular Tags |