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: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.util;
17:
18: import java.io.Externalizable;
19: import java.io.IOException;
20: import java.io.ObjectInput;
21: import java.io.ObjectOutput;
22: import java.util.Enumeration;
23: import java.util.NoSuchElementException;
24: import java.util.Vector;
25:
26: public final class ArrayEnumeration implements Enumeration,
27: Externalizable {
28: static final long serialVersionUID = -1194966576855523042L;
29:
30: private Object[] elements;
31: private int elementsIndex;
32:
33: public ArrayEnumeration(Vector elements) {
34: this .elements = new Object[elements.size()];
35: elements.copyInto(this .elements);
36: }
37:
38: public ArrayEnumeration(java.util.List list) {
39: this .elements = new Object[list.size()];
40: list.toArray(this .elements);
41: }
42:
43: public ArrayEnumeration() {
44: }
45:
46: public java.lang.Object get(int index) {
47: return elements[index];
48: }
49:
50: public void set(int index, java.lang.Object o) {
51: elements[index] = o;
52: }
53:
54: public int size() {
55: return elements.length;
56: }
57:
58: public boolean hasMoreElements() {
59: return (elementsIndex < elements.length);
60: }
61:
62: public Object nextElement() {
63: if (!hasMoreElements())
64: throw new NoSuchElementException("No more elements exist");
65: return elements[elementsIndex++];
66: }
67:
68: public void writeExternal(ObjectOutput out) throws IOException {
69: out.writeInt(elements.length);
70: out.writeInt(elementsIndex);
71: for (int i = 0; i < elements.length; i++) {
72: out.writeObject(elements[i]);
73: }
74: }
75:
76: public void readExternal(ObjectInput in) throws IOException,
77: ClassNotFoundException {
78: elements = new Object[in.readInt()];
79: elementsIndex = in.readInt();
80: for (int i = 0; i < elements.length; i++) {
81: elements[i] = in.readObject();
82: }
83: }
84:
85: }
|