KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > jndikit > ArrayNamingEnumeration


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.jndikit;
9
10 import java.util.NoSuchElementException JavaDoc;
11 import javax.naming.Binding JavaDoc;
12 import javax.naming.Context JavaDoc;
13 import javax.naming.NamingException JavaDoc;
14
15 /**
16  * Class for building NamingEnumerations.
17  *
18  * @author Peter Donald
19  * @version $Revision: 1.1 $
20  */

21 final class ArrayNamingEnumeration
22     extends AbstractNamingEnumeration
23 {
24     protected Object JavaDoc[] m_items;
25     protected int m_index;
26
27     public ArrayNamingEnumeration( final Context JavaDoc owner,
28                                    final Namespace namespace,
29                                    final Object JavaDoc[] items )
30     {
31         super( owner, namespace );
32         m_items = items;
33         //m_index = 0;
34
}
35
36     public boolean hasMoreElements()
37     {
38         return m_index < m_items.length;
39     }
40
41     public Object JavaDoc next()
42         throws NamingException JavaDoc
43     {
44         if( !hasMore() )
45         {
46             throw new NoSuchElementException JavaDoc();
47         }
48
49         final Object JavaDoc object = m_items[ m_index++ ];
50
51         if( object instanceof Binding JavaDoc )
52         {
53             final Binding JavaDoc binding = (Binding JavaDoc)object;
54             final Object JavaDoc resolvedObject = resolve( binding.getName(), binding.getObject() );
55             binding.setObject( resolvedObject );
56         }
57
58         return object;
59     }
60
61     public void close()
62     {
63         super.close();
64         m_items = null;
65     }
66 }
67
Popular Tags