| 1 7 package winstone.jndi; 8 9 import java.util.Arrays ; 10 import java.util.Enumeration ; 11 import java.util.Map ; 12 import java.util.Vector ; 13 14 import javax.naming.NameClassPair ; 15 import javax.naming.NamingEnumeration ; 16 import javax.naming.NamingException ; 17 18 25 public class WinstoneNameEnumeration implements NamingEnumeration { 26 private Enumeration nameEnumeration; 27 28 31 public WinstoneNameEnumeration(Map bindings) { 32 Object keys[] = bindings.keySet().toArray(); 33 Arrays.sort(keys); 34 Vector nameClassPairs = new Vector (); 35 for (int n = 0; n < keys.length; n++) 36 nameClassPairs.add(new NameClassPair ((String ) keys[n], bindings 37 .get(keys[n]).getClass().getName())); 38 this.nameEnumeration = nameClassPairs.elements(); 39 } 40 41 public void close() throws NamingException { 42 this.nameEnumeration = null; 43 } 44 45 public boolean hasMore() throws NamingException { 46 if (this.nameEnumeration == null) 47 throw new NamingException (ContainerJNDIManager.JNDI_RESOURCES 48 .getString("WinstoneNameEnumeration.AlreadyClosed")); 49 else 50 return this.nameEnumeration.hasMoreElements(); 51 } 52 53 public Object next() throws NamingException { 54 if (hasMore()) 55 return this.nameEnumeration.nextElement(); 56 else 57 return null; 58 } 59 60 public boolean hasMoreElements() { 61 try { 62 return hasMore(); 63 } catch (NamingException err) { 64 return false; 65 } 66 } 67 68 public Object nextElement() { 69 try { 70 return next(); 71 } catch (NamingException err) { 72 return null; 73 } 74 } 75 76 } 77 | Popular Tags |