Module: RRT_RUBY::Finder

Included in:
RRTFinder, Writer
Defined in:
lib/rrt_ruby/finder.rb

Overview

Finder#root_component_package, Finder#root_deployment_package etc. also do this for their respective Package instances.

Defined Under Namespace

Classes: FinderException

Constant Summary collapse

TYPE_CLASS =

OLE element type

'Class'
TYPE_CAPSULE =

OLE element type

'Capsule'
TYPE_PROTOCOL =

OLE element type

'Protocol'
TYPE_LOGICAL_PACKAGE =

OLE element type

'LogicalPackage'
TYPE_DEPLOYMENT_PACKAGE =

OLE element type

'DeploymentPackage'
TYPE_COMPONENT_PACKAGE =

OLE element type

'ComponentPackage'

Instance Method Summary collapse

Instance Method Details

#component_names(root_package) ⇒ Object

Delivers all fully qualified component names under the defined package. If the parameter does not correspond to a component view package it will return an empty array



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rrt_ruby/finder.rb', line 123

def component_names root_package
  check
  components=Array.new
  #first of all find the package in the model

  pkg= find_component_package(root_package)
  begin 
    comps=pkg.GetAllComponents
    @logger.debug("There are #{comps.Count} components under #{pkg.GetQualifiedName}")
    cnt=comps.Count
    1.upto(cnt){|i|
      components<<comps.GetAt(i).GetQualifiedName
    }
  end if pkg
  return components
end

#components(root_package) ⇒ Object

Returns all components in the given package



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rrt_ruby/finder.rb', line 139

def components root_package
  check
  components=Array.new
  #first of all find the package in the model

  pkg= find_component_package(root_package)
  begin 
    comps=pkg.GetAllComponents
    @logger.debug("There are #{comps.Count} components under #{pkg.GetQualifiedName}")
    cnt=comps.Count
    1.upto(cnt){|i|
      components<<Component.new(comps.GetAt(i))
    }
  end if pkg
  return components
end

#executables(root_package) ⇒ Object

Returns all executables in the given package



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rrt_ruby/finder.rb', line 155

def executables root_package
  check
  components=Array.new
  #first of all find the package in the model

  pkg= find_component_package(root_package)
  begin 
    comps=pkg.GetAllComponents
    @logger.debug("There are #{comps.Count} components under #{pkg.GetQualifiedName}")
    cnt=comps.Count
    1.upto(cnt){|i|
      comp=comps.GetAt(i)
      components<<Executable.new(comp) if comp.Type=~/Executable/
    }
  end if pkg
  return components
end

#external_libraries(root_package) ⇒ Object

Returns all external libraries in the given package and it’s subpackages



190
191
192
193
194
195
196
# File 'lib/rrt_ruby/finder.rb', line 190

def external_libraries root_package
  check
  comps=components(root_package)
  return comps.collect{|c|
    c if c.type=~/External/
  }.compact
end

#find_capsule(name) ⇒ Object

Returns the first Capsule that matches the given name, nil if no match is made.



84
85
86
87
88
89
90
# File 'lib/rrt_ruby/finder.rb', line 84

def find_capsule name
  check
  el=ole_element(name,TYPE_CAPSULE)
  return Capsule.new(el) if el
  @logger.debug("Capsule #{name} not found in #{@modelname}")
  return nil
end

#find_class(name) ⇒ Object

Returns the RRT_RUBY::Class instance of the first class with the provided name nil if nothing is found.



93
94
95
96
97
98
99
# File 'lib/rrt_ruby/finder.rb', line 93

def find_class name
  check
  el=ole_element(name,TYPE_CLASS)
  return RRT_RUBY::Class.new(el) if el
  @logger.debug("Class #{name} not found in #{@modelname}")
  return nil
end

#find_component_package(package_name = false) ⇒ Object

This will return the first component package matching the name, nil if no component package is found.

If no fully qualified name is provided, then the first match is returned



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/rrt_ruby/finder.rb', line 200

def find_component_package package_name=false
  check
  #get the simple package name

  splitted=package_name.split("::")
  simple_name=splitted[splitted.size-1] unless splitted.size==0
  #get a collection with all the packages with the same name

  col=@model.FindModelElements(simple_name)
  count=col.Count
  @logger.debug("There are #{count} packages named #{simple_name}")
  1.upto(count){|i|
    obj=col.GetAt(i)
    #match the first if no qualified name is given

    return obj if package_name==simple_name&&obj.Name==simple_name && obj.IsClass("ComponentPackage")
    #match the qualified name

    return obj if obj.GetQualifiedName==package_name && obj.IsClass("ComponentPackage")
  }
  return nil
end

#find_deployment_package(package_name) ⇒ Object

This will return the first deployment package matching the name nil if no deployment package is found if no fully qualified name is provided, then the first match is returned



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/rrt_ruby/finder.rb', line 238

def find_deployment_package package_name
  check
  #get the simple package name

  splitted=package_name.split("::")
  simple_name=splitted[splitted.size-1] unless splitted.size==0
  #get a collection with all the packages with the same name

  col=@model.FindModelElements(simple_name)
  count=col.Count
  $stdout.puts "There are #{count} packages named #{simple_name}" if debug
  1.upto(count){|i|
    obj=col.GetAt(i)
    #match the first if no qualified name is given

    return obj if package_name==simple_name&&obj.Name==simple_name && obj.IsClass("DeploymentPackage")
    #match the qualified name

    return obj if obj.GetQualifiedName==package_name && obj.IsClass("DeploymentPackage")
  }
  return nil
end

#find_logical_package(package_name) ⇒ Object

This will return the logical view package matching the name or nil if no package is found.

If no fully qualified name is provided, then the first match is returned.

Note that a package contains other packages and capsules and classes and this information is all read when calling this method so looking for a package high in the hierarchy can yield a structure containing most or all of the logical view of the model.

Specifying “” or “LogicalView” as package_name will return the entire Logical View contents. See also LogicalFinder#root_package



75
76
77
78
79
80
81
82
# File 'lib/rrt_ruby/finder.rb', line 75

def find_logical_package package_name
  check
  return root_logical_package if package_name=="" || package_name=="LogicalView"
  el=ole_element(package_name,TYPE_LOGICAL_PACKAGE)
  return LogicalPackage.new(el) if el
  @logger.debug("Package #{package_name} not found in #{@modelname}") unless el
  return nil
end

#libraries(root_package) ⇒ Object

returns all libraries in the given package and it’s subpackages



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rrt_ruby/finder.rb', line 172

def libraries root_package
  check
  components=Array.new
  #first of all find the package in the model

  pkg= find_component_package(root_package)
  begin 
    comps=pkg.GetAllComponents
    @logger.debug("There are #{comps.Count} components under #{pkg.GetQualifiedName}")
    cnt=comps.Count
    1.upto(cnt){|i|
      comp=comps.GetAt(i)
      type=comp.Type
      components<<Library.new(comp) if type=~/Library/ && !(type=~/External/)
    }
  end if pkg
  return components
end

#ole_element(name, type = nil) ⇒ Object

Returns the first OLE element with the given name, optionally if it’s of the given type.

Use the TYPE_ constants to define the element types



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
# File 'lib/rrt_ruby/finder.rb', line 40

def ole_element name,type=nil
  check
  #get the simple  name

  splitted=name.split("::")
  simple_name=splitted[splitted.size-1] unless splitted.size==0
  #find it

  col=@model.FindModelElements(simple_name)
  count=col.Count
  1.upto(count){|i|
    it=col.GetAt(i)
    #match the first if no qualified name is given

    if type
      return it if it.IsClass(type)
    else
      return it
    end if it&&name==simple_name&&it.Name==name
    #match the qualified name

    if type
      return it if it.IsClass(type)
    else
      return it
    end if it&&it.GetQualifiedName==name
  }
  @logger.warn("Element #{name} not found in #{@modelname}")
  return nil
end

#processors(root_package) ⇒ Object

delivers all processors under the defined package. If the parameter does not correspond to a deployment view package it will return an empty array



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/rrt_ruby/finder.rb', line 220

def processors root_package
  check
  components=Array.new
  #first of all find the package in the model

  pkg= find_deployment_package(root_package)
  begin 
    comps=pkg.GetAllProcessors
    $stdout.puts("There are #{comps.Count} processors under #{pkg.GetQualifiedName}") if debug
    cnt=comps.Count
    1.upto(cnt){|i|
      components<<Processor.new(comps.GetAt(i))
    }
  end if pkg
  return components
end

#root_component_packageObject

Returns the ComponentPackage instance for Component View. Essentially this instance contains the complete component view contents



109
110
111
112
113
# File 'lib/rrt_ruby/finder.rb', line 109

def root_component_package
  check
  @component_view=ComponentPackage.new(@model.RootComponentPackage) unless @component_view
  return @component_view
end

#root_deployment_packageObject

Returns the DeploymentPackage instance for Deployment View. Essentially this instance contains the complete deployment view contents



115
116
117
118
119
# File 'lib/rrt_ruby/finder.rb', line 115

def root_deployment_package
  check
  @deployment_view=DeploymentPackage.new(@model.RootDeploymentPackage) unless @deployment_view
  return @deployment_view
end

#root_logical_packageObject

Returns the LogicalPackage instance for Logical View. Essentially this instance contains the complete logical view contents



102
103
104
105
106
# File 'lib/rrt_ruby/finder.rb', line 102

def root_logical_package
  check
  @logical_view=LogicalPackage.new(@model.RootLogicalPackage) unless @logical_view
  return @logical_view
end