1 5 package com.teamkonzept.lib; 6 7 public class TKClassRegistry { 8 9 TKHashtable registry = new TKHashtable(); 10 TKHashtable cache = new TKHashtable(); 11 12 public TKClassRegistry() 13 { 14 } 15 16 public synchronized void registerClass( String classId, String className ) 17 { 18 String oldEntry = (String ) registry.put( classId, className ); 19 if( !((oldEntry == null) || (oldEntry.equals( className ))) ) { 20 cache.remove( classId ); 21 } 22 } 23 24 public synchronized Object get( String classId ) 25 throws 26 TKUnregisteredClassException, 27 ClassNotFoundException , 28 InstantiationException , 29 IllegalAccessException 30 { 31 Class objectClass = (Class ) cache.get( classId ); 32 if( objectClass == null ) { 33 String className = (String ) registry.get( classId ); 34 if( className == null ) throw new TKUnregisteredClassException(classId); 35 objectClass = Class.forName( className ); 36 cache.put( classId, objectClass ); 37 } 38 39 return objectClass.newInstance(); 40 } 41 42 public Object get( String classId, Object initData ) 43 throws 44 TKUnregisteredClassException, 45 ClassNotFoundException , 46 InstantiationException , 47 IllegalAccessException 48 { 49 Object result = get( classId ); 50 initObject( classId, result, initData ); 51 return result; 52 } 53 54 public void initObject( String classId, Object classObject, Object initData ) 55 throws 56 TKUnregisteredClassException, 57 ClassNotFoundException , 58 InstantiationException , 59 IllegalAccessException 60 {} 61 62 } 63 64 | Popular Tags |