KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)BindingIteratorImpl.java 1.41 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.ORB JavaDoc;
12 import org.omg.CORBA.Object JavaDoc;
13
14 // Import org.omg.CosNaming classes
15
import org.omg.CosNaming.Binding JavaDoc;
16 import org.omg.CosNaming.BindingType JavaDoc;
17 import org.omg.CosNaming.BindingHolder JavaDoc;
18 import org.omg.CosNaming.BindingListHolder JavaDoc;
19 import org.omg.CosNaming.BindingIteratorHolder JavaDoc;
20 import org.omg.CosNaming.BindingIteratorPOA JavaDoc;
21 import org.omg.CORBA.BAD_PARAM JavaDoc;
22
23 /**
24  * Class BindingIteratorImpl implements the org.omg.CosNaming::BindingIterator
25  * interface, but does not implement the method to retrieve the next
26  * binding in the NamingContext for which it was created. This is left
27  * to a subclass, which is why this class is abstract; BindingIteratorImpl
28  * provides an implementation of the interface operations on top of two
29  * subclass methods, allowing multiple implementations of iterators that
30  * differ in storage and access to the contents of a NamingContext
31  * implementation.
32  * <p>
33  * The operation next_one() is implemented by the subclass, whereas
34  * next_n() is implemented on top of the next_one() implementation.
35  * Destroy must also be implemented by the subclass.
36  * <p>
37  * A subclass must implement NextOne() and Destroy(); these
38  * methods are invoked from synchronized methods and need therefore
39  * not be synchronized themselves.
40  */

41 public abstract class BindingIteratorImpl extends BindingIteratorPOA JavaDoc
42 {
43     protected ORB JavaDoc orb ;
44
45     /**
46      * Create a binding iterator servant.
47      * runs the super constructor.
48      * @param orb an ORB object.
49      * @exception java.lang.Exception a Java exception.
50      */

51     public BindingIteratorImpl(ORB JavaDoc orb)
52         throws java.lang.Exception JavaDoc
53     {
54     super();
55     this.orb = orb ;
56     }
57   
58     /**
59      * Return the next binding. It also returns true or false, indicating
60      * whether there were more bindings.
61      * @param b The Binding as an out parameter.
62      * @return true if there were more bindings.
63      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
64      * system exceptions.
65      * @see NextOne
66      */

67     public synchronized boolean next_one(org.omg.CosNaming.BindingHolder JavaDoc b)
68     {
69     // NextOne actually returns the next one
70
return NextOne(b);
71     }
72   
73     /**
74      * Return the next n bindings. It also returns true or false, indicating
75      * whether there were more bindings.
76      * @param how_many The number of requested bindings in the BindingList.
77      * @param bl The BindingList as an out parameter.
78      * @return true if there were more bindings.
79      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
80      * system exceptions.
81      * @see NextOne
82      */

83     public synchronized boolean next_n(int how_many,
84         org.omg.CosNaming.BindingListHolder JavaDoc blh)
85     {
86         if( how_many == 0 ) {
87             throw new BAD_PARAM JavaDoc( " 'how_many' parameter is set to 0 which is" +
88             " invalid" );
89         }
90         return list( how_many, blh );
91     }
92
93     /**
94      * lists next n bindings. It returns true or false, indicating
95      * whether there were more bindings. This method has the package private
96      * scope, It will be called from NamingContext.list() operation or
97      * this.next_n().
98      * @param how_many The number of requested bindings in the BindingList.
99      * @param bl The BindingList as an out parameter.
100      * @return true if there were more bindings.
101      */

102     public boolean list( int how_many, org.omg.CosNaming.BindingListHolder JavaDoc blh)
103     {
104     // Take the smallest of what's left and what's being asked for
105
int numberToGet = Math.min(RemainingElements(),how_many);
106     
107         // Create a resulting BindingList
108
Binding JavaDoc[] bl = new Binding JavaDoc[numberToGet];
109     BindingHolder JavaDoc bh = new BindingHolder JavaDoc();
110     int i = 0;
111     // Keep iterating as long as there are entries
112
while (i < numberToGet && this.NextOne(bh) == true) {
113         bl[i] = bh.value;
114         i++;
115     }
116     // Found any at all?
117
if (i == 0) {
118         // No
119
blh.value = new Binding JavaDoc[0];
120         return false;
121     }
122
123     // Set into holder
124
blh.value = bl;
125     
126     return true;
127     }
128
129
130
131
132     /**
133      * Destroy this BindingIterator object. The object corresponding to this
134      * object reference is destroyed.
135      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
136      * system exceptions.
137      * @see Destroy
138      */

139     public synchronized void destroy()
140     {
141     // Destroy actually destroys
142
this.Destroy();
143     }
144
145     /**
146      * Abstract method for returning the next binding in the NamingContext
147      * for which this BindingIterator was created.
148      * @param b The Binding as an out parameter.
149      * @return true if there were more bindings.
150      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
151      * system exceptions.
152      */

153     protected abstract boolean NextOne(org.omg.CosNaming.BindingHolder JavaDoc b);
154
155     /**
156      * Abstract method for destroying this BindingIterator.
157      * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
158      * system exceptions.
159      */

160     protected abstract void Destroy();
161
162     /**
163      * Abstract method for returning the remaining number of elements.
164      * @return the remaining number of elements in the iterator.
165      */

166     protected abstract int RemainingElements();
167 }
168
Popular Tags