1 /*
2 * Copyright (C) The Apache Software Foundation. All rights reserved.
3 *
4 * This software is published under the terms of the Apache Software License
5 * version 1.1, a copy of which has been included with this distribution in
6 * the LICENSE file.
7 */
8 package org.apache.avalon.excalibur.naming.memory;
9
10 import java.util.Hashtable;
11 import java.util.Iterator;
12 import java.util.NoSuchElementException;
13 import javax.naming.Binding;
14 import javax.naming.Context;
15 import javax.naming.NameClassPair;
16 import javax.naming.NamingException;
17 import org.apache.avalon.excalibur.naming.AbstractNamingEnumeration;
18 import org.apache.avalon.excalibur.naming.Namespace;
19
20 /***
21 * Class for building NamingEnumerations.
22 *
23 * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
24 * @version $Revision: 1.2 $
25 */
26 final class MemoryNamingEnumeration
27 extends AbstractNamingEnumeration
28 {
29 protected Hashtable m_bindings;
30 protected Iterator m_names;
31 protected boolean m_returnBindings;
32
33 public MemoryNamingEnumeration( final Context owner,
34 final Namespace namespace,
35 final Hashtable bindings,
36 final boolean returnBindings )
37 {
38 super( owner, namespace );
39 m_returnBindings = returnBindings;
40 m_bindings = bindings;
41 m_names = m_bindings.keySet().iterator();
42 }
43
44 public boolean hasMoreElements()
45 {
46 return m_names.hasNext();
47 }
48
49 public Object next()
50 throws NamingException
51 {
52 if( !hasMore() ) throw new NoSuchElementException();
53
54 final String name = (String)m_names.next();
55 Object object = m_bindings.get( name );
56
57 if( !m_returnBindings )
58 {
59 return new NameClassPair( name, object.getClass().getName() );
60 }
61 else
62 {
63 return new Binding( name, resolve( name, object ) );
64 }
65 }
66
67 public void close()
68 {
69 super.close();
70 m_bindings = null;
71 }
72 }
This page was automatically generated by Maven