Module: RRT_RUBY::Writer

Includes:
Finder
Included in:
RRTAccessor
Defined in:
lib/rrt_ruby/writer.rb

Overview

Additionally at the moment, all add operations fail miserably when the target package already exists

Constant Summary

Constants included from Finder

Finder::TYPE_CAPSULE, Finder::TYPE_CLASS, Finder::TYPE_COMPONENT_PACKAGE, Finder::TYPE_DEPLOYMENT_PACKAGE, Finder::TYPE_LOGICAL_PACKAGE, Finder::TYPE_PROTOCOL

Instance Method Summary collapse

Methods included from Finder

#component_names, #components, #executables, #external_libraries, #find_capsule, #find_class, #find_component_package, #find_deployment_package, #find_logical_package, #libraries, #ole_element, #processors, #root_component_package, #root_deployment_package, #root_logical_package

Instance Method Details

#add_logical_package(package, save = true) ⇒ Object

Adds package (a LogicalPackage instance) to the model.

Throws a ModelException when something goes wrong.

Things that can go wrong:

  • The parent package for package does not exist

  • The parent package for package is not writeable



24
25
26
27
28
29
30
31
32
33
34
35
36
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
# File 'lib/rrt_ruby/writer.rb', line 24

def add_logical_package package,save=true
	@logger.debug("Adding #{package.to_s}")
	#if no parent it goes directly to logical view
	if package.parent.empty?
		host=@model.RootLogicalPackage 
	else
		#find if the parent exists
		host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE)
	end
	if host
		if host.IsModifiable
			#add the package
			added_package=host.AddLogicalPackage(package.name)
			added_package.stereotype=package.stereotype
			#add all the classes
			package.classes.each{|c|
				add_class(c,added_package)
			}
			#add all the contained packages
			package.packages.each{|p|
				add_logical_package(p,false)
			}
			#save if wanted
			begin
				update_relations(package)
				#show so that no errors are generated when dialogs pop up
				self.show
				#save, hide and invalidated the view cache
				unit=host.GetContainingControlledElement
				raise ModelException,"Could not save#{unit.name}" unless unit.Save
				self.hide
				@logical_view=nil
			end if save
		else
			raise ModelException,"#{host.name} is not writable"
		end
	else
		raise ModelException,"#{package.parent} does not exist in the model"
	end
end

#remove_logical_package(package) ⇒ Object

Removes a LogicalPackage from the model.

Throws a ModelException when something goes wrong. Things that can go wrong:

  • The parent package for package does not exist

  • package does not exist

  • The parent package for package is not writeable



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
103
# File 'lib/rrt_ruby/writer.rb', line 73

def remove_logical_package package
	@logger.debug("Removing #{package.to_s}")
	#if no parent it goes directly to logical view
	if package.parent.empty?
		host=@model.RootLogicalPackage
		@logger.debug("...from the root logical package")
	else
		#find if the parent exists
		host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE)
	end
	if host
		if host.IsModifiable
			pkg=ole_element(package.qualified_name,TYPE_LOGICAL_PACKAGE)
			if pkg
				self.show
				#delete the package
				host.DeleteLogicalPackage(pkg)
				unit=host.GetContainingControlledElement
				raise ModelException,"Could not save#{unit.name}" unless unit.Save
				self.hide
				@logical_view=nil
			else
				@logger.info("#{package.name} does not exist in the model") 
			end
		else
			raise ModelException,"#{host.name} is not writable"
		end
	else
		raise ModelException,"#{package.parent} does not exist in the model"
	end
end

#writeable?(name) ⇒ Boolean

Checks if an OLE element with the given name can be written to/is modifiable

Raises a ModelException if no element is found

Returns:

  • (Boolean)


108
109
110
111
112
113
114
115
# File 'lib/rrt_ruby/writer.rb', line 108

def writeable? name
	el=ole_element(name)
	if el
		return el.IsModifiable
	else
		raise ModelException,"#{name} does not exist in the model"
	end
end