View Javadoc

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;
9   
10  import java.util.NoSuchElementException;
11  import javax.naming.Binding;
12  import javax.naming.Context;
13  import javax.naming.NamingException;
14  
15  /***
16   * Class for building NamingEnumerations.
17   *
18   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
19   * @version $Revision: 1.2 $
20   */
21  final class ArrayNamingEnumeration
22      extends AbstractNamingEnumeration
23  {
24      protected Object[]   m_items;
25      protected int        m_index;
26  
27      public ArrayNamingEnumeration( final Context owner,
28                                     final Namespace namespace,
29                                     final Object[] 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 next()
42          throws NamingException
43      {
44          if( !hasMore() ) throw new NoSuchElementException();
45  
46  
47          final Object object = m_items[ m_index++ ];
48  
49          if( object instanceof Binding )
50          {
51              final Binding binding = (Binding)object;
52              final Object resolvedObject = resolve( binding.getName(), binding.getObject() );
53              binding.setObject( resolvedObject );
54          }
55  
56          return object;
57      }
58  
59      public void close()
60      {
61          super.close();
62          m_items = null;
63      }
64  }