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.util;
25
26 import org.apache.commons.digester.AbstractObjectCreationFactory;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import org.xml.sax.Attributes;
31
32
33
34 /***
35 * ObjectCreationFactory used by Digester to return the instance
36 * of a singleton class.
37 *
38 * @author Luca Fossato
39 * @created 21 november 2002
40 */
41 public class SingletonClassFactoryCreate extends AbstractObjectCreationFactory {
42 /*** logging category */
43 private static Log logCat = LogFactory.getLog(SingletonClassFactoryCreate.class
44 .getName());
45
46 /*** full qualified name of the singleton class to instance */
47 private String className = null;
48
49 /***
50 * EventFactoryCreate constructor.
51 *
52 * @param className the name of the singleton class to instance
53 */
54 public SingletonClassFactoryCreate(String className) {
55 super();
56 setClassName(className);
57 }
58
59 /***
60 * Sets the className attribute of the EventFactoryCreate object
61 *
62 * @param className The new className value
63 */
64 public void setClassName(String className) {
65 this.className = className;
66 }
67
68
69 /***
70 * Gets the className attribute of the EventFactoryCreate object
71 *
72 * @return The className value
73 */
74 public String getClassName() {
75 return className;
76 }
77
78
79 /***
80 * Get the unique instance of the Singleton class.
81 *
82 * @param attributes not used
83 * @return the unique instance of the singleton class
84 * specified by the <code>className</code> member attribute
85 */
86 public Object createObject(Attributes attributes) {
87 Object obj = null;
88
89 try {
90 obj = ReflectionUtil.invoke(className, "instance", null, null);
91 } catch (Exception e) {
92 logCat.error("::createObject - cannot instance the class ["
93 + className + "]", e);
94 }
95
96 return obj;
97 }
98 }