KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > pcosnaming > PersistentBindingIterator


1 /*
2  * @(#)PersistentBindingIterator.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * @(#)TransientBindingIterator.java 1.36 99/07/16
9  *
10  * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
11  * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
12  *
13  * This software is the confidential and proprietary information of Sun
14  * Microsystems, Inc. ("Confidential Information"). You shall not
15  * disclose such Confidential Information and shall use it only in
16  * accordance with the terms of the license agreement you entered into
17  * with Sun.
18  *
19  * CopyrightVersion 1.2
20  *
21  */

22
23 package com.sun.corba.se.impl.naming.pcosnaming;
24
25 // Import general CORBA classes
26
import org.omg.CORBA.SystemException JavaDoc;
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.CORBA.INTERNAL JavaDoc;
29
30 // Get org.omg.CosNaming Types
31
import org.omg.CosNaming.Binding JavaDoc;
32 import org.omg.CosNaming.BindingType JavaDoc;
33 import org.omg.CosNaming.BindingTypeHolder JavaDoc;
34 import org.omg.CosNaming.NameComponent JavaDoc;
35 import org.omg.PortableServer.POA JavaDoc;
36
37 // Get base implementation
38
import com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl;
39 import com.sun.corba.se.impl.naming.pcosnaming.InternalBindingValue;
40
41 import com.sun.corba.se.impl.naming.cosnaming.BindingIteratorImpl;
42
43 // Get a hash table
44
import java.util.Hashtable JavaDoc;
45 import java.util.Enumeration JavaDoc;
46
47 /**
48  * Class TransientBindingIterator implements the abstract methods
49  * defined by BindingIteratorImpl, to use with the TransientNamingContext
50  * implementation of the NamingContextImpl. The TransientBindingIterator
51  * implementation receives a hash table of InternalBindingValues, and uses
52  * an Enumeration to iterate over the contents of the hash table.
53  * @see BindingIteratorImpl
54  * @see TransientNamingContext
55  */

56 public class PersistentBindingIterator extends BindingIteratorImpl
57 {
58     private POA JavaDoc biPOA;
59     /**
60      * Constructs a new PersistentBindingIterator object.
61      * @param orb a org.omg.CORBA.ORB object.
62      * @param aTable A hashtable containing InternalBindingValues which is
63      * the content of the PersistentNamingContext.
64      * @param java.lang.Exception a Java exception.
65      * @exception Exception a Java exception thrown of the base class cannot
66      * initialize.
67    */

68     public PersistentBindingIterator(org.omg.CORBA.ORB JavaDoc orb, Hashtable JavaDoc aTable,
69         POA JavaDoc thePOA ) throws java.lang.Exception JavaDoc
70     {
71     super(orb);
72     this.orb = orb;
73     theHashtable = aTable;
74     theEnumeration = this.theHashtable.keys();
75     currentSize = this.theHashtable.size();
76         biPOA = thePOA;
77     }
78
79     /**
80    * Returns the next binding in the NamingContext. Uses the enumeration
81    * object to determine if there are more bindings and if so, returns
82    * the next binding from the InternalBindingValue.
83    * @param b The Binding as an out parameter.
84    * @return true if there were more bindings.
85    */

86     final public boolean NextOne(org.omg.CosNaming.BindingHolder JavaDoc b)
87     {
88     // If there are more elements get the next element
89
boolean hasMore = theEnumeration.hasMoreElements();
90     if (hasMore) {
91             InternalBindingKey theBindingKey =
92          ((InternalBindingKey)theEnumeration.nextElement());
93             InternalBindingValue theElement =
94         (InternalBindingValue)theHashtable.get( theBindingKey );
95         NameComponent JavaDoc n = new NameComponent JavaDoc( theBindingKey.id, theBindingKey.kind );
96         NameComponent JavaDoc[] nlist = new NameComponent JavaDoc[1];
97         nlist[0] = n;
98             BindingType JavaDoc theType = theElement.theBindingType;
99         
100         b.value =
101             new Binding JavaDoc( nlist, theType );
102     } else {
103         // Return empty but marshalable binding
104
b.value = new Binding JavaDoc(new NameComponent JavaDoc[0],BindingType.nobject);
105     }
106     return hasMore;
107     }
108
109     /**
110    * Destroys this BindingIterator by disconnecting from the ORB
111    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
112    */

113     final public void Destroy()
114     {
115         // Remove the object from the Active Object Map.
116
try {
117             byte[] objectId = biPOA.servant_to_id( this );
118             if( objectId != null ) {
119                 biPOA.deactivate_object( objectId );
120             }
121         }
122         catch( Exception JavaDoc e ) {
123             throw new INTERNAL JavaDoc( "Exception in BindingIterator.Destroy " + e );
124         }
125     }
126
127     /**
128    * Returns the remaining number of elements in the iterator.
129    * @return the remaining number of elements in the iterator.
130    */

131     public final int RemainingElements() {
132     return currentSize;
133     }
134
135     private int currentSize;
136     private Hashtable JavaDoc theHashtable;
137     private Enumeration JavaDoc theEnumeration;
138     private org.omg.CORBA.ORB JavaDoc orb;
139 }
140
Popular Tags