KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > ejb > project > support > NameBindingIterator


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.ejb.project.support;
23
24 import java.util.Hashtable JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import javax.naming.Binding JavaDoc;
28 import javax.naming.Name JavaDoc;
29 import javax.naming.NamingEnumeration JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31 import javax.naming.directory.DirContext JavaDoc;
32 import javax.naming.spi.DirectoryManager JavaDoc;
33
34 /** An implementation of NamingEnumeration for listing the Bindings
35  in a context. It accepts an Iterator of DirBindings and transforms
36  the raw object and attributes into the output object using the
37  DirectoryManager.getObjectInstance method.
38
39 @see DirBinding
40 @see DirectoryManager.getObjectInstance(Object,Name,Context,Hashtable,Attributes)
41
42 @author Scott_Stark@displayscape.com
43 @version $Id: NameBindingIterator.java 37406 2005-10-29 23:41:24Z starksm $
44 */

45 public class NameBindingIterator implements NamingEnumeration JavaDoc
46 {
47     private Iterator JavaDoc bindings;
48     private DirContext JavaDoc context;
49
50     /** Creates new NameBindingIterator for enumerating a list of Bindings.
51      *@param names, an Iterator of DirBindings for the raw context bindings.
52      * This is the name and raw object data/attributes that should be input into
53      * DirectoryManager.getObjectInstance().
54      */

55     public NameBindingIterator(Iterator JavaDoc bindings, DirContext JavaDoc context)
56     {
57         this.bindings = bindings;
58         this.context = context;
59     }
60
61     public void close() throws NamingException JavaDoc
62     {
63     }
64
65     public boolean hasMore() throws NamingException JavaDoc
66     {
67         return bindings.hasNext();
68     }
69
70     public Object JavaDoc next() throws NamingException JavaDoc
71     {
72         DirBinding binding = (DirBinding) bindings.next();
73         Object JavaDoc rawObject = binding.getObject();
74         Name JavaDoc name = new DefaultName(binding.getName());
75         Hashtable JavaDoc env = context.getEnvironment();
76         try
77         {
78             Object JavaDoc instanceObject = DirectoryManager.getObjectInstance(rawObject,
79                 name, context, env, binding.getAttributes());
80             binding.setObject(instanceObject);
81         }
82         catch(Exception JavaDoc e)
83         {
84             NamingException JavaDoc ne = new NamingException JavaDoc("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 JavaDoc e)
99         {
100         }
101         return hasMore;
102     }
103     
104     public Object JavaDoc nextElement()
105     {
106         Object JavaDoc next = null;
107         try
108         {
109             next = next();
110         }
111         catch(NamingException JavaDoc e)
112         {
113             throw new NoSuchElementException JavaDoc(e.toString());
114         }
115         return next;
116     }
117 }
118
Popular Tags