Class: RGen::Instantiator::QualifiedNameResolver
- Inherits:
-
Object
- Object
- RGen::Instantiator::QualifiedNameResolver
- Defined in:
- lib/rgen/instantiator/qualified_name_resolver.rb
Overview
This is a resolver resolving element identifiers which are qualified names.
Instance Attribute Summary collapse
-
#leadingSeparator ⇒ Object
readonly
Returns the value of attribute leadingSeparator.
-
#nameAttribute ⇒ Object
readonly
Returns the value of attribute nameAttribute.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
-
#initialize(rootElements, options = {}) ⇒ QualifiedNameResolver
constructor
A new instance of QualifiedNameResolver.
- #resolveIdentifier(qualifiedName) ⇒ Object
- #resolveReferences(unresolvedReferences, problems = []) ⇒ Object
Constructor Details
#initialize(rootElements, options = {}) ⇒ QualifiedNameResolver
Returns a new instance of QualifiedNameResolver.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 14 def initialize(rootElements, ={}) @rootElements = rootElements @nameAttribute = [:nameAttribute] || "name" @separator = [:separator] || "/" @leadingSeparator = .has_key?(:leadingSeparator) ? [:leadingSeparator] : true @elementByQName = {} @visitedQName = {} @childReferences = {} @resolverDelegate = ReferenceResolver.new(:identifier_resolver => method(:resolveIdentifier)) end |
Instance Attribute Details
#leadingSeparator ⇒ Object (readonly)
Returns the value of attribute leadingSeparator.
12 13 14 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 12 def leadingSeparator @leadingSeparator end |
#nameAttribute ⇒ Object (readonly)
Returns the value of attribute nameAttribute.
10 11 12 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 10 def nameAttribute @nameAttribute end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
11 12 13 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 11 def separator @separator end |
Instance Method Details
#resolveIdentifier(qualifiedName) ⇒ Object
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 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 25 def resolveIdentifier(qualifiedName) return @elementByQName[qualifiedName] if @elementByQName.has_key?(qualifiedName) path = qualifiedName.split(separator).reject{|s| s == ""} if path.size > 1 parentQName = (leadingSeparator ? separator : "") + path[0..-2].join(separator) parents = resolveIdentifier(parentQName) parents = [parents].compact unless parents.is_a?(Array) children = parents.collect{|p| allNamedChildren(p)}.flatten elsif path.size == 1 parentQName = "" children = allRootNamedChildren else return @elementByQName[qualifiedName] = nil end # if the parent was already visited all matching elements are the hash if !@visitedQName[parentQName] children.each do |c| name = c.send(nameAttribute) if name qname = parentQName + ((parentQName != "" || leadingSeparator) ? separator : "") + name existing = @elementByQName[qname] if existing @elementByQName[qname] = [existing] unless existing.is_a?(Array) @elementByQName[qname] << c else @elementByQName[qname] = c end end end # all named children of praent have been checked and hashed @visitedQName[parentQName] = true end @elementByQName[qualifiedName] ||= nil end |
#resolveReferences(unresolvedReferences, problems = []) ⇒ Object
60 61 62 |
# File 'lib/rgen/instantiator/qualified_name_resolver.rb', line 60 def resolveReferences(unresolvedReferences, problems=[]) @resolverDelegate.resolve(unresolvedReferences, :problems => problems) end |