Class: R2CORBA::INS::NamingContext

Inherits:
POA::CosNaming::NamingContextExt
  • Object
show all
Defined in:
lib/corba/svcs/ins/cos_naming.rb

Overview

Naming context servant class

Constant Summary collapse

MAP_TYPE =
Class.new(::Hash) do
  def synchronize(&block)
    yield
  end
end
@@iterators =
MAP_TYPE.new
@@iterator_max =
100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orb) ⇒ NamingContext

Returns a new instance of NamingContext.



200
201
202
203
# File 'lib/corba/svcs/ins/cos_naming.rb', line 200

def initialize(orb)
  @orb = orb
  @map = MAP_TYPE.new
end

Instance Attribute Details

#oidObject

Returns the value of attribute oid.



205
206
207
# File 'lib/corba/svcs/ins/cos_naming.rb', line 205

def oid
  @oid
end

Class Method Details

.alloc_iterator(reglist) ⇒ Object



189
190
191
192
193
194
195
196
197
198
# File 'lib/corba/svcs/ins/cos_naming.rb', line 189

def self.alloc_iterator(reglist)
  @@iterators.synchronize do
    unless @@iterators.size < @@iterator_max
      oldest_id, oldest_it = @iterators.min
      oldest_it.destroy
    end
    itid = Time.now
    return (@@iterators[itid] = INS::BindingIterator.new(reglist, itid))
  end
end

.clear_iterator(id) ⇒ Object



185
186
187
# File 'lib/corba/svcs/ins/cos_naming.rb', line 185

def self.clear_iterator(id)
  @@iterators.delete(id)
end

.set_iterator_max(max) ⇒ Object



181
182
183
# File 'lib/corba/svcs/ins/cos_naming.rb', line 181

def self.set_iterator_max(max)
  @@iterator_max = max.to_i
end

Instance Method Details

#bind(n, obj) ⇒ Object

CosNaming::NamingContext methods

Raises:

  • (CosNaming::NamingContext::InvalidName)


209
210
211
212
213
214
215
216
217
218
# File 'lib/corba/svcs/ins/cos_naming.rb', line 209

def bind(n, obj)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  if n.size > 1
    nc = find_context(n)
    nc.bind(n, obj)
  else
    register_object(n.first, n, CosNaming::Nobject, obj)
  end
end

#bind_context(n, nc_new) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


231
232
233
234
235
236
237
238
239
240
# File 'lib/corba/svcs/ins/cos_naming.rb', line 231

def bind_context(n, nc_new)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  if n.size > 1
    nc = find_context(n)
    nc.bind_context(n, nc_new)
  else
    register_object(n.first, n, CosNaming::Ncontext, nc_new)
  end
end

#bind_new_context(n) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


281
282
283
284
285
286
287
# File 'lib/corba/svcs/ins/cos_naming.rb', line 281

def bind_new_context(n)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  nc = self.new_context
  self.bind_context(n, nc)
  nc
end

#destroyObject

Raises:

  • (CosNaming::NamingContext::NotEmpty)


289
290
291
292
293
294
295
296
# File 'lib/corba/svcs/ins/cos_naming.rb', line 289

def destroy
  raise CosNaming::NamingContext::NotEmpty.new if @map.size > 0
  return if self.oid.nil? ## no oid for root context

  poa = self._default_POA
  poa.deactivate_object(self.oid)
  @orb = nil
end

#list(how_many) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/corba/svcs/ins/cos_naming.rb', line 298

def list(how_many)
  reglist = @map.values
  bindings = []
  while how_many > 0 and !reglist.empty?
    reg = reglist.shift
    bindings << CosNaming::Binding.new(reg[:name], reg[:type])
    how_many -= 1
  end
  bi_obj = nil
  unless reglist.empty?
    bi = INS::NamingContext.alloc_iterator(reglist)
    poa = self._default_POA
    bi.oid = poa.activate_object(bi)
    bi_obj = poa.id_to_reference(bi.oid)
  end
  [bindings, CosNaming::BindingIterator._narrow(bi_obj)]
end

#new_contextObject



274
275
276
277
278
279
# File 'lib/corba/svcs/ins/cos_naming.rb', line 274

def new_context
  poa = self._default_POA
  naming_srv = NamingContext.new(@orb)
  naming_srv.oid = poa.activate_object(naming_srv)
  ::CosNaming::NamingContextExt::_narrow(poa.id_to_reference(naming_srv.oid))
end

#rebind(n, obj) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


220
221
222
223
224
225
226
227
228
229
# File 'lib/corba/svcs/ins/cos_naming.rb', line 220

def rebind(n, obj)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  if n.size > 1
    nc = find_context(n)
    nc.rebind(n, obj)
  else
    reregister_object(n.first, n, CosNaming::Nobject, obj)
  end
end

#rebind_context(n, nc_new) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


242
243
244
245
246
247
248
249
250
251
# File 'lib/corba/svcs/ins/cos_naming.rb', line 242

def rebind_context(n, nc_new)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  if n.size > 1
    nc = find_context(n)
    nc.rebind_context(n, nc_new)
  else
    reregister_object(n.first, n, CosNaming::Ncontext, nc_new)
  end
end

#resolve(n) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


253
254
255
256
257
# File 'lib/corba/svcs/ins/cos_naming.rb', line 253

def resolve(n)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  find_object(n)
end

#resolve_str(sn) ⇒ Object



362
363
364
# File 'lib/corba/svcs/ins/cos_naming.rb', line 362

def resolve_str(sn)
  self.resolve(self.to_name(sn).first)
end

#to_name(sn) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/corba/svcs/ins/cos_naming.rb', line 324

def to_name(sn)
  raise CosNaming::NamingContext::InvalidName.new if sn.to_s.empty?

  snc_arr = []
  off_ = 0
  esc_ = false
  sn.size.times do |i|
    case sn[i, 1]
    when '\\'
      esc_ = !esc_
    when '/'
      unless esc_
        snc_arr << sn[off_, i - off_]
        off_ = i + 1
      end
      esc_ = false
    else
      esc_ = false
    end
  end
  snc_arr << sn[off_, sn.size]
  [snc_arr.collect { |snc| CosNaming::NameComponent.from_string(snc) }]
end

#to_string(n) ⇒ Object

CosNaming::NamingContextExt methods

Raises:

  • (CosNaming::NamingContext::InvalidName)


318
319
320
321
322
# File 'lib/corba/svcs/ins/cos_naming.rb', line 318

def to_string(n)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  n.collect { |nc| nc.to_string }.join('/')
end

#to_url(addr, sn) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/corba/svcs/ins/cos_naming.rb', line 348

def to_url(addr, sn)
  raise CosNaming::NamingContext::InvalidName.new if addr.to_s.empty? or sn.to_s.empty?

  url = 'corbaname:' + addr + '#'
  sn.scan(/./) do |ch|
    if /[a-zA-Z0-9;\/:\?@=+\$,\-_\.!~*\'\(\)]/ =~ ch
      url << ch
    else
      url << '%' << ch.unpack('H2').first
    end
  end
  url
end

#unbind(n) ⇒ Object

Raises:

  • (CosNaming::NamingContext::InvalidName)


259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/corba/svcs/ins/cos_naming.rb', line 259

def unbind(n)
  raise CosNaming::NamingContext::InvalidName.new if n.size < 1

  if n.size > 1
    nc = find_context(n)
    nc.unbind(n)
  else
    @map.synchronize do
      raise CosNaming::NamingContext::NotFound.new(CosNaming::NamingContext::Missing_node,
                                                   n) unless @map.has_key?(n.first.r_id)
      @map.delete(n.last.r_id)
    end
  end
end