KickJava   Java API By Example, From Geeks To Geeks.

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


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.Context JavaDoc;
12 import javax.naming.Name JavaDoc;
13 import javax.naming.NamingEnumeration JavaDoc;
14 import javax.naming.NamingException JavaDoc;
15
16 /**
17  * Class for building NamingEnumerations.
18  *
19  * @author Peter Donald
20  * @version $Revision: 1.1 $
21  */

22 public abstract class AbstractNamingEnumeration
23     implements NamingEnumeration JavaDoc
24 {
25     private Context JavaDoc m_owner;
26     private Namespace m_namespace;
27
28     public AbstractNamingEnumeration( final Context JavaDoc owner, final Namespace namespace )
29     {
30         m_owner = owner;
31         m_namespace = namespace;
32     }
33
34     public boolean hasMore()
35         throws NamingException JavaDoc
36     {
37         return hasMoreElements();
38     }
39
40     public Object JavaDoc nextElement()
41     {
42         try
43         {
44             return next();
45         }
46         catch( final NamingException JavaDoc ne )
47         {
48             throw new NoSuchElementException JavaDoc( ne.toString() );
49         }
50     }
51
52     protected Object JavaDoc resolve( final String JavaDoc name, final Object JavaDoc object )
53         throws NamingException JavaDoc
54     {
55         // Call getObjectInstance for using any object factories
56
try
57         {
58             final Name JavaDoc atom = m_owner.getNameParser( name ).parse( name );
59             return m_namespace.
60                 getObjectInstance( object, atom, m_owner, m_owner.getEnvironment() );
61         }
62         catch( final Exception JavaDoc e )
63         {
64             final NamingException JavaDoc ne = new NamingException JavaDoc( "getObjectInstance failed" );
65             ne.setRootCause( e );
66             throw ne;
67         }
68     }
69
70     public void close()
71     {
72         m_namespace = null;
73         m_owner = null;
74     }
75 }
76
Popular Tags