tla-sbuilder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +328 -0
  3. data/VERSION +1 -0
  4. data/bin/sbuilder.rb +5 -0
  5. data/lib/cli/cli-customer.rb +420 -0
  6. data/lib/cli/cli-example.rb +92 -0
  7. data/lib/cli/cli-pet.rb +767 -0
  8. data/lib/cli/cli-text.rb +226 -0
  9. data/lib/cli/cli.rb +298 -0
  10. data/lib/sbuilder.rb +52 -0
  11. data/lib/sbuilder/constants.rb +72 -0
  12. data/lib/sbuilder/controller.rb +798 -0
  13. data/lib/sbuilder/default-sbuilder.yaml +372 -0
  14. data/lib/sbuilder/domain.rb +124 -0
  15. data/lib/sbuilder/domain_cardinality.rb +37 -0
  16. data/lib/sbuilder/domain_value.rb +81 -0
  17. data/lib/sbuilder/exception.rb +27 -0
  18. data/lib/sbuilder/extension_loader.rb +721 -0
  19. data/lib/sbuilder/factory.rb +234 -0
  20. data/lib/sbuilder/model.rb +356 -0
  21. data/lib/sbuilder/mustache/template.rb +125 -0
  22. data/lib/sbuilder/mustache/template_reader.rb +206 -0
  23. data/lib/sbuilder/mustache/template_reader_context.rb +371 -0
  24. data/lib/sbuilder/param_set.rb +132 -0
  25. data/lib/sbuilder/param_set_db.rb +20 -0
  26. data/lib/sbuilder/param_set_def.rb +57 -0
  27. data/lib/sbuilder/param_set_if.rb +68 -0
  28. data/lib/sbuilder/param_set_loader.rb +77 -0
  29. data/lib/sbuilder/param_set_loader_swagger.rb +424 -0
  30. data/lib/sbuilder/param_set_step.rb +62 -0
  31. data/lib/sbuilder/param_sets.rb +54 -0
  32. data/lib/sbuilder/parameter.rb +97 -0
  33. data/lib/sbuilder/parameter_container.rb +72 -0
  34. data/lib/sbuilder/parameter_dom.rb +70 -0
  35. data/lib/sbuilder/parameter_ref.rb +71 -0
  36. data/lib/sbuilder/resolver.rb +78 -0
  37. data/lib/sbuilder/resolver_loader.rb +79 -0
  38. data/lib/sbuilder/resolver_loader_yaml.rb +103 -0
  39. data/lib/sbuilder/resolver_rule.rb +36 -0
  40. data/lib/sbuilder/resolver_rule_match.rb +55 -0
  41. data/lib/sbuilder/resolver_rule_ref.rb +37 -0
  42. data/lib/utils/hash_inject.rb +12 -0
  43. data/lib/utils/logger.rb +80 -0
  44. data/lib/utils/netio.rb +58 -0
  45. data/lib/utils/string_inject.rb +10 -0
  46. data/lib/utils/version.rb +13 -0
  47. data/mustache/cfg/const_def.mustache +8 -0
  48. data/mustache/cfg/const_run.mustache +3 -0
  49. data/mustache/cfg/invariant-infrastructure-service.mustache +4 -0
  50. data/mustache/cfg/macro_run.mustache +6 -0
  51. data/mustache/cfg/module_footer.mustache +0 -0
  52. data/mustache/cfg/module_header.mustache +7 -0
  53. data/mustache/data-model-dump.mustache +19 -0
  54. data/mustache/data-model-footer.mustache +5 -0
  55. data/mustache/data-model-header.mustache +16 -0
  56. data/mustache/definition_types.mustache +40 -0
  57. data/mustache/domains.mustache +20 -0
  58. data/mustache/domains_assign.mustache +22 -0
  59. data/mustache/domains_run.mustache +21 -0
  60. data/mustache/extend/extend_assumptions.mustache +7 -0
  61. data/mustache/extend/extend_const.mustache +5 -0
  62. data/mustache/extend/extend_implementation.mustache +9 -0
  63. data/mustache/extend/extend_invariant.mustache +7 -0
  64. data/mustache/extend/extend_invariant_cfg.mustache +7 -0
  65. data/mustache/extend/extend_macros.mustache +19 -0
  66. data/mustache/extend/extend_operations.mustache +9 -0
  67. data/mustache/extend/extend_state.mustache +9 -0
  68. data/mustache/infrastructure-service-init.mustache +36 -0
  69. data/mustache/infrastructure-service-variables.mustache +10 -0
  70. data/mustache/interface_processes.mustache +38 -0
  71. data/mustache/interface_stubs_dummy.mustache +13 -0
  72. data/mustache/interface_types.mustache +52 -0
  73. data/mustache/markdown-header.mustache +24 -0
  74. data/mustache/markdown-toc.mustache +13 -0
  75. data/mustache/name_definition_type.mustache +5 -0
  76. data/mustache/name_domain.mustache +5 -0
  77. data/mustache/name_domain_value.mustache +5 -0
  78. data/mustache/name_domain_value_prefix.mustache +5 -0
  79. data/mustache/name_interface_response_type.mustache +6 -0
  80. data/mustache/name_interface_type.mustache +6 -0
  81. data/mustache/name_parameter_definition.mustache +5 -0
  82. data/mustache/name_parameter_type.mustache +6 -0
  83. data/mustache/name_process.mustache +6 -0
  84. data/mustache/name_type_invariant.mustache +5 -0
  85. data/mustache/name_variable.mustache +6 -0
  86. data/mustache/operator-infrastructure-service.mustache +13 -0
  87. data/mustache/possibility/module_extends.mustache +1 -0
  88. data/mustache/possibility/module_footer.mustache +1 -0
  89. data/mustache/possibility/module_header.mustache +8 -0
  90. data/mustache/possibility/possibility_definition.mustache +12 -0
  91. data/mustache/possibility/possibility_directive.mustache +1 -0
  92. data/mustache/possibility/possility_setup.mustache +28 -0
  93. data/mustache/setup/module_footer.mustache +1 -0
  94. data/mustache/setup/module_header.mustache +9 -0
  95. data/mustache/setup/operator_run.mustache +7 -0
  96. data/mustache/setup/operator_tick.mustache +2 -0
  97. data/mustache/setup/steps_run.mustache +22 -0
  98. data/mustache/setup/steps_run_bind_rule.mustache +51 -0
  99. data/mustache/setup/steps_run_bind_set.mustache +37 -0
  100. data/mustache/setup/steps_run_parameterBind.mustache +80 -0
  101. data/mustache/setup/steps_run_parameterExact.mustache +79 -0
  102. data/mustache/state_type_invariant-infrastructure-service.mustache +49 -0
  103. data/mustache/state_type_invariant.mustache +17 -0
  104. data/mustache/state_type_invariant_cfg.mustache +18 -0
  105. data/mustache/state_variables.mustache +20 -0
  106. data/mustache/tla/const_def.mustache +5 -0
  107. data/mustache/tla/const_run.mustache +3 -0
  108. data/mustache/tla/macro-infrastructure-service.mustache +14 -0
  109. data/mustache/tla/macro_run.mustache +40 -0
  110. data/mustache/tla/module_footer.mustache +2 -0
  111. data/mustache/tla/module_header.mustache +9 -0
  112. data/mustache/tla/operator_run.mustache +8 -0
  113. data/mustache/tla/operators-infrastructure-service.mustache +12 -0
  114. data/mustache/tla/plc_define_footer.mustache +1 -0
  115. data/mustache/tla/plc_define_header.mustache +1 -0
  116. data/mustache/tla/plc_define_run.mustache +59 -0
  117. data/mustache/tla/plc_footer.mustache +2 -0
  118. data/mustache/tla/plc_header.mustache +2 -0
  119. data/mustache/tla/plc_run_state.mustache +12 -0
  120. data/mustache/tla/plc_tail.mustache +8 -0
  121. data/mustache/tla/plc_translation.mustache +2 -0
  122. data/resources/schema/json_schema/draft-04.json +150 -0
  123. data/resources/schema/swagger/2.0/schema.json +1591 -0
  124. data/src-extend/README +2 -0
  125. data/src-extend/extend/extend_assumptions.mustache +7 -0
  126. data/src-extend/extend/extend_const.mustache +5 -0
  127. data/src-extend/extend/extend_implementation.mustache +9 -0
  128. data/src-extend/extend/extend_invariant.mustache +11 -0
  129. data/src-extend/extend/extend_invariant_cfg.mustache +7 -0
  130. data/src-extend/extend/extend_macros.mustache +19 -0
  131. data/src-extend/extend/extend_operations.mustache +9 -0
  132. data/src-extend/extend/extend_state.mustache +9 -0
  133. data/src-extend/extend_app/assumption +20 -0
  134. data/src-extend/extend_app/correctness +19 -0
  135. data/src-extend/extend_app/correctness.cfg +9 -0
  136. data/src-extend/extend_app/infrastructure +25 -0
  137. data/src-extend/extend_app/interface +11 -0
  138. data/src-extend/extend_app/operator +18 -0
  139. data/src-extend/extend_app/possibility +16 -0
  140. data/src-extend/extend_app/service +33 -0
  141. data/src-extend/extend_app/state +16 -0
  142. data/src-extend/extend_app/transaction +22 -0
  143. data/src/pet/assumption +29 -0
  144. data/src/pet/assumption_address_domains.tla +12 -0
  145. data/src/pet/assumption_domains.tla +16 -0
  146. data/src/pet/assumption_generic.tla +8 -0
  147. data/src/pet/assumption_id_domains.tla +2 -0
  148. data/src/pet/assumption_owner_domains.tla +14 -0
  149. data/src/pet/assumption_pet_domains.tla +16 -0
  150. data/src/pet/assumption_tag_domains.tla +13 -0
  151. data/src/pet/correctness +24 -0
  152. data/src/pet/correctness.cfg +9 -0
  153. data/src/pet/correctness_coherent_owner_address.tla +6 -0
  154. data/src/pet/correctness_pet_name.tla +4 -0
  155. data/src/pet/correctness_ref_tag.tla +13 -0
  156. data/src/pet/correctness_type_invariants.tla +12 -0
  157. data/src/pet/correctness_unique_pet.tla +3 -0
  158. data/src/pet/correctness_unique_tag.tla +3 -0
  159. data/src/pet/docs/Petstore.md +117 -0
  160. data/src/pet/extend/extend_assumptions.mustache +7 -0
  161. data/src/pet/extend/extend_implementation.mustache +9 -0
  162. data/src/pet/extend/extend_invariant.mustache +11 -0
  163. data/src/pet/extend/extend_invariant_cfg.mustache +7 -0
  164. data/src/pet/extend/extend_macros.mustache +19 -0
  165. data/src/pet/extend/extend_operations.mustache +9 -0
  166. data/src/pet/extend/extend_state.mustache +9 -0
  167. data/src/pet/infrastructure +25 -0
  168. data/src/pet/infrastructure_id_get.tla +24 -0
  169. data/src/pet/interface +12 -0
  170. data/src/pet/interface_delete_pet.tla +5 -0
  171. data/src/pet/interface_get_pet.tla +4 -0
  172. data/src/pet/interface_post_pet.tla +5 -0
  173. data/src/pet/interface_post_tag.tla +5 -0
  174. data/src/pet/interface_put_tag.tla +3 -0
  175. data/src/pet/operator +30 -0
  176. data/src/pet/operator_find_tag_by_owner_name.tla +1 -0
  177. data/src/pet/operator_get_pet.tla +4 -0
  178. data/src/pet/operator_get_pet_by_tag.tla +4 -0
  179. data/src/pet/operator_get_tag.tla +10 -0
  180. data/src/pet/operator_new_owner.tla +3 -0
  181. data/src/pet/operator_new_pet.tla +13 -0
  182. data/src/pet/operator_new_tag.tla +3 -0
  183. data/src/pet/operator_next_pet_id.tla +3 -0
  184. data/src/pet/operator_responses.tla +8 -0
  185. data/src/pet/operator_tag_exists.tla +2 -0
  186. data/src/pet/operator_tag_owner_validated.tla +2 -0
  187. data/src/pet/operator_tag_referenced.tla +4 -0
  188. data/src/pet/operator_valid_owner.tla +17 -0
  189. data/src/pet/operator_valid_pet.tla +6 -0
  190. data/src/pet/operator_valid_tag.tla +5 -0
  191. data/src/pet/possibility +18 -0
  192. data/src/pet/possibility_at_least_two_tags.tla +12 -0
  193. data/src/pet/possibility_invalid_tag_address.tla +8 -0
  194. data/src/pet/service +35 -0
  195. data/src/pet/service_pet_delete.tla +11 -0
  196. data/src/pet/service_pet_get.tla +27 -0
  197. data/src/pet/service_pet_post.tla +78 -0
  198. data/src/pet/service_tag_post.tla +53 -0
  199. data/src/pet/service_tag_put.tla +82 -0
  200. data/src/pet/state +16 -0
  201. data/src/pet/state_infra.tla +6 -0
  202. data/src/pet/state_pet.tla +5 -0
  203. data/src/pet/state_tag_id.tla +2 -0
  204. data/src/pet/transaction +23 -0
  205. data/src/pet/transaction_delete_pet.tla +13 -0
  206. data/src/pet/transaction_enter_pet.tla +13 -0
  207. data/src/pet/transaction_enter_tag.tla +56 -0
  208. data/src/pet/transaction_error.tla +23 -0
  209. data/tla-sbuilder.gemspec +43 -0
  210. metadata +353 -0
@@ -0,0 +1,62 @@
1
+ module Sbuilder
2
+
3
+ # interface paramter set extending interface
4
+ class ParamSetStep < ParamSet
5
+
6
+ attr_reader :bindExact # return return boolead
7
+ attr_reader :interfaceReference # return interface:paramSet referenced
8
+ attr_reader :inputs # array of inputs
9
+
10
+ # ------------------------------------------------------------------
11
+ # mixer
12
+ PROGNAME = "ParamSetStep" # progname for logger
13
+ include Sbuilder::Utils::MyLogger # mix logger
14
+
15
+ # constrcutore
16
+ def initialize( options = {} )
17
+ super( options )
18
+ @logger = getLogger( PROGNAME, options )
19
+ @logger.info( "#{__method__} initialized" )
20
+
21
+ # default - use rule
22
+ @bindExact = false
23
+ @inputs = []
24
+ end
25
+
26
+ # ------------------------------------------------------------------
27
+ # setInterfaceRefence
28
+
29
+ # configure
30
+ def setInterfaceReference( interfaceParamSet )
31
+ @interfaceReference = interfaceParamSet
32
+ self
33
+ end
34
+
35
+ # identity - deletegate to reference
36
+ def doGetId
37
+ interfaceReference.getId
38
+ end
39
+
40
+ # ------------------------------------------------------------------
41
+ # build
42
+ # def setInputs( inputs )
43
+ # @inputs = inputs
44
+ # end
45
+
46
+ def addInput( input )
47
+ @inputs << input
48
+ self
49
+ end
50
+
51
+ # ------------------------------------------------------------------
52
+ # bindExact
53
+ def setBindExact( bindExact )
54
+ @bindExact = bindExact.nil? ? false : bindExact
55
+ self
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+
@@ -0,0 +1,54 @@
1
+ require 'tsort' # to sort paramset in correct order
2
+
3
+ module Sbuilder
4
+
5
+ class ParamSets < Hash
6
+
7
+ attr_reader :model # to resolve paramSets
8
+
9
+ include TSort # sort in correct order
10
+
11
+ # ------------------------------------------------------------------
12
+ # constructore
13
+
14
+ class << self
15
+
16
+ def create( model )
17
+ new( model )
18
+ end
19
+
20
+ private :new
21
+
22
+ end # class methods
23
+
24
+ def initialize( model )
25
+ @model = model
26
+ end
27
+
28
+ # ------------------------------------------------------------------
29
+ # tsort
30
+
31
+ alias tsort_each_node each_key
32
+
33
+ def tsort_each_child( paramSetName, &block)
34
+
35
+ # # no depencies if no name ??
36
+ # return unless key?( paramSetName )
37
+
38
+ # access the object to sort
39
+ # puts "fetch(#{paramSetName}) in #{keys}"
40
+ paramSet = fetch(paramSetName)
41
+
42
+ # find dependencies amongst the refenced paramSets (TestCase)
43
+ paramSet.parameters.
44
+ select do |parameter|
45
+ parameter.isReference
46
+ end. # consider only refences
47
+ map do |parameter|
48
+ parameter.getResolvedReference( model ).getId
49
+ end. # resolve paramSet referenced
50
+ each(&block) # process tsort block for each paramSetname
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,97 @@
1
+
2
+ module Sbuilder
3
+
4
+ class Parameter
5
+
6
+ attr_reader :name
7
+ attr_reader :isArray # defaults 'false'
8
+
9
+
10
+ # ------------------------------------------------------------------
11
+ # mixer
12
+ PROGNAME = "Parameter" # progname for logger
13
+ include Sbuilder::Utils::MyLogger # mix logger
14
+
15
+ # ------------------------------------------------------------------
16
+ # constrcutore
17
+ def initialize( options = {} )
18
+ @logger = getLogger( PROGNAME, options )
19
+ @logger.info( "#{__method__} initialized" )
20
+ # default is not an arrays
21
+ @isArray = false
22
+ end
23
+
24
+ # def self.create( name )
25
+ # p = Parameter.new
26
+ # p.setName( name )
27
+ # end
28
+
29
+ # ------------------------------------------------------------------
30
+ # build identity
31
+
32
+ def setName( name )
33
+ @name = name
34
+ self
35
+ end
36
+
37
+ def getName()
38
+ return name.
39
+ gsub( / /, "" ) # remove spaces
40
+ end
41
+
42
+ def setIsArray( isArray = true )
43
+ @isArray = isArray
44
+ self
45
+ end
46
+
47
+ # is NOT reference (override in sub-class if is a reference)
48
+ def isReference
49
+ false
50
+ end
51
+
52
+
53
+
54
+ # ------------------------------------------------------------------
55
+ # generate (build model)
56
+
57
+ # domain or reference parameter set
58
+ def getType
59
+ return doGetType
60
+ end
61
+
62
+ def doGetType
63
+ msg = "Sub class should implement doGetType -method"
64
+ @logger.error( "#{__method__} #{msg}" )
65
+ raise NoMethodError.new( msg )
66
+ end
67
+
68
+ # ------------------------------------------------------------------
69
+ # create patermeter definition
70
+
71
+ def parameter_definition( model )
72
+ {
73
+ :parameter_name => getName,
74
+ :isArray => isArray,
75
+ }.merge!( do_parameter_definition( model ) )
76
+ end
77
+
78
+
79
+ def do_parameter_definition( model )
80
+ msg = "Sub class should implement do_parameter_definition -method"
81
+ @logger.error( "#{__method__} #{msg}" )
82
+ raise NoMethodError.new( msg )
83
+ end
84
+
85
+ # ------------------------------------------------------------------
86
+ # resolve
87
+
88
+ # resolve parametSet reference in 'model': simple parameter
89
+ # resolves to 'self'
90
+ def getResolvedReference( model )
91
+ self
92
+ end
93
+
94
+
95
+ end # class
96
+
97
+ end
@@ -0,0 +1,72 @@
1
+
2
+ module Sbuilder
3
+
4
+ class ParameterContainer < Parameter
5
+
6
+ attr_reader :domainElement # access configured domain Id
7
+ # TODO: refractor domainElement to a sub-class
8
+ attr_reader :parameter # parameter-->domain-->(check cardinality)->domainElement
9
+ attr_reader :parameters # array of hash names: modeling hash
10
+ attr_reader :rows # modeling array
11
+
12
+ # ------------------------------------------------------------------
13
+ # mixer
14
+ PROGNAME = "ParameterContainer" # progname for logger
15
+ include Sbuilder::Utils::MyLogger # mix logger
16
+
17
+ # ------------------------------------------------------------------
18
+ # constrcutore
19
+ def initialize( options = {} )
20
+ super( options )
21
+ @logger = getLogger( PROGNAME, options )
22
+ @logger.info( "#{__method__} initialized" )
23
+ end
24
+
25
+ # ------------------------------------------------------------------
26
+ # build
27
+
28
+ def setDomainElement( domainElement )
29
+ @domainElement = domainElement
30
+ self
31
+ end
32
+
33
+ # set a reference
34
+ def setParameter( parameter )
35
+ @parameter = parameter
36
+ self
37
+ end
38
+
39
+ # add to collection
40
+ def addParameter( parameter )
41
+ @parameters = [] if @parameters.nil?
42
+ @parameters << parameter
43
+ self
44
+ end
45
+
46
+ # add to collection
47
+ def addParameter( parameter )
48
+ @parameters = [] if @parameters.nil?
49
+ @parameters << parameter
50
+ self
51
+ end
52
+
53
+ # add to collection
54
+ def addRow( parameter )
55
+ @rows = [] if @rows.nil?
56
+ @rows << parameter
57
+ self
58
+ end
59
+
60
+ # ------------------------------------------------------------------
61
+ # genarate phase
62
+ def do_parameter_definition( model )
63
+
64
+ # ret = parameters.inject( [] ) { |arr, parameter| arr << { :parameter_name[parameter.name] = "value for #{parameter.name}" }
65
+ ret
66
+ end
67
+
68
+
69
+ end
70
+ end
71
+
72
+
@@ -0,0 +1,70 @@
1
+
2
+ module Sbuilder
3
+
4
+ class Parameter_Dom < Parameter
5
+
6
+ attr_reader :domain # name resolved
7
+ attr_reader :resolvedDomain # pointer to Domain-object
8
+
9
+ # ------------------------------------------------------------------
10
+ # mixer
11
+ PROGNAME = "ParameterDom" # progname for logger
12
+ include Sbuilder::Utils::MyLogger # mix logger
13
+
14
+
15
+ # ------------------------------------------------------------------
16
+ # constrcutore
17
+ def initialize( options = {} )
18
+ super( options )
19
+ @logger = getLogger( PROGNAME, options )
20
+ @logger.info( "#{__method__} initialized" )
21
+ end
22
+
23
+ def self.create( name, domain )
24
+ p = Parameter_Dom.new
25
+ p.setName( name )
26
+ p.setDomain( domain )
27
+ end
28
+
29
+ def to_s
30
+ "#{PROGNAME}: name: '#{getName}', domain='#{ domain }'"
31
+ end
32
+
33
+ # ------------------------------------------------------------------
34
+ # build domain
35
+
36
+ def setDomain( domain )
37
+ @domain = domain
38
+ self
39
+ end
40
+
41
+ # ------------------------------------------------------------------
42
+ # resolve
43
+ def resolveDomain( model )
44
+ # access domain(name) from model, exception if not found
45
+ @resolvedDomain = model.getDomain( domain )
46
+ end
47
+
48
+
49
+ # ------------------------------------------------------------------
50
+ # build model
51
+
52
+ def doGetType
53
+ domain
54
+ end
55
+
56
+ def do_parameter_definition( model )
57
+ {
58
+ # :name => name,
59
+ :type => domain,
60
+ :namespace => Constants::TYPE_NAMESPACE_DOM, # in TLA code prefix with 'd_',
61
+ :composite_parameters => false,
62
+ }
63
+ end
64
+
65
+
66
+
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,71 @@
1
+
2
+ module Sbuilder
3
+
4
+ class Parameter_Ref < Parameter
5
+
6
+ attr_reader :reference # name of paramSet being pointed
7
+
8
+ # ------------------------------------------------------------------
9
+ # mixer
10
+ PROGNAME = "ParameterRef" # progname for logger
11
+ include Sbuilder::Utils::MyLogger # mix logger
12
+
13
+ # ------------------------------------------------------------------
14
+ # constrcutore
15
+ def initialize( options = {} )
16
+ super( options )
17
+ @logger = getLogger( PROGNAME, options )
18
+ @logger.info( "#{__method__} initialized" )
19
+ end
20
+
21
+ def self.create( name, paramSetName )
22
+ p = Parameter_Ref.new
23
+ p.setName( name )
24
+ p.setReference( paramSetName )
25
+ end
26
+
27
+
28
+ # ------------------------------------------------------------------
29
+ # configure
30
+ def setReference( paramSetName )
31
+ @reference = paramSetName
32
+ self
33
+ end
34
+
35
+ # is reference && valid reference configured
36
+ def isReference
37
+ ! @reference.nil?
38
+ end
39
+
40
+ # ------------------------------------------------------------------
41
+ # resolve
42
+
43
+ # resolve parametSet reference in 'model'
44
+ def getResolvedReference( model )
45
+ model.getParamset( reference )
46
+ end
47
+
48
+
49
+ # ------------------------------------------------------------------
50
+ # build model
51
+
52
+ def doGetType
53
+ reference
54
+ end
55
+
56
+ def do_parameter_definition( model )
57
+ {
58
+ # :name => name,
59
+ :type => reference,
60
+ :namespace => Constants::TYPE_NAMESPACE_REF, # in TLA code prefix with 't_'
61
+ :composite_parameters => getResolvedReference(model).parameter_definitions( model ),
62
+ }
63
+ end
64
+
65
+ def to_s
66
+ reference ? reference.to_s : ""
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,78 @@
1
+
2
+ module Sbuilder
3
+
4
+ class Resolver
5
+
6
+ attr_reader :name # identity
7
+ attr_reader :rules # array of rules:ResolverRule
8
+ attr_reader :matcher # String or Regexp to match
9
+
10
+ # ------------------------------------------------------------------
11
+ # mixer
12
+ PROGNAME = "Resolver" # progname for logger
13
+ include Sbuilder::Utils::MyLogger # mix logger
14
+
15
+ # ------------------------------------------------------------------
16
+ # constrcutore
17
+ def initialize( options = {} )
18
+ @logger = getLogger( PROGNAME, options )
19
+ @logger.info( "#{__method__} initialized" )
20
+ @rules = []
21
+ end
22
+
23
+ # ------------------------------------------------------------------
24
+ # build it
25
+
26
+ # add to @rules, return @rule
27
+ def add_rule( rule )
28
+ rules << rule
29
+ rules
30
+ end
31
+
32
+ # ------------------------------------------------------------------
33
+ # identify right matcher
34
+
35
+ def setName( name )
36
+ @name = name
37
+ end
38
+
39
+ # # use attribute 'matcher' for string comparison or regepx comparisin
40
+ # def matchesWithParamSet( paramSet )
41
+ # matcher.is_a?( String ) ? paramSet.getId == matcher : (paramSet.getId =~ matcher) != nil
42
+ # end
43
+
44
+ # match is 'String' or 'Regexp'
45
+ def setMatch( matcher )
46
+ @matcher = matcher
47
+ end
48
+
49
+ # ------------------------------------------------------------------
50
+ # resolve
51
+ def resolveDomains( paramSet, model )
52
+ @logger.info( "#{__method__} start paramSet.getId= #{paramSet.getId}, rules=#{rules.size}" )
53
+ paramSet.parametersToResolve.each do |parameter|
54
+ @logger.debug( "#{__method__} resolving '#{parameter}'" )
55
+ if ! applyRule( parameter, model ) then
56
+ raise ResolverException, "Could not resolve domain for parameter '#{parameter.getName}' in parameter set #{paramSet} #{ parameter.isReference ? '(with reference to ' + parameter.reference + ')' : '' }"
57
+ end
58
+ end
59
+ end
60
+
61
+ # iterate rules and find a match, must find one that matches
62
+ def applyRule( parameter, model )
63
+ # No need resolve referenced paramters
64
+ return true if parameter.isReference
65
+ rules.each do |rule|
66
+ if rule.applyRule( parameter, model ) then
67
+ return true
68
+ end
69
+ end
70
+ return false
71
+
72
+ end
73
+
74
+
75
+ end
76
+
77
+ end
78
+