package org.jboss.test.security.ejb.project.support;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.naming.Binding;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.spi.DirectoryManager;
public class NameBindingIterator implements NamingEnumeration
{
private Iterator bindings;
private DirContext context;
public NameBindingIterator(Iterator bindings, DirContext context)
{
this.bindings = bindings;
this.context = context;
}
public void close() throws NamingException
{
}
public boolean hasMore() throws NamingException
{
return bindings.hasNext();
}
public Object next() throws NamingException
{
DirBinding binding = (DirBinding) bindings.next();
Object rawObject = binding.getObject();
Name name = new DefaultName(binding.getName());
Hashtable env = context.getEnvironment();
try
{
Object instanceObject = DirectoryManager.getObjectInstance(rawObject,
name, context, env, binding.getAttributes());
binding.setObject(instanceObject);
}
catch(Exception e)
{
NamingException ne = new NamingException("getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
return binding;
}
public boolean hasMoreElements()
{
boolean hasMore = false;
try
{
hasMore = hasMore();
}
catch(NamingException e)
{
}
return hasMore;
}
public Object nextElement()
{
Object next = null;
try
{
next = next();
}
catch(NamingException e)
{
throw new NoSuchElementException(e.toString());
}
return next;
}
}