1 7 8 package com.sun.corba.se.impl.naming.cosnaming; 9 10 import org.omg.CORBA.SystemException ; 12 import org.omg.CORBA.Object ; 13 import org.omg.CORBA.INTERNAL ; 14 import org.omg.CORBA.CompletionStatus ; 15 import org.omg.CORBA.ORB ; 16 import org.omg.PortableServer.POA ; 17 18 import org.omg.CosNaming.Binding ; 20 import org.omg.CosNaming.BindingType ; 21 import org.omg.CosNaming.BindingTypeHolder ; 22 import org.omg.CosNaming.BindingListHolder ; 23 import org.omg.CosNaming.BindingIteratorHolder ; 24 import org.omg.CosNaming.NameComponent ; 25 import org.omg.CosNaming.NamingContext ; 26 27 import java.util.logging.Logger ; 28 import java.util.logging.Level ; 29 30 import java.util.Hashtable ; 31 import com.sun.corba.se.impl.orbutil.LogKeywords; 32 import com.sun.corba.se.impl.logging.NamingSystemException; 33 import com.sun.corba.se.spi.logging.CORBALogDomains; 34 35 63 public class TransientNamingContext extends NamingContextImpl implements NamingContextDataStore 64 { 65 private Logger readLogger, updateLogger, lifecycleLogger; 66 67 private NamingSystemException wrapper ; 71 72 79 public TransientNamingContext(com.sun.corba.se.spi.orb.ORB orb, 80 org.omg.CORBA.Object initial, 81 POA nsPOA ) 82 throws java.lang.Exception 83 { 84 super(orb, nsPOA ); 85 wrapper = NamingSystemException.get( orb, CORBALogDomains.NAMING ) ; 86 87 this.localRoot = initial; 88 readLogger = orb.getLogger( CORBALogDomains.NAMING_READ); 89 updateLogger = orb.getLogger( CORBALogDomains.NAMING_UPDATE); 90 lifecycleLogger = orb.getLogger( 91 CORBALogDomains.NAMING_LIFECYCLE); 92 lifecycleLogger.fine( "Root TransientNamingContext LIFECYCLE.CREATED" ); 93 } 94 95 106 public final void Bind(NameComponent n, org.omg.CORBA.Object obj, 107 BindingType bt) 108 throws org.omg.CORBA.SystemException 109 { 110 InternalBindingKey key = new InternalBindingKey(n); 112 NameComponent [] name = new NameComponent [1]; 113 name[0] = n; 114 Binding b = new Binding (name,bt); 115 InternalBindingValue value = new InternalBindingValue(b,null); 116 value.theObjectRef = obj; 117 InternalBindingValue oldValue = 119 (InternalBindingValue)this.theHashtable.put(key,value); 120 121 if (oldValue != null) { 122 updateLogger.warning( LogKeywords.NAMING_BIND + "Name " + 123 getName( n ) + " Was Already Bound" ); 124 throw wrapper.transNcBindAlreadyBound() ; 125 } 126 if( updateLogger.isLoggable( Level.FINE ) ) { 127 updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + 128 "Name Component: " + n.id + "." + n.kind ); 129 } 130 } 131 132 145 public final org.omg.CORBA.Object Resolve(NameComponent n, 146 BindingTypeHolder bth) 147 throws org.omg.CORBA.SystemException 148 { 149 if ( (n.id.length() == 0) 151 &&(n.kind.length() == 0 ) ) 152 { 153 bth.value = BindingType.ncontext; 154 return localRoot; 155 } 156 157 InternalBindingKey key = new InternalBindingKey(n); 159 160 InternalBindingValue value = 161 (InternalBindingValue) this.theHashtable.get(key); 162 if (value == null) return null; 163 if( readLogger.isLoggable( Level.FINE ) ) { 164 readLogger.fine( LogKeywords.NAMING_RESOLVE_SUCCESS 165 + "Namecomponent :" + getName( n ) ); 166 } 167 168 bth.value = value.theBinding.binding_type; 170 return value.theObjectRef; 171 } 172 173 183 public final org.omg.CORBA.Object Unbind(NameComponent n) 184 throws org.omg.CORBA.SystemException 185 { 186 InternalBindingKey key = new InternalBindingKey(n); 188 InternalBindingValue value = 189 (InternalBindingValue)this.theHashtable.remove(key); 190 191 if (value == null) { 193 if( updateLogger.isLoggable( Level.FINE ) ) { 194 updateLogger.fine( LogKeywords.NAMING_UNBIND_FAILURE + 195 " There was no binding with the name " + getName( n ) + 196 " to Unbind " ); 197 } 198 return null; 199 } else { 200 if( updateLogger.isLoggable( Level.FINE ) ) { 201 updateLogger.fine( LogKeywords.NAMING_UNBIND_SUCCESS + 202 " NameComponent: " + getName( n ) ); 203 } 204 return value.theObjectRef; 205 } 206 } 207 208 219 public final void List(int how_many, BindingListHolder bl, 220 BindingIteratorHolder bi) 221 throws org.omg.CORBA.SystemException 222 { 223 try { 224 TransientBindingIterator bindingIterator = 229 new TransientBindingIterator(this.orb, 230 (Hashtable )this.theHashtable.clone(), nsPOA); 231 bindingIterator.list(how_many,bl); 233 234 byte[] objectId = nsPOA.activate_object( bindingIterator ); 235 org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId ); 236 237 org.omg.CosNaming.BindingIterator bindingRef = 239 org.omg.CosNaming.BindingIteratorHelper.narrow( obj ); 240 241 bi.value = bindingRef; 242 } catch (org.omg.CORBA.SystemException e) { 243 readLogger.warning( LogKeywords.NAMING_LIST_FAILURE + e ); 244 throw e; 245 } catch (Exception e) { 246 readLogger.severe( LogKeywords.NAMING_LIST_FAILURE + e ); 248 throw wrapper.transNcListGotExc( e ) ; 249 } 250 } 251 252 260 public final org.omg.CosNaming.NamingContext NewContext() 261 throws org.omg.CORBA.SystemException 262 { 263 try { 264 TransientNamingContext transContext = 266 new TransientNamingContext( 267 (com.sun.corba.se.spi.orb.ORB) orb,localRoot, nsPOA); 268 269 byte[] objectId = nsPOA.activate_object( transContext ); 270 org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId ); 271 lifecycleLogger.fine( "TransientNamingContext " + 272 "LIFECYCLE.CREATE SUCCESSFUL" ); 273 return org.omg.CosNaming.NamingContextHelper.narrow( obj ); 274 275 } catch (org.omg.CORBA.SystemException e) { 276 lifecycleLogger.log( 277 Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e ); 278 throw e; 279 } catch (Exception e) { 280 lifecycleLogger.log( 281 Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e ); 282 throw wrapper.transNcNewctxGotExc( e ) ; 283 } 284 } 285 286 291 public final void Destroy() 292 throws org.omg.CORBA.SystemException 293 { 294 try { 296 byte[] objectId = nsPOA.servant_to_id( this ); 297 if( objectId != null ) { 298 nsPOA.deactivate_object( objectId ); 299 } 300 if( lifecycleLogger.isLoggable( Level.FINE ) ) { 301 lifecycleLogger.fine( 302 LogKeywords.LIFECYCLE_DESTROY_SUCCESS ); 303 } 304 } catch (org.omg.CORBA.SystemException e) { 305 lifecycleLogger.log( Level.WARNING, 306 LogKeywords.LIFECYCLE_DESTROY_FAILURE, e ); 307 throw e; 308 } catch (Exception e) { 309 lifecycleLogger.log( Level.WARNING, 310 LogKeywords.LIFECYCLE_DESTROY_FAILURE, e ); 311 throw wrapper.transNcDestroyGotExc( e ) ; 312 } 313 } 314 315 318 private String getName( NameComponent n ) { 319 return n.id + "." + n.kind; 320 } 321 322 327 public final boolean IsEmpty() 328 { 329 return this.theHashtable.isEmpty(); 330 } 331 332 private final Hashtable theHashtable = new Hashtable (); 334 335 338 public org.omg.CORBA.Object localRoot; 339 } 340 341 | Popular Tags |