01: /*
02: * Created on Feb 13, 2004
03: */
04: package uk.org.ponder.saxalizer.mapping;
05:
06: import java.util.HashMap;
07:
08: /**
09: * Managing the mapping of nicknames of polymorphic classes using the
10: * "tagname*" scheme in SAXAccessMethodSpecs and the 'type="nickname"'
11: * attribute, and also allows type of object to be determined based
12: * on root tag type.
13: *
14: * @author Bosmon
15: */
16: public class ClassNameManager {
17: private HashMap forwardnick = new HashMap();
18: private HashMap backwardnick = new HashMap();
19: private static ClassNameManager instance = new ClassNameManager();
20:
21: public static ClassNameManager instance() {
22: return instance;
23: }
24:
25: public void registerClass(String nickname, Class clazz) {
26: Class previous = (Class) forwardnick.get(nickname);
27: if (previous != null && !previous.equals(clazz)) {
28: throw new IllegalArgumentException("Nickname " + nickname
29: + " is already registered to class "
30: + forwardnick.get(nickname));
31: }
32: forwardnick.put(nickname, clazz);
33: backwardnick.put(clazz, nickname);
34: }
35:
36: public Class findClazz(String classname) {
37: return (Class) forwardnick.get(classname);
38: }
39:
40: public String getClassName(Class clazz) {
41: return (String) backwardnick.get(clazz);
42: }
43: }
|