4
|
1 |
/*
|
5555
|
2 |
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
|
4
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5555
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
4
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5555
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
4
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5555
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
4
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.corba.se.impl.naming.pcosnaming;
|
|
27 |
|
|
28 |
// Import general CORBA classes
|
|
29 |
import org.omg.CORBA.SystemException;
|
|
30 |
import org.omg.CORBA.ORB;
|
|
31 |
import org.omg.CORBA.INTERNAL;
|
|
32 |
|
|
33 |
// Get org.omg.CosNaming Types
|
|
34 |
import org.omg.CosNaming.Binding;
|
|
35 |
import org.omg.CosNaming.BindingType;
|
|
36 |
import org.omg.CosNaming.BindingTypeHolder;
|
|
37 |
import org.omg.CosNaming.NameComponent;
|
|
38 |
import org.omg.PortableServer.POA;
|
|
39 |
|
|
40 |
// Get base implementation
|
|
41 |
import com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl;
|
|
42 |
import com.sun.corba.se.impl.naming.pcosnaming.InternalBindingValue;
|
|
43 |
|
|
44 |
import com.sun.corba.se.impl.naming.cosnaming.BindingIteratorImpl;
|
|
45 |
|
|
46 |
// Get a hash table
|
|
47 |
import java.util.Hashtable;
|
|
48 |
import java.util.Enumeration;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Class TransientBindingIterator implements the abstract methods
|
|
52 |
* defined by BindingIteratorImpl, to use with the TransientNamingContext
|
|
53 |
* implementation of the NamingContextImpl. The TransientBindingIterator
|
|
54 |
* implementation receives a hash table of InternalBindingValues, and uses
|
|
55 |
* an Enumeration to iterate over the contents of the hash table.
|
|
56 |
* @see BindingIteratorImpl
|
|
57 |
* @see TransientNamingContext
|
|
58 |
*/
|
|
59 |
public class PersistentBindingIterator extends BindingIteratorImpl
|
|
60 |
{
|
|
61 |
private POA biPOA;
|
|
62 |
/**
|
|
63 |
* Constructs a new PersistentBindingIterator object.
|
|
64 |
* @param orb a org.omg.CORBA.ORB object.
|
|
65 |
* @param aTable A hashtable containing InternalBindingValues which is
|
|
66 |
* the content of the PersistentNamingContext.
|
|
67 |
* @param java.lang.Exception a Java exception.
|
|
68 |
* @exception Exception a Java exception thrown of the base class cannot
|
|
69 |
* initialize.
|
|
70 |
*/
|
|
71 |
public PersistentBindingIterator(org.omg.CORBA.ORB orb, Hashtable aTable,
|
|
72 |
POA thePOA ) throws java.lang.Exception
|
|
73 |
{
|
|
74 |
super(orb);
|
|
75 |
this.orb = orb;
|
|
76 |
theHashtable = aTable;
|
|
77 |
theEnumeration = this.theHashtable.keys();
|
|
78 |
currentSize = this.theHashtable.size();
|
|
79 |
biPOA = thePOA;
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Returns the next binding in the NamingContext. Uses the enumeration
|
|
84 |
* object to determine if there are more bindings and if so, returns
|
|
85 |
* the next binding from the InternalBindingValue.
|
|
86 |
* @param b The Binding as an out parameter.
|
|
87 |
* @return true if there were more bindings.
|
|
88 |
*/
|
|
89 |
final public boolean NextOne(org.omg.CosNaming.BindingHolder b)
|
|
90 |
{
|
|
91 |
// If there are more elements get the next element
|
|
92 |
boolean hasMore = theEnumeration.hasMoreElements();
|
|
93 |
if (hasMore) {
|
|
94 |
InternalBindingKey theBindingKey =
|
|
95 |
((InternalBindingKey)theEnumeration.nextElement());
|
|
96 |
InternalBindingValue theElement =
|
|
97 |
(InternalBindingValue)theHashtable.get( theBindingKey );
|
|
98 |
NameComponent n = new NameComponent( theBindingKey.id, theBindingKey.kind );
|
|
99 |
NameComponent[] nlist = new NameComponent[1];
|
|
100 |
nlist[0] = n;
|
|
101 |
BindingType theType = theElement.theBindingType;
|
|
102 |
|
|
103 |
b.value =
|
|
104 |
new Binding( nlist, theType );
|
|
105 |
} else {
|
|
106 |
// Return empty but marshalable binding
|
|
107 |
b.value = new Binding(new NameComponent[0],BindingType.nobject);
|
|
108 |
}
|
|
109 |
return hasMore;
|
|
110 |
}
|
|
111 |
|
|
112 |
/**
|
|
113 |
* Destroys this BindingIterator by disconnecting from the ORB
|
|
114 |
* @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
|
|
115 |
*/
|
|
116 |
final public void Destroy()
|
|
117 |
{
|
|
118 |
// Remove the object from the Active Object Map.
|
|
119 |
try {
|
|
120 |
byte[] objectId = biPOA.servant_to_id( this );
|
|
121 |
if( objectId != null ) {
|
|
122 |
biPOA.deactivate_object( objectId );
|
|
123 |
}
|
|
124 |
}
|
|
125 |
catch( Exception e ) {
|
|
126 |
throw new INTERNAL( "Exception in BindingIterator.Destroy " + e );
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Returns the remaining number of elements in the iterator.
|
|
132 |
* @return the remaining number of elements in the iterator.
|
|
133 |
*/
|
|
134 |
public final int RemainingElements() {
|
|
135 |
return currentSize;
|
|
136 |
}
|
|
137 |
|
|
138 |
private int currentSize;
|
|
139 |
private Hashtable theHashtable;
|
|
140 |
private Enumeration theEnumeration;
|
|
141 |
private org.omg.CORBA.ORB orb;
|
|
142 |
}
|