1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.search;
18
19
20 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 /***
28 * Search object handler factory
29 *
30 * @author <a href="morciuch@apache.org">Mark Orciuch</a>
31 *
32 * @version $Id: HandlerFactory.java,v 1.4 2004/02/23 03:48:47 jford Exp $
33 */
34 public class HandlerFactory
35 {
36 private static final Map handlerCache = Collections.synchronizedMap(new HashMap());
37
38 /***
39 * Returns parsed object handler for specific object
40 *
41 * @param obj
42 * @return
43 */
44 public static ObjectHandler getHandler(Object obj) throws Exception
45 {
46 return getHandler(obj.getClass().getName());
47
48 }
49
50 /***
51 * Returns parsed object handler for specific object
52 *
53 * @param obj
54 * @return
55 */
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
79
80 return handler;
81 }
82 }