001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: CollectionEnum.java 5445 2004-09-17 08:25:02Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.lib;
025:
026: import java.io.Serializable;
027: import java.lang.Object;
028: import java.util.Enumeration;
029: import java.util.NoSuchElementException;
030: import java.util.Vector;
031:
032: /**
033: * This class implements the java.util.Enumeration and the java.io.Serializable interfaces.
034: * <br>
035: * This class is used as the return value type of the implementation of the finder methods
036: * which return a collection.
037: * <br>
038: * Indeed, the EJB spec. tells that the type for a collection is the java.util.Enumeration.
039: * In addition the return value type must be legal type for Java RMI (ie. serializable type).
040: * @author Helene Joanin : Initial developer
041: */
042:
043: public class CollectionEnum implements Serializable, Enumeration {
044:
045: /**
046: * @serial
047: */
048: private Vector mCollection = null;
049: /**
050: * @serial
051: */
052: private int mIndex = 0;
053:
054: /**
055: * Create an empty CollectionEnum
056: *
057: */
058: public CollectionEnum() {
059: mCollection = new Vector();
060: mIndex = 0;
061: }
062:
063: /**
064: * Add an element
065: */
066: public synchronized void addElement(Object obj) {
067: mCollection.addElement(obj);
068: }
069:
070: /**
071: * Create a CollectionEnum from a vector
072: */
073: public CollectionEnum(Vector v) {
074: mCollection = new Vector();
075: for (int i = 0; i < v.size(); i++) {
076: mCollection.addElement(v.elementAt(i));
077: }
078: mIndex = 0;
079: }
080:
081: /**
082: * Implements Enumeration.hasMoreElements()
083: */
084: public boolean hasMoreElements() {
085: return (mIndex < mCollection.size());
086: }
087:
088: /**
089: * Implements Enumeration.nextElement()
090: */
091: public Object nextElement() throws NoSuchElementException {
092: if (mIndex >= mCollection.size()) {
093: throw new NoSuchElementException("CollectionEnum ("
094: + mIndex + ">=" + mCollection.size() + ")");
095: }
096: mIndex++;
097: return (mCollection.elementAt(mIndex - 1));
098: }
099:
100: }
|