01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.tools.dbloader;
07:
08: import java.lang.reflect.Constructor;
09:
10: import org.jasig.portal.PortalException;
11: import org.xml.sax.helpers.DefaultHandler;
12:
13: class DataHandlerFactory {
14: private static DataHandlerFactory __instance;
15: private static final String propName = "org.jasig.portal.tools.dbloader.dataHandler.implementation";
16: private static final Class defaultDataHandler = DataHandler.class;
17:
18: public static DataHandlerFactory instance() {
19: if (__instance == null) {
20: __instance = new DataHandlerFactory();
21: }
22: return __instance;
23: }
24:
25: public DefaultHandler getHandler(Configuration config)
26: throws PortalException {
27: Class dataHandlerClass = null;
28: String className = null;
29: try {
30: DefaultHandler dataHandler = null;
31: className = System.getProperty(propName);
32: if (className == null) {
33: dataHandlerClass = defaultDataHandler;
34: } else {
35: dataHandlerClass = Class.forName(className);
36: }
37: Class[] params = { Configuration.class };
38: Object[] args = { config };
39: Constructor constructor = dataHandlerClass
40: .getConstructor(params);
41: dataHandler = (DefaultHandler) constructor
42: .newInstance(args);
43: return dataHandler;
44: } catch (ClassNotFoundException cnfe) {
45: StringBuffer sb = new StringBuffer();
46: sb.append("DataHandlerFactory: Could not instantiate ");
47: sb.append(className);
48: throw new PortalException(sb.toString(), cnfe);
49: } catch (Exception e) {
50: StringBuffer sb = new StringBuffer();
51: sb.append("DataHandlerFactory: Could not instantiate ");
52: sb.append(dataHandlerClass);
53: throw new PortalException(sb.toString(), e);
54: }
55: }
56:
57: DataHandlerFactory() {
58: }
59:
60: }
|