KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > portable > ObjrefEnumeration


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.ejb.portable;
24
25 import java.util.*;
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * This class is necessary because neither Vector nor Hashtable
30  * return a Serializable Enumeration, which can be sent from the
31  * EJB server back to the client.
32  * This class must be available at the client too, and it could
33  * be instantiated in another vendor's container.
34  *
35  */

36
37 public final class ObjrefEnumeration implements Enumeration, Serializable JavaDoc
38 {
39     private int count=0;
40     private ArrayList objrefs;
41
42     // This is called only by the EJB container in the RI.
43
public void add(Object JavaDoc obj)
44     {
45     if ( objrefs == null )
46         objrefs = new ArrayList();
47     objrefs.add(obj);
48     }
49
50     public boolean hasMoreElements()
51     {
52     if ( objrefs == null )
53         return false;
54     return count < objrefs.size();
55     }
56
57     public Object JavaDoc nextElement()
58     {
59     if ( objrefs != null ) {
60         synchronized (this) {
61         if (count < objrefs.size()) {
62             return objrefs.get(count++);
63         }
64         }
65     }
66     throw new NoSuchElementException("ObjrefEnumeration");
67     }
68 }
69
Popular Tags