KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > util > SingletonClassFactoryCreate


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/util/SingletonClassFactoryCreate.java,v 1.4 2004/08/18 12:26:09 hkollmann Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/18 12:26:09 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 JavaDoc;
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 JavaDoc className = null;
48
49    /**
50     * EventFactoryCreate constructor.
51     *
52     * @param className the name of the singleton class to instance
53     */

54    public SingletonClassFactoryCreate(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc createObject(Attributes JavaDoc attributes) {
87       Object JavaDoc obj = null;
88
89       try {
90          obj = ReflectionUtil.invoke(className, "instance", null, null);
91       } catch (Exception JavaDoc e) {
92          logCat.error("::createObject - cannot instance the class ["
93                       + className + "]", e);
94       }
95
96       return obj;
97    }
98 }
99
Popular Tags