1 5 6 14 15 package org.joseki.server; 16 17 import java.util.* ; 18 19 public class Registry 20 { 21 static Registry registryRegistry = 22 createRegistry("Registry", Registry.class) ; 23 24 public static Registry getRegistry(String name) 25 { 26 return (Registry)registryRegistry.get(name) ; 27 } 28 29 public static Registry createRegistry(String regName, Class objClass) 30 { 31 Registry reg = new Registry(regName, objClass) ; 32 registryRegistry.add(regName, reg) ; 33 return reg ; 34 } 35 36 Class objectClass ; 37 Map registry = new HashMap() ; 38 39 Registry(String regName, Class objClass) 40 { 41 objectClass = objClass ; 42 } 43 44 public void add(String name, Object object) 45 { 46 if ( object.getClass().equals(objectClass) ) 47 { 48 registry.put(name,object) ; 49 return ; 50 } 51 throw new RuntimeException ("Registry: wrong type: "+object.getClass().getName()+" [expected "+objectClass.getName()+"]") ; 52 } 53 54 public Object get(String name) 56 { 57 return registry.get(name) ; 58 } 59 60 public Iterator registeredNames() 61 { 62 return registry.keySet().iterator() ; 63 } 64 65 public Iterator registeredObjects() 66 { 67 return registry.values().iterator() ; 68 } 69 70 public void remove(String name) 71 { 72 registry.remove(name) ; 73 } 74 } 75 76 77 103 104 | Popular Tags |