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 is not defined and package is not Logical View

  • The parent package for package is not writeable

Raises:

  • (ModelException)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rrt_ruby/writer.rb', line 26

def add_logical_package package,save=true
	@logger.debug("Writing #{package.to_s}")
	#check parentage
	raise ModelException, "No parent package specified" if package.parent.empty?&&package.name!="Logical View"
	host=@model.RootLogicalPackage if package.name=="Logical View"
	#find if the parent exists
	host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE) unless host
	if host
		#if the package is "Logical View", write it's subpackages, else write the package
		if package.name=="Logical View"
			package.packages.each{|pkg|
				write_logical_package(pkg,host)
			}
		else
			write_logical_package(package,host)
		end
		update_relations(package)
		save(host) if save
	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 is not defined and package is not Logical View

  • The parent package for package is not writeable

Raises:

  • (ModelException)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rrt_ruby/writer.rb', line 58

def remove_logical_package package
	@logger.debug("Removing #{package.to_s}")
	#check parentage
	raise ModelException, "No parent package specified" if package.parent.empty?&&package.name!="Logical View"
	host=@model.RootLogicalPackage if package.name=="Logical View"
	#find if the parent exists
	host=ole_element(package.parent,TYPE_LOGICAL_PACKAGE) unless host
	if host
		#if the package is "Logical View", write it's subpackages, else write the package
		if package.name=="Logical View"
			package.packages.each{|pkg|
				delete_logical_package(pkg,host)
			}
		else
			delete_logical_package(package,host)
		end
		save(host)
	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)


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

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