module Sbuilder class Resolver attr_reader :name # identity attr_reader :rules # array of rules:ResolverRule attr_reader :matcher # String or Regexp to match # ------------------------------------------------------------------ # mixer PROGNAME = "Resolver" # progname for logger include Sbuilder::Utils::MyLogger # mix logger # ------------------------------------------------------------------ # constrcutore def initialize( options = {} ) @logger = getLogger( PROGNAME, options ) @logger.info( "#{__method__} initialized" ) @rules = [] end # ------------------------------------------------------------------ # build it # add to @rules, return @rule def add_rule( rule ) rules << rule rules end # ------------------------------------------------------------------ # identify right matcher def setName( name ) @name = name end # # use attribute 'matcher' for string comparison or regepx comparisin # def matchesWithParamSet( paramSet ) # matcher.is_a?( String ) ? paramSet.getId == matcher : (paramSet.getId =~ matcher) != nil # end # match is 'String' or 'Regexp' def setMatch( matcher ) @matcher = matcher end # ------------------------------------------------------------------ # resolve def resolveDomains( paramSet, model ) @logger.info( "#{__method__} start paramSet.getId= #{paramSet.getId}, rules=#{rules.size}" ) paramSet.parametersToResolve.each do |parameter| @logger.debug( "#{__method__} resolving '#{parameter}'" ) if ! applyRule( parameter, model ) then raise ResolverException, "Could not resolve domain for parameter '#{parameter.getName}' in parameter set #{paramSet} #{ parameter.isReference ? '(with reference to ' + parameter.reference + ')' : '' }" end end end # iterate rules and find a match, must find one that matches def applyRule( parameter, model ) # No need resolve referenced paramters return true if parameter.isReference rules.each do |rule| if rule.applyRule( parameter, model ) then return true end end return false end end end