01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.xwork.util;
06:
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09: import com.opensymphony.util.ClassLoaderUtil;
10:
11: /**
12: * Factory for getting an instance of {@link ObjectTypeDeterminer}.
13: * <p/>
14: * In WebWork this factory is used to instantiate a JDK5 generics compatible factory.
15: * <br/>
16: * Will use <code>com.opensymphony.xwork.util.GenericsObjectTypeDeterminer</code> if running on JDK5 or higher.
17: * If not <code>com.opensymphony.xwork.util.ObjectTypeDeterminer</code> is used.
18: *
19: * @author plightbo
20: * @author Rainer Hermanns
21: */
22: public class ObjectTypeDeterminerFactory {
23: private static final Log LOG = LogFactory
24: .getLog(ObjectTypeDeterminerFactory.class);
25:
26: private static ObjectTypeDeterminer instance = new DefaultObjectTypeDeterminer();
27:
28: static {
29: try {
30: Class c = ClassLoaderUtil
31: .loadClass(
32: "com.opensymphony.xwork.util.GenericsObjectTypeDeterminer",
33: ObjectTypeDeterminerFactory.class);
34:
35: LOG
36: .info("Detected GenericsObjectTypeDeterminer, initializing it...");
37: instance = (ObjectTypeDeterminer) c.newInstance();
38: } catch (ClassNotFoundException e) {
39: // this is fine, just fall back to the default object type determiner
40: } catch (Exception e) {
41: LOG
42: .error(
43: "Exception when trying to create new GenericsObjectTypeDeterminer",
44: e);
45: }
46: }
47:
48: public static void setInstance(ObjectTypeDeterminer instance) {
49: ObjectTypeDeterminerFactory.instance = instance;
50: }
51:
52: public static ObjectTypeDeterminer getInstance() {
53: return instance;
54: }
55: }
|