01: /*
02: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/TKClassRegistry.java,v 1.5 2000/05/22 15:01:18 careck Exp $
03: *
04: */
05: package com.teamkonzept.lib;
06:
07: public class TKClassRegistry {
08:
09: TKHashtable registry = new TKHashtable();
10: TKHashtable cache = new TKHashtable();
11:
12: public TKClassRegistry() {
13: }
14:
15: public synchronized void registerClass(String classId,
16: String className) {
17: String oldEntry = (String) registry.put(classId, className);
18: if (!((oldEntry == null) || (oldEntry.equals(className)))) {
19: cache.remove(classId);
20: }
21: }
22:
23: public synchronized Object get(String classId)
24: throws TKUnregisteredClassException,
25: ClassNotFoundException, InstantiationException,
26: IllegalAccessException {
27: Class objectClass = (Class) cache.get(classId);
28: if (objectClass == null) {
29: String className = (String) registry.get(classId);
30: if (className == null)
31: throw new TKUnregisteredClassException(classId);
32: objectClass = Class.forName(className);
33: cache.put(classId, objectClass);
34: }
35:
36: return objectClass.newInstance();
37: }
38:
39: public Object get(String classId, Object initData)
40: throws TKUnregisteredClassException,
41: ClassNotFoundException, InstantiationException,
42: IllegalAccessException {
43: Object result = get(classId);
44: initObject(classId, result, initData);
45: return result;
46: }
47:
48: public void initObject(String classId, Object classObject,
49: Object initData) throws TKUnregisteredClassException,
50: ClassNotFoundException, InstantiationException,
51: IllegalAccessException {
52: }
53:
54: }
|