1 2 package SOFA.Component; 3 4 8 public class NamedElementRegister extends java.util.Hashtable { 9 10 14 public Object getElementNamed(String name) throws NamingException { 15 Object o = get(name); 16 if (o==null) 17 throw new NamingException("No such name"); 18 return o; 19 } 20 21 26 public void registerElementNamed(String name, Object element) throws NamingException { 27 try { 28 if (containsKey(name)) { 29 throw new NamingException("Duplicated name"); 30 } else { 31 put(name, element); 32 } 33 } catch(Exception e) { 34 throw new NamingException(e.toString()); 35 } 36 } 37 38 43 public void forceRegisterElementNamed(String name, Object element) throws NamingException { 44 try { 45 if (containsKey(name)) 46 remove(name); 47 put(name, element); 48 } catch(Exception e) { 49 throw new NamingException(e.toString()); 50 } 51 } 52 53 57 public void unregisterElementNamed(String name) throws NamingException { 58 try { 59 if (containsKey(name)) 60 remove(name); 61 else 62 throw new NamingException("No such name"); 63 } catch(Exception e) { 64 throw new NamingException(e.toString()); 65 } 66 } 67 68 71 public java.util.Enumeration getAllNames() { 72 return keys(); 73 } 74 } 75 | Popular Tags |