blob: 79c273423996b448fed61cd822c1b3d72b19548a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*
* Oreka -- A media capture and retrieval platform
*
* Copyright (C) 2005, orecx LLC
*
* http://www.orecx.com
*
* This program is free software, distributed under the terms of
* the GNU General Public License.
* Please refer to http://www.gnu.org/copyleft/gpl.html
*
*/
package net.sf.oreka;
/**
* The ObjectFactory can be used to instanciate Objects based on class name.
* All existing Objects must be registered to the ObjectFactory at startup.
*/
public class OrkObjectFactory {
static OrkObjectFactory instance = null;
java.util.HashMap<String, OrkObject> classes;
private OrkObjectFactory()
{
classes = new java.util.HashMap<String, OrkObject>();
}
public static OrkObjectFactory instance()
{
if(instance == null)
{
instance = new OrkObjectFactory();
}
return instance;
}
public OrkObject newOrkObject(String className) throws OrkException
{
className = className.toLowerCase();
OrkObject classObject = classes.get(className);
OrkObject newInstance = null;
if(classObject != null)
{
try
{
newInstance = classObject.getClass().newInstance();
}
catch (Exception e)
{
throw new OrkException("OrkObjectFactory: Could not instanciate:" + className);
}
}
else
{
throw new OrkException("OrkObjectFactory: class does not exist:" + className);
}
return newInstance;
}
public void registerOrkObject(OrkObject object)
{
classes.put(object.getOrkClassName(), object);
}
}
|