1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.naming;
20
21 import java.util.Iterator;
22
23 import javax.naming.NameClassPair;
24 import javax.naming.NamingEnumeration;
25 import javax.naming.NamingException;
26
27 /**
28  * Naming enumeration implementation.
29  *
30  * @author Remy Maucherat
31  */

32 public class NamingContextEnumeration
33     implements NamingEnumeration<NameClassPair> {
34
35
36     // ----------------------------------------------------------- Constructors
37
38
39     public NamingContextEnumeration(Iterator<NamingEntry> entries) {
40         iterator = entries;
41     }
42
43
44     // -------------------------------------------------------------- Variables
45
46
47     /**
48      * Underlying enumeration.
49      */

50     protected final Iterator<NamingEntry> iterator;
51
52
53     // --------------------------------------------------------- Public Methods
54
55
56     /**
57      * Retrieves the next element in the enumeration.
58      */

59     @Override
60     public NameClassPair next()
61         throws NamingException {
62         return nextElement();
63     }
64
65
66     /**
67      * Determines whether there are any more elements in the enumeration.
68      */

69     @Override
70     public boolean hasMore()
71         throws NamingException {
72         return iterator.hasNext();
73     }
74
75
76     /**
77      * Closes this enumeration.
78      */

79     @Override
80     public void close()
81         throws NamingException {
82     }
83
84
85     @Override
86     public boolean hasMoreElements() {
87         return iterator.hasNext();
88     }
89
90
91     @Override
92     public NameClassPair nextElement() {
93         NamingEntry entry = iterator.next();
94         return new NameClassPair(entry.name, entry.value.getClass().getName());
95     }
96
97
98 }
99
100