01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: /**
20: * @author Vasily Zakharov
21: * @version $Revision: 1.1.2.2 $
22: */package org.apache.harmony.jndi.provider.rmi.registry;
23:
24: import java.rmi.registry.Registry;
25:
26: import java.util.NoSuchElementException;
27:
28: import javax.naming.Name;
29: import javax.naming.NameClassPair;
30: import javax.naming.NamingEnumeration;
31: import javax.naming.NamingException;
32:
33: /**
34: * Enumeration of {@link NameClassPair} objects, used by
35: * {@link RegistryContext#list(Name)} method.
36: */
37: class NameClassPairEnumeration implements
38: NamingEnumeration<NameClassPair> {
39:
40: /**
41: * Binding names returned from {@link Registry#list()} method.
42: */
43: protected final String[] names;
44:
45: /**
46: * Index of the next name to return.
47: */
48: protected int index = 0;
49:
50: /**
51: * Creates this enumeration.
52: *
53: * @param names
54: * Binding names returned from {@link Registry#list()} method.
55: */
56: public NameClassPairEnumeration(String[] names) {
57: this .names = names;
58: }
59:
60: public boolean hasMore() {
61: return (index < names.length);
62: }
63:
64: public NameClassPair next() throws NamingException,
65: NoSuchElementException {
66: if (!hasMore()) {
67: throw new NoSuchElementException();
68: }
69:
70: String name = names[index++];
71: NameClassPair pair = new NameClassPair(name, Object.class
72: .getName());
73: pair.setNameInNamespace(name);
74: return pair;
75: }
76:
77: public boolean hasMoreElements() {
78: return hasMore();
79: }
80:
81: public NameClassPair nextElement() {
82: try {
83: return next();
84: } catch (NamingException e) {
85: throw (NoSuchElementException) new NoSuchElementException()
86: .initCause(e);
87: }
88: }
89:
90: public void close() {
91: index = names.length;
92: }
93:
94: }
|