Class: Fhlow::Node
- Inherits:
-
Object
- Object
- Fhlow::Node
- Defined in:
- lib/module_fhlow/node.rb
Overview
Nodes are something like containers that are able to contain Leaf and Node objects. Each Node creates it’s children (Leaf and Node objects) when it is created. So parsing the fhlow structure is implicitly done by creating the RootNode object. The valid prefixes of Node and Leaf objects for each nodelevel (see initialize) are stored in the default configfile (<fhlow-root>/flw/defaults.flw).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
The configuration object.
-
#name ⇒ Object
readonly
The name of the node.
-
#prefix ⇒ Object
readonly
The prefix of the node.
Instance Method Summary collapse
-
#fetchDependencies ⇒ Object
Tells each children to fetch its dependencies.
-
#getLeaf(_objectfootprint, _passthrough = 0) ⇒ Object
Returns the requested Leaf.
-
#getPath ⇒ Object
Returns the absolute path to the Node.
-
#initialize(_prefix, _name, _parent, _nodelevel, _log, _pen, _defaultconf = _parent.conf) ⇒ Node
constructor
Initializes the members, creates the children (Leaf and Node objects) corresponding to the default configfile (<fhlow-root>/flw/defaults.flw) and reads the configuration file for this Node.
-
#printMe(_prefix = " ") ⇒ Object
Prints the name of this group and information about its children.
Constructor Details
#initialize(_prefix, _name, _parent, _nodelevel, _log, _pen, _defaultconf = _parent.conf) ⇒ Node
Initializes the members, creates the children (Leaf and Node objects) corresponding to the default configfile (<fhlow-root>/flw/defaults.flw) and reads the configuration file for this Node.
_prefix
-
Prefix of the Node.
_name
-
Name of the Node.
_parent
-
Reference to the parent Node.
_nodelevel
-
The level of the Node inside the fhlow structure.
_log
-
Reference to a Log object.
_pen
-
Reference to a Pen obejct (output to console).
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/module_fhlow/node.rb', line 53 def initialize(_prefix, _name, _parent, _nodelevel, _log, _pen, _defaultconf=_parent.conf) @prefix = _prefix @name = _name # a hash is used for nodes and leafs because the key (prefix+nodename) can be used to # directly access the desired object (by for example getObject) so we don't have # to iterate through the whole structure _recursively_. a hash will therefore be # much faster! @nodes = Hash.new @leafs = Hash.new @nodelevel = _nodelevel @parent = _parent @log = _log @pen = _pen if File.exist?(@parent.getPath+@prefix+@name+"/config.flw") # read the config file @conf = Config::Config.new(@parent.getPath+@prefix+@name+"/config.flw") # inherit the configurations from previous levels @conf.merge(_defaultconf) @log.debug(@prefix+@name, "Sucessfully merged inherited configs from #{@parent.prefix+@parent.name}.") else @log.warning(self, "config.flw does not exists in #{@prefix}#{@name}.") raise FhlowException, "No configurations found in #{@prefix}#{@name}!" if @parent.conf.nil? @conf = @parent.conf end raise FhlowException, "\"NodePrefixes\" in section \"fhlow\" is not set in any of your config files." unless @conf["fhlow"]["NodePrefixes"] raise FhlowException, "\"LeafPrefixes\" in section \"fhlow\" is not set in any of your config files." unless @conf["fhlow"]["LeafPrefixes"] @log.info(@prefix+@name, "initializing node...") if @nodelevel < @conf["fhlow"]["NodePrefixes"].length # add the nodes @conf["fhlow"]["NodePrefixes"][@nodelevel].strip.split(",").each do |pf| pf.strip! Dir[getPath+pf+"*"].each do |nodename| nodename = nodename.gsub(/.*\/#{pf}/, "") @log.debug(@prefix+@name, "adding node "+" "*@nodelevel+pf+nodename) # a hash is used for nodes because the key (prefix+nodename) can be used to # directly access the desired object (by for example getObject) so we don't have # to iterate through the whole structure _recursively_. a hash will therefore be # much faster! @nodes.store(pf+nodename, Node.new(pf, nodename, self, @nodelevel+1, @log, @pen)) end end end if @nodelevel > 0 && @conf["fhlow"]["LeafPrefixes"][@nodelevel-@conf["fhlow"]["NodePrefixes"].length-1] # add the leafs @conf["fhlow"]["LeafPrefixes"][@nodelevel-@conf["fhlow"]["NodePrefixes"].length-1].strip.split(",").each do |prefix| prefix.strip! Dir[getPath+prefix+"*"].each do |leafname| leafname = leafname.gsub(/.*\/#{prefix}/, "") @log.debug(@prefix+@name, "adding leaf "+prefix+leafname) # a hash is used for leafs because the key (prefix+leafname) can be used to # directly access the desired object (by for example getObject) so we don't have # to iterate through the whole structure _recursively_. a hash will therefore be # much faster! @leafs.store(prefix+leafname, LeafFactory.getLeafFor(prefix, leafname, self, @log, @pen)) end end end end |
Instance Attribute Details
#conf ⇒ Object (readonly)
The configuration object.
42 43 44 |
# File 'lib/module_fhlow/node.rb', line 42 def conf @conf end |
#name ⇒ Object (readonly)
The name of the node.
36 37 38 |
# File 'lib/module_fhlow/node.rb', line 36 def name @name end |
#prefix ⇒ Object (readonly)
The prefix of the node.
39 40 41 |
# File 'lib/module_fhlow/node.rb', line 39 def prefix @prefix end |
Instance Method Details
#fetchDependencies ⇒ Object
Tells each children to fetch its dependencies.
132 133 134 135 |
# File 'lib/module_fhlow/node.rb', line 132 def fetchDependencies() @nodes.each_value { |node| node.fetchDependencies() } unless @nodes.empty? @leafs.each_value { |leaf| leaf.fetchDependencies() } unless @leafs.empty? end |
#getLeaf(_objectfootprint, _passthrough = 0) ⇒ Object
Returns the requested Leaf.
_objectfootprint
-
An Array that specifies where in the fhlow structure the leaf can be found. may look like these:
- “Prol16”, “Cpu”
- “grp/Prol16”, “unit/Cpu”
- “Cpu”
-
most likely the attribute
value
from Config::SimpleUnit, Config::ComplexUnit, Config::SimplePackage or Config::ComplexPackage will be used
_passthrough
-
The amount of passthroughs to a lower level in the fhlow structure.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/module_fhlow/node.rb', line 144 def getLeaf(_objectfootprint, _passthrough=0) raise FhlowException.new(@prefix+@name), "illegal _passthrough value: #{_passthrough}" if _passthrough < 0 if _passthrough > 0 # passthrough the request until the object that should know the # desired object is reached # -> go some levels down in the fhlow tree @parent.getLeaf(_objectfootprint, _passthrough-1) else # now request the desired object from child objects # -> go some levels down in the fhlow tree if _objectfootprint.length > 1 # there need to be nodes if there are more than one element in the _objectfootprint if _objectfootprint[0] =~ /(.*)\/(.*)/ # take care of exact definitions (grp/Fhlow, prj/Fhlow, etc) raise FhlowObjectNotFoundException.new(@prefix+@name), "No such object <#{$1}#{$2}>!" unless @nodes[$1+$2] @nodes[$1+$2].getLeaf(_objectfootprint[1..-1]) else # take care of multiple possiblities (unitTest and pkgTest in one group) possibilities = Array.new @nodes.each_key { |nodename| possibilities.push(nodename) if nodename =~ /.*#{_objectfootprint[0]}/ } raise FhlowObjectNotFoundException.new(@prefix+@name), "There are multible possibilities for node #{_objectfootprint[0]}: "+possiblities.join(", ") if possibilities.length > 1 raise FhlowObjectNotFoundException.new(@prefix+@name), "No such node <"+ (possibilities.empty? ? _objectfootprint[0].to_s : possibilities[0].to_s)+">!" unless @nodes[possibilities[0]] @nodes[possibilities[0]].getLeaf(_objectfootprint[1..-1]) end else if _objectfootprint[0] =~ /(.*)\/(.*)/ raise FhlowObjectNotFoundException.new(@prefix+@name), "No such object <#{$1}#{$2}>!" unless @leafs[$1+$2] return @leafs[$1+$2] # finally the object can be returned else possibilities = Array.new @leafs.each_key { |leafname| possibilities.push(leafname) if leafname =~ /.*#{_objectfootprint[0]}/ } raise FhlowObjectNotFoundException.new(@prefix+@name), "There are multible possibilities for leaf #{_objectfootprint[0]}: "+possibilities.join(", ") if possibilities.length > 1 raise FhlowObjectNotFoundException.new(@prefix+@name), "No such node <"+(possibilities.empty? ? _objectfootprint[0].to_s : possibilities[0].to_s)+">!" unless @leafs[possibilities[0]] return @leafs[possibilities[0]] # finally the object can be returned end end end end |
#getPath ⇒ Object
Returns the absolute path to the Node.
126 127 128 |
# File 'lib/module_fhlow/node.rb', line 126 def getPath @parent.getPath+@prefix+@name+"/" end |
#printMe(_prefix = " ") ⇒ Object
Prints the name of this group and information about its children.
_prefix
-
A prefix that is used for the output.
196 197 198 199 200 201 |
# File 'lib/module_fhlow/node.rb', line 196 def printMe(_prefix = " ") @pen.print _prefix,@name+"\n" @nodes.each_value {|x| x.printMe(_prefix+" "); puts x } unless @nodes.empty? @leafs.each_value {|x| x.printMe(_prefix+" ") } unless @leafs.empty? @pen.print "\n" end |