01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.client;
18:
19: import java.util.Enumeration;
20: import java.util.Vector;
21: import java.util.NoSuchElementException;
22: import java.io.Externalizable;
23: import java.io.ObjectOutput;
24: import java.io.IOException;
25: import java.io.ObjectInput;
26:
27: /**
28: * @version $Revision: 450758 $ $Date: 2006-09-28 01:40:18 -0700 $
29: */
30: public final class ArrayEnumeration implements Enumeration,
31: Externalizable {
32: static final long serialVersionUID = -1194966576855523042L;
33:
34: private Object[] elements;
35: private int elementsIndex;
36:
37: public ArrayEnumeration(Vector elements) {
38: this .elements = new Object[elements.size()];
39: elements.copyInto(this .elements);
40: }
41:
42: public ArrayEnumeration(java.util.List list) {
43: this .elements = new Object[list.size()];
44: list.toArray(this .elements);
45: }
46:
47: public ArrayEnumeration() {
48: }
49:
50: public Object get(int index) {
51: return elements[index];
52: }
53:
54: public void set(int index, Object o) {
55: elements[index] = o;
56: }
57:
58: public int size() {
59: return elements.length;
60: }
61:
62: public boolean hasMoreElements() {
63: return (elementsIndex < elements.length);
64: }
65:
66: public Object nextElement() {
67: if (!hasMoreElements())
68: throw new NoSuchElementException("No more elements exist");
69: return elements[elementsIndex++];
70: }
71:
72: public void writeExternal(ObjectOutput out) throws IOException {
73: out.writeInt(elements.length);
74: out.writeInt(elementsIndex);
75: for (int i = 0; i < elements.length; i++) {
76: out.writeObject(elements[i]);
77: }
78: }
79:
80: public void readExternal(ObjectInput in) throws IOException,
81: ClassNotFoundException {
82: elements = new Object[in.readInt()];
83: elementsIndex = in.readInt();
84: for (int i = 0; i < elements.length; i++) {
85: elements[i] = in.readObject();
86: }
87: }
88:
89: }
|