1 16 17 package org.apache.jetspeed.services.search; 18 19 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import org.apache.turbine.services.resources.ResourceService; 25 import org.apache.turbine.services.TurbineServices; 26 27 34 public class HandlerFactory 35 { 36 private static final Map handlerCache = Collections.synchronizedMap(new HashMap ()); 37 38 44 public static ObjectHandler getHandler(Object obj) throws Exception 45 { 46 return getHandler(obj.getClass().getName()); 47 48 } 49 50 56 public static ObjectHandler getHandler(String className) throws Exception 57 { 58 ObjectHandler handler = null; 59 60 if(handlerCache.containsKey(className)) 61 { 62 handler = (ObjectHandler)handlerCache.get(className); 63 } 64 else 65 { 66 ResourceService serviceConf = ((TurbineServices) TurbineServices.getInstance()) 67 .getResources(SearchService.SERVICE_NAME); 68 String handlerClass = serviceConf.getString("document." + className); 69 70 if (handlerClass == null) 71 { 72 throw new Exception ("No handler was found for document type: " + className); 73 } 74 75 handler = (ObjectHandler) Class.forName(handlerClass).newInstance(); 76 handlerCache.put(className, handler); 77 } 78 80 return handler; 81 } 82 } 83 | Popular Tags |