1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.dom;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.interfaces.IDOMFactory;
30
31 import org.dbforms.util.ReflectionUtil;
32
33
34 /***
35 * abstract class to hide the implemtation details of the various dom
36 * implementations.
37 *
38 * @author Henner Kollmann
39 */
40 public class DOMFactory {
41 private static final ThreadLocal singlePerThread = new ThreadLocal();
42 private static Log logCat = LogFactory.getLog(DOMFactory.class
43 .getName());
44 private static String factoryClass = "org.dbforms.dom.DOMFactoryXALANImpl";
45
46 /***
47 * Creates a new DOMFactory object.
48 */
49 private DOMFactory() {
50 }
51
52 /***
53 * Get the thread singelton instance
54 *
55 * @return a DOMFactory instance per thread
56 */
57 public static IDOMFactory instance() {
58 IDOMFactory fact = (IDOMFactory) singlePerThread.get();
59 if (fact == null) {
60 try {
61 fact = (IDOMFactory) ReflectionUtil.newInstance(factoryClass);
62 } catch (Exception e) {
63 logCat.error("instance", e);
64 }
65
66 if (fact == null) {
67 fact = new DOMFactoryXALANImpl();
68 }
69 singlePerThread.set(fact);
70 }
71 return fact;
72 }
73
74 /***
75 * Sets another dom factory to use.
76 * Must be called before the first call to instance()!!
77 *
78 * @param string
79 */
80 public static void setFactoryClass(String string) {
81 singlePerThread.set(null);
82 factoryClass = string;
83 }
84
85 }