Class: R2CORBA::PortableServer::DSI::Servant

Inherits:
PortableServer::Native::DynamicImplementation
  • Object
show all
Defined in:
lib/corba/jbase/Servant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_instance(rsrv) ⇒ Object



17
18
19
20
21
# File 'lib/corba/jbase/Servant.rb', line 17

def self.new_instance(rsrv)
  srv = PortableServer::DSI::Servant.new
  srv.__send__(:init, rsrv)
  srv
end

Instance Method Details

#_all_interfaces(poa, oid) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/corba/jbase/Servant.rb', line 104

def _all_interfaces(poa, oid)
  if @rsrv.nil?
    return [].to_java(:string)
  elsif @rsrv.respond_to?(:_ids)
    return @rsrv._ids.to_java(:string)
  elsif @rsrv.class.constants.any? { |c| c.to_sym == :Ids }
    return @rsrv.class::Ids.to_java(:string)
  elsif @rsrv.respond_to?(:_primary_interface)
    return [@rsrv._primary_interface(oid, poa)].to_java(:string)
  else
    return [].to_java(:string)
  end
end

#_get_componentObject



152
153
154
155
156
157
158
159
160
161
# File 'lib/corba/jbase/Servant.rb', line 152

def _get_component
  if @rsrv.nil?
    return nil
  elsif @rsrv.respond_to?(:_get_component)
    obj = @rsrv._get_component
    return obj ? obj.objref_ : nil
  else
    return super
  end
end

#_is_a(repo_id) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/corba/jbase/Servant.rb', line 118

def _is_a(repo_id)
  if @rsrv.nil?
    return false
  elsif @rsrv.respond_to?('_is_a?'.to_sym)
    return @rsrv._is_a?(repo_id)
  else
    begin
      return @rsrv.class::Ids.include?(repo_id)
    rescue
      return super
    end
  end
end

#_non_existentObject



142
143
144
145
146
147
148
149
150
# File 'lib/corba/jbase/Servant.rb', line 142

def _non_existent
  if @rsrv.nil?
    return true
  elsif @rsrv.respond_to?(:_non_existent)
    return @rsrv._non_existent
  else
    return super
  end
end

#_repository_idObject



132
133
134
135
136
137
138
139
140
# File 'lib/corba/jbase/Servant.rb', line 132

def _repository_id
  if @rsrv.nil?
    return ''
  elsif @rsrv.respond_to?(:_repository_id)
    return @rsrv._repository_id
  else
    return (@rsrv.class.const_get(:Id) rescue '')
  end
end

#detach_rbServantObject



33
34
35
# File 'lib/corba/jbase/Servant.rb', line 33

def detach_rbServant
  @rsrv = nil
end

#invoke(jsrvreq) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/corba/jbase/Servant.rb', line 37

def invoke(jsrvreq)
  begin
    raise CORBA::NO_IMPLEMENT.new('', 0, CORBA::COMPLETED_NO) unless @rsrv

    rsrvreq = CORBA::ServerRequest._wrap_native(jsrvreq, self._orb)
    begin
      case rsrvreq.srvreq_.operation
      when '_is_a'
        rsrvreq.describe({arg_list: [['', CORBA::ARG_IN, CORBA._tc_string]], result_type: CORBA._tc_boolean})
        rc = self._is_a(*rsrvreq.arguments)
        jany = rsrvreq.orb_.create_any
        jany.insert_boolean(rc == true)
        jsrvreq.set_result(jany)
      when '_non_existent'
        rsrvreq.describe({arg_list: [], result_type: CORBA._tc_boolean})
        rc = self._non_existent(*rsrvreq.arguments)
        jany = rsrvreq.orb_.create_any
        jany.insert_boolean(rc == true)
        jsrvreq.set_result(jany)
      when '_repository_id'
        rsrvreq.describe({arg_list: [], result_type: CORBA._tc_string})
        rc = self._repository_id(*rsrvreq.arguments)
        jany = rsrvreq.orb_.create_any
        jany.insert_string(rc)
        jsrvreq.set_result(jany)
      when '_component'
        rsrvreq.describe({arg_list: [], result_type: CORBA._tc_Object})
        rc = self._get_component(*rsrvreq.arguments)
        jany = rsrvreq.orb_.create_any
        jany.insert_Object(rc)
        jsrvreq.set_result(jany)
      else
        @rsrv.is_a?(PortableServer::DynamicImplementation) ? self.invoke_DSI(rsrvreq) : self.invoke_SI(rsrvreq)
      end
    rescue NativeException => ex_
      CORBA::Exception.native2r(ex_)
    end
  rescue CORBA::UserException => ex_
    STDERR.puts "#{ex_}\n#{ex_.backtrace.join("\n")}" if $VERBOSE
    if rsrvreq.exc_list_.nil? || rsrvreq.exc_list_.any? { |extc| extc.id == ex_.class._tc.id }
      jsrvreq.set_exception(CORBA::Any.to_any(ex_).to_java(self._orb))
    else
      STDERR.puts "#{ex_}\n#{ex_.backtrace.join("\n")}" unless $VERBOSE
      if jsrvreq.respond_to?(:setSystemException) # JacORB special
        jsrvreq.setSystemException(CORBA::Native::UNKNOWN.new("#{ex_}", 0, CORBA::Native::CompletionStatus.from_int(CORBA::COMPLETED_MAYBE)))
      else
        jsrvreq.set_exception(CORBA::Any.to_any(CORBA::UNKNOWN.new("#{ex_}", 0, CORBA::COMPLETED_MAYBE)).to_java(self._orb))
      end
    end
  rescue CORBA::SystemException => ex_
    STDERR.puts "#{ex_}\n#{ex_.backtrace.join("\n")}" if $VERBOSE
    if jsrvreq.respond_to?(:setSystemException) # JacORB special
      jex_klass = CORBA::Native.const_get(ex_.class::Name)
      jsrvreq.setSystemException(jex_klass.new(ex_.reason, ex_.minor, CORBA::Native::CompletionStatus.from_int(ex_.completed)))
    else
      jsrvreq.set_exception(CORBA::Any.to_any(ex_).to_java(self._orb))
    end
  rescue Exception => ex_
    STDERR.puts "#{ex_}\n#{ex_.backtrace.join("\n")}"
    if jsrvreq.respond_to?(:setSystemException) # JacORB special
      jsrvreq.setSystemException(CORBA::Native::UNKNOWN.new("#{ex_}", 0, CORBA::Native::CompletionStatus.from_int(CORBA::COMPLETED_MAYBE)))
    else
      jsrvreq.set_exception(CORBA::Any.to_any(CORBA::UNKNOWN.new("#{ex_}", 0, CORBA::COMPLETED_MAYBE)).to_java(self._orb))
    end
  end
end

#rbServantObject



29
30
31
# File 'lib/corba/jbase/Servant.rb', line 29

def rbServant
  @rsrv
end