KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > cosnaming > TransientBindingIterator


1 /*
2  * @(#)TransientBindingIterator.java 1.45 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 package com.sun.corba.se.impl.naming.cosnaming;
9
10 // Import general CORBA classes
11
import org.omg.CORBA.SystemException JavaDoc;
12 import org.omg.CORBA.ORB JavaDoc;
13 import org.omg.PortableServer.POA JavaDoc;
14
15 // Get org.omg.CosNaming Types
16
import org.omg.CosNaming.Binding JavaDoc;
17 import org.omg.CosNaming.BindingType JavaDoc;
18 import org.omg.CosNaming.BindingTypeHolder JavaDoc;
19 import org.omg.CosNaming.NameComponent JavaDoc;
20
21 // Get base implementation
22
import com.sun.corba.se.impl.naming.cosnaming.NamingContextImpl;
23 import com.sun.corba.se.impl.naming.cosnaming.InternalBindingValue;
24
25 // Get a hash table
26
import java.util.Hashtable JavaDoc;
27 import java.util.Enumeration JavaDoc;
28
29 /**
30  * Class TransientBindingIterator implements the abstract methods
31  * defined by BindingIteratorImpl, to use with the TransientNamingContext
32  * implementation of the NamingContextImpl. The TransientBindingIterator
33  * implementation receives a hash table of InternalBindingValues, and uses
34  * an Enumeration to iterate over the contents of the hash table.
35  * @see BindingIteratorImpl
36  * @see TransientNamingContext
37  */

38 public class TransientBindingIterator extends BindingIteratorImpl
39 {
40     // There is only one POA used for both TransientNamingContext and
41
// TransientBindingIteraor servants.
42
private POA JavaDoc nsPOA;
43     /**
44      * Constructs a new TransientBindingIterator object.
45      * @param orb a org.omg.CORBA.ORB object.
46      * @param aTable A hashtable containing InternalBindingValues which is
47      * the content of the TransientNamingContext.
48      * @param java.lang.Exception a Java exception.
49      * @exception Exception a Java exception thrown of the base class cannot
50      * initialize.
51    */

52     public TransientBindingIterator(ORB JavaDoc orb, Hashtable JavaDoc aTable,
53         POA JavaDoc thePOA )
54     throws java.lang.Exception JavaDoc
55     {
56     super(orb);
57     theHashtable = aTable;
58     theEnumeration = this.theHashtable.elements();
59     currentSize = this.theHashtable.size();
60         this.nsPOA = thePOA;
61     }
62
63     /**
64    * Returns the next binding in the NamingContext. Uses the enumeration
65    * object to determine if there are more bindings and if so, returns
66    * the next binding from the InternalBindingValue.
67    * @param b The Binding as an out parameter.
68    * @return true if there were more bindings.
69    */

70     final public boolean NextOne(org.omg.CosNaming.BindingHolder JavaDoc b)
71     {
72     // If there are more elements get the next element
73
boolean hasMore = theEnumeration.hasMoreElements();
74     if (hasMore) {
75         b.value =
76         ((InternalBindingValue)theEnumeration.nextElement()).theBinding;
77         currentSize--;
78     } else {
79         // Return empty but marshalable binding
80
b.value = new Binding JavaDoc(new NameComponent JavaDoc[0],BindingType.nobject);
81     }
82     return hasMore;
83     }
84
85     /**
86      * Destroys this BindingIterator by disconnecting from the ORB
87      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
88      * system exceptions.
89      */

90     final public void Destroy()
91     {
92     // Remove the object from the Active Object Map.
93
try {
94             byte[] objectId = nsPOA.servant_to_id( this );
95             if( objectId != null ) {
96                 nsPOA.deactivate_object( objectId );
97             }
98         }
99         catch( Exception JavaDoc e ) {
100             NamingUtils.errprint("BindingIterator.Destroy():caught exception:");
101             NamingUtils.printException(e);
102         }
103     }
104
105     /**
106      * Returns the remaining number of elements in the iterator.
107      * @return the remaining number of elements in the iterator.
108      */

109     public final int RemainingElements() {
110     return currentSize;
111     }
112
113     private int currentSize;
114     private Hashtable JavaDoc theHashtable;
115     private Enumeration JavaDoc theEnumeration;
116 }
117
Popular Tags