1 22 package org.jboss.test.security.ejb.project.support; 23 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.NoSuchElementException ; 27 import javax.naming.Binding ; 28 import javax.naming.Name ; 29 import javax.naming.NamingEnumeration ; 30 import javax.naming.NamingException ; 31 import javax.naming.directory.DirContext ; 32 import javax.naming.spi.DirectoryManager ; 33 34 45 public class NameBindingIterator implements NamingEnumeration 46 { 47 private Iterator bindings; 48 private DirContext context; 49 50 55 public NameBindingIterator(Iterator bindings, DirContext context) 56 { 57 this.bindings = bindings; 58 this.context = context; 59 } 60 61 public void close() throws NamingException 62 { 63 } 64 65 public boolean hasMore() throws NamingException 66 { 67 return bindings.hasNext(); 68 } 69 70 public Object next() throws NamingException 71 { 72 DirBinding binding = (DirBinding) bindings.next(); 73 Object rawObject = binding.getObject(); 74 Name name = new DefaultName(binding.getName()); 75 Hashtable env = context.getEnvironment(); 76 try 77 { 78 Object instanceObject = DirectoryManager.getObjectInstance(rawObject, 79 name, context, env, binding.getAttributes()); 80 binding.setObject(instanceObject); 81 } 82 catch(Exception e) 83 { 84 NamingException ne = new NamingException ("getObjectInstance failed"); 85 ne.setRootCause(e); 86 throw ne; 87 } 88 return binding; 89 } 90 91 public boolean hasMoreElements() 92 { 93 boolean hasMore = false; 94 try 95 { 96 hasMore = hasMore(); 97 } 98 catch(NamingException e) 99 { 100 } 101 return hasMore; 102 } 103 104 public Object nextElement() 105 { 106 Object next = null; 107 try 108 { 109 next = next(); 110 } 111 catch(NamingException e) 112 { 113 throw new NoSuchElementException (e.toString()); 114 } 115 return next; 116 } 117 } 118 | Popular Tags |