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,372 @@
1
+
2
+ # ------------------------------------------------------------------
3
+ # default generation configs, with template extension points
4
+
5
+ generate:
6
+
7
+ # ----------------------------------------
8
+ # Default model.tla.
9
+ #
10
+ # Override template extension points
11
+ # - extend_const.tla
12
+ # - extend_state.tla
13
+ # - extend_operations.tla
14
+ # - extend_macros.tla
15
+ # - extend_implementation.tla
16
+ # - extend_invariant.tla
17
+ # - extend_assumptions.tla
18
+
19
+
20
+
21
+ - output: tla/model.tla
22
+ inputs:
23
+
24
+ - desc: Hader for tla module
25
+ template: tla/module_header.mustache
26
+ modelData: none
27
+
28
+ - desc: Constants for environment model
29
+ template: tla/const_run.mustache
30
+ modelData: none
31
+
32
+ - desc: Constants for specification
33
+ template: tla/const_def.mustache
34
+ modelData: none
35
+
36
+ # --------------------
37
+ # extension point: extend_const.tla
38
+ - desc: Extension point for constants
39
+ template: extend/extend_const.mustache
40
+ modelData: none
41
+
42
+ - desc: Domain definitions
43
+ template: domains.mustache
44
+ modelData: domains
45
+
46
+ - desc: Environment operators
47
+ template: tla/operator_run.mustache
48
+ modelData: none
49
+
50
+ - desc: Initial value for infrastructure service responses
51
+ template: infrastructure-service-init.mustache
52
+ modelData: infrastructureServices
53
+
54
+ - desc: Data type definitions
55
+ template: definition_types.mustache
56
+ modelData: definitions
57
+
58
+ - desc: Interface types
59
+ template: interface_types.mustache
60
+ modelData: interfaces
61
+
62
+ - desc: Start of plc block
63
+ template: tla/plc_header.mustache
64
+ modelData: none
65
+
66
+ - desc: State environment model
67
+ template: tla/plc_run_state.mustache
68
+ modelData: none
69
+
70
+ - desc: Variables used by infrastructure-services
71
+ template: infrastructure-service-variables.mustache
72
+ modelData: none
73
+
74
+
75
+ # --------------------
76
+ # extension point: extend_state.tla
77
+
78
+ - desc: Extension point for specification state
79
+ template: extend/extend_state.mustache
80
+ modelData: none
81
+
82
+ - desc: Specification state
83
+ template: state_variables.mustache
84
+ modelData: variables
85
+
86
+ - desc: Start of plc define block
87
+ template: tla/plc_define_header.mustache
88
+ modelData: none
89
+
90
+ - desc: Environment execution operators
91
+ template: tla/plc_define_run.mustache
92
+ modelData: none
93
+
94
+ - desc: Operators for infrastrcuture service (generated)
95
+ template: operator-infrastructure-service.mustache
96
+ modelData: infrastructureServices
97
+
98
+
99
+ - desc: Operators supporting infrastructure services
100
+ template: tla/operators-infrastructure-service.mustache
101
+ modelData: none
102
+
103
+ # --------------------
104
+ # extension point: extend_operations.tla
105
+
106
+ - desc: Extension point for operations
107
+ template: extend/extend_operations.mustache
108
+ modelData: none
109
+
110
+ - desc: End of plc define block
111
+ template: tla/plc_define_footer.mustache
112
+ modelData: none
113
+
114
+ - desc: Environment execution macros (state change)
115
+ template: tla/macro_run.mustache
116
+ modelData: none
117
+
118
+ - desc: Macros for infrastructure services
119
+ template: tla/macro-infrastructure-service.mustache
120
+ modelData: none
121
+
122
+ # --------------------
123
+ # extension point: extend_macros.tla
124
+
125
+ - desc: Extension poin to add macros
126
+ template: extend/extend_macros.mustache
127
+ modelData: none
128
+
129
+ - desc: Create a dummy procedure to have 'defaultInitValue' in the model
130
+ template: interface_stubs_dummy.mustache
131
+ modelData: none
132
+
133
+ # --------------------
134
+ # extension point: extend_implementation.tla
135
+
136
+ - desc: Extension point for implementation
137
+ template: extend/extend_implementation.mustache
138
+ modelData: none
139
+
140
+ - desc: Process interfaces
141
+ template: interface_processes.mustache
142
+ modelData: interfaces
143
+
144
+ - desc: Environment model 'Tail' process
145
+ template: tla/plc_tail.mustache
146
+ modelData: none
147
+
148
+ - desc: End of plc block
149
+ template: tla/plc_footer.mustache
150
+ modelData: none
151
+
152
+ - desc: Plc translation section
153
+ template: tla/plc_translation.mustache
154
+ modelData: none
155
+
156
+ - desc: Type constraint in specification
157
+ template: state_type_invariant.mustache
158
+ modelData: variables
159
+
160
+ # --------------------
161
+ # extension point: extend_type_invariant.tla
162
+
163
+ # - desc: Extension point for type invariants
164
+ # template: extend/extend_type_invariant.tla
165
+ # modelData: none
166
+
167
+ - desc: Validate types for infrastructure service return values
168
+ template: state_type_invariant-infrastructure-service.mustache
169
+ modelData: infrastructureServices
170
+
171
+
172
+ # --------------------
173
+ # extension point: extend_invariant.tla
174
+
175
+ - desc: Extension point for specification invariants
176
+ template: extend/extend_invariant.mustache
177
+ modelData: none
178
+
179
+ # --------------------
180
+ # extension point: extend_assumptions.tla
181
+ - desc: Extension point for assumptions
182
+ template: extend/extend_assumptions.mustache
183
+ modelData: none
184
+
185
+ - desc: module_footer.tla
186
+ template: tla/module_footer.mustache
187
+ modelData: none
188
+
189
+ # ----------------------------------------
190
+ # Default setup.cfg
191
+ #
192
+ # Override template extension points
193
+ # - extend_invariant.cfg
194
+
195
+
196
+ - output: tla/setup.cfg
197
+ inputs:
198
+
199
+ - desc: Configuration module header
200
+ template: cfg/module_header.mustache
201
+ modelData: none
202
+
203
+ - desc: Environment execution step assignments
204
+ template: cfg/const_run.mustache
205
+ modelData: none
206
+
207
+ - desc: Environment execution macro assignments
208
+ template: cfg/macro_run.mustache
209
+ modelData: none
210
+
211
+ - desc: Specification constans assignments
212
+ template: cfg/const_def.mustache
213
+ modelData: none
214
+
215
+
216
+ # - desc: processes stubs in specification
217
+ # template: interface_stubs.mustache
218
+ # modelData: interfaces
219
+
220
+
221
+ - desc: Configure specification domains
222
+ template: domains_assign.mustache
223
+ modelData: domains
224
+
225
+ - desc: Activate specification invariants
226
+ template: state_type_invariant_cfg.mustache
227
+ modelData: variables
228
+
229
+ - desc: Activate type invariants for infrastrcuture services
230
+ template: cfg/invariant-infrastructure-service.mustache
231
+ modelData: none
232
+
233
+
234
+ # --------------------
235
+ # extension point: extend_type_invariant.cfg
236
+ # - desc: Extesion pointo to activate type constraints
237
+ # template: extend/extend_type_invariant.cfg
238
+ # modelData: none
239
+
240
+ # --------------------
241
+ # extension point: extend_invariant.cfg
242
+
243
+ - desc: Extension pointo to activate specification invariants
244
+ template: extend/extend_invariant_cfg.mustache
245
+ modelData: none
246
+
247
+ - desc: End of module
248
+ template: cfg/module_footer.mustache
249
+ modelData: none
250
+
251
+
252
+ # ----------------------------------------
253
+ # Default setup.tla
254
+ #
255
+ # Override template extension points
256
+
257
+
258
+ - output: tla/setup.tla
259
+ inputs:
260
+
261
+ - desc: Start of module
262
+ template: setup/module_header.mustache
263
+ modelData: none
264
+
265
+ - desc: Implemenation for environment execution operators
266
+ template: setup/operator_run.mustache
267
+ modelData: none
268
+
269
+ - desc: Implemenation for environment time tick operator
270
+ template: setup/operator_tick.mustache
271
+ modelData: none
272
+
273
+ - desc: Setup domain values
274
+ template: domains_run.mustache
275
+ modelData: domains
276
+
277
+ # - desc: interface calls in setup
278
+ # template: interface_steps.mustache
279
+ # modelData: interfaces
280
+
281
+ - desc: Setup environment execution steps
282
+ template: setup/steps_run.mustache
283
+ modelData: steps
284
+
285
+ - desc: End of of module
286
+ template: setup/module_footer.mustache
287
+ modelData: none
288
+
289
+
290
+ # ----------------------------------------
291
+ # Dump data-models for template generation
292
+
293
+ - output: doc/data-model.md
294
+ inputs:
295
+
296
+ - desc: Model header
297
+ template: data-model-header.mustache
298
+ modelData: none
299
+
300
+ - desc: Model interfaces
301
+ template: data-model-dump.mustache
302
+ modelData: interfaces
303
+
304
+ - desc: Model infrastructureServices
305
+ template: data-model-dump.mustache
306
+ modelData: infrastructureServices
307
+
308
+ - desc: Model definitions
309
+ template: data-model-dump.mustache
310
+ modelData: definitions
311
+
312
+ - desc: Model domains
313
+ template: data-model-dump.mustache
314
+ modelData: domains
315
+
316
+ - desc: Model state
317
+ template: data-model-dump.mustache
318
+ modelData: variables
319
+
320
+ - desc: Model steps
321
+ template: data-model-dump.mustache
322
+ modelData: steps
323
+
324
+ - desc: Model footer
325
+ template: data-model-footer.mustache
326
+ modelData: none
327
+
328
+
329
+ # ------------------------------------------------------------------
330
+
331
+ # Category possibility: iterate configs per possibility defines
332
+ # in setup. Generation processes each 'category' separately.
333
+
334
+
335
+ # output to file evaluated using array 'possibilities' in setup
336
+
337
+ - output: tla/possible_{{possibility}}.tla
338
+ category: possibility
339
+ inputs:
340
+
341
+ - desc: Start of module
342
+ template: possibility/module_header.mustache
343
+ modelData: possibility
344
+
345
+ - desc: Extension definition
346
+ template: possibility/module_extends.mustache
347
+ modelData: possibility
348
+
349
+ - desc: Define possibility invariant operator
350
+ template: possibility/possibility_definition.mustache
351
+ modelData: possibility
352
+
353
+
354
+ - desc: End of module
355
+ template: possibility/module_footer.mustache
356
+ modelData: possibility
357
+
358
+
359
+ - output: tla/possible_{{possibility}}.cfg
360
+ category: possibility
361
+ inputs:
362
+
363
+ - desc: Include setup.cfg
364
+ template: possibility/possility_setup.mustache
365
+ modelData: possibility
366
+ templateParameters:
367
+ include: tla/setup.cfg
368
+
369
+
370
+ - desc: Activate possibility directive
371
+ template: possibility/possibility_directive.mustache
372
+ modelData: possibility
@@ -0,0 +1,124 @@
1
+
2
+ module Sbuilder
3
+
4
+ class Domain
5
+
6
+ attr_reader :name
7
+
8
+ attr_reader :extension
9
+
10
+ # ------------------------------------------------------------------
11
+ # mixer
12
+ PROGNAME = "domain" # progname for logger
13
+ include Sbuilder::Utils::MyLogger # mix logger
14
+
15
+
16
+ def initialize( options = {} )
17
+ @logger = getLogger( PROGNAME, options )
18
+ @logger.info( "#{__method__} initialized" )
19
+ end
20
+
21
+ def to_s
22
+ "#{self.class}: name=#{name}"
23
+ end
24
+
25
+ # ------------------------------------------------------------------
26
+ # config
27
+
28
+ def setName( name )
29
+ @name = name
30
+ self
31
+ end
32
+
33
+ # def setCardinality( cardinality )
34
+ # @cardinality = cardinality
35
+ # raise "deprecated #{__method__} in #{self.class}"
36
+ # self
37
+ # end
38
+
39
+ # ------------------------------------------------------------------
40
+ # extendDomain
41
+
42
+ def setExtension( extension )
43
+ @extension = extension
44
+ end
45
+
46
+ # ------------------------------------------------------------------
47
+ # use extension
48
+
49
+ # delegate to extension - return 1 if does not exist
50
+ def cardinality
51
+ return 1 unless extension
52
+ extension.cardinality
53
+ end
54
+
55
+ # ------------------------------------------------------------------
56
+ # generate
57
+
58
+ # alias for
59
+ alias domain_name :name
60
+
61
+ # # used to generate default values - in extension loaded
62
+ # def domain_prefix
63
+ # domain_name + "_"
64
+ # end
65
+
66
+ # Return domain value for for element 'i'. Possibly delegate to sub-class.
67
+ #
68
+ #
69
+ # @param i [Integer|String] element index (interger) or String value non integer
70
+ #
71
+ # @return value of domain element 'i', false if i==0
72
+ def domain_entry( i )
73
+
74
+ # interpret 0 as Nil
75
+ return false if i.is_a?(Integer) && i == 0
76
+
77
+ # delegage - if possible
78
+ return extension.domain_entry( i ) if extension
79
+
80
+ raise DomainException.new <<-EOS unless i.is_a?(Integer)
81
+ Unknown type '#{i.class}' with value '#{i}' in 'domain_entry' #{name}.
82
+
83
+ Support only for Integer
84
+ EOS
85
+
86
+ raise DomainException.new <<-EOS if i > cardinality
87
+ Requested cardinality #{i} exceeds cardinality #{cardinality} of domain #{name}
88
+ EOS
89
+
90
+
91
+ "d_#{domain_name}_#{i}"
92
+ end
93
+
94
+
95
+ # return array of strings for entries in domain - overrid
96
+ def domain_entries
97
+ arr = *(1..cardinality).map { |i| domain_entry( i ) }
98
+ return arr
99
+ end
100
+
101
+
102
+ # return and array of {:value,:_comma} hashes
103
+ def domain_values
104
+ # delegate - if extended
105
+ return extension.domain_values if extension
106
+ arra = domain_entries.map.with_index do |domain_entry, i|
107
+ {
108
+ :namespace => Constants::TYPE_NAMESPACE_DOM,
109
+ :value => domain_entry,
110
+ :_comma => (i +1) == cardinality ? "" : ",",
111
+ :index => i+1,
112
+ }
113
+ end
114
+ @logger.debug( "#{__method__} #{name}: arra #{arra.to_yaml}" )
115
+ return arra
116
+ end
117
+
118
+ end
119
+
120
+
121
+ end
122
+
123
+
124
+