kwalify 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGES.txt +232 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +16 -19
  4. data/bin/kwalify +3 -3
  5. data/contrib/inline-require +6 -4
  6. data/contrib/kwalify +3719 -2427
  7. data/doc-api/classes/CommandOptionError.html +17 -17
  8. data/doc-api/classes/CommandOptionParser.html +63 -63
  9. data/doc-api/classes/Kwalify.html +29 -7
  10. data/doc-api/classes/Kwalify/AssertionError.html +9 -9
  11. data/doc-api/classes/Kwalify/BaseError.html +72 -71
  12. data/doc-api/classes/Kwalify/BaseParser.html +461 -0
  13. data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
  14. data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
  15. data/doc-api/classes/Kwalify/HashInterface.html +13 -135
  16. data/doc-api/classes/Kwalify/Json.html +105 -0
  17. data/doc-api/classes/Kwalify/Main.html +129 -126
  18. data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
  19. data/doc-api/classes/Kwalify/Parser.html +12 -12
  20. data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
  21. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
  22. data/doc-api/classes/Kwalify/Rule.html +152 -130
  23. data/doc-api/classes/Kwalify/SchemaError.html +10 -10
  24. data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
  25. data/doc-api/classes/Kwalify/Types.html +26 -25
  26. data/doc-api/classes/Kwalify/Util.html +389 -0
  27. data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
  28. data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
  29. data/doc-api/classes/Kwalify/ValidationError.html +10 -10
  30. data/doc-api/classes/Kwalify/Validator.html +153 -86
  31. data/doc-api/classes/Kwalify/Yaml.html +181 -0
  32. data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
  33. data/doc-api/classes/Kwalify/YamlParser.html +190 -183
  34. data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
  35. data/doc-api/created.rid +1 -1
  36. data/doc-api/files/__/README_txt.html +17 -22
  37. data/doc-api/files/kwalify/errors_rb.html +2 -2
  38. data/doc-api/files/kwalify/main_rb.html +4 -3
  39. data/doc-api/files/kwalify/messages_rb.html +2 -2
  40. data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
  41. data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
  42. data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
  43. data/doc-api/files/kwalify/rule_rb.html +2 -2
  44. data/doc-api/files/kwalify/types_rb.html +2 -2
  45. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
  46. data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
  47. data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
  48. data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
  49. data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
  50. data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
  51. data/doc-api/files/kwalify/util_rb.html +107 -0
  52. data/doc-api/files/kwalify/validator_rb.html +2 -2
  53. data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
  54. data/doc-api/files/kwalify_rb.html +3 -2
  55. data/doc-api/fr_class_index.html +8 -1
  56. data/doc-api/fr_file_index.html +5 -1
  57. data/doc-api/fr_method_index.html +128 -69
  58. data/doc/img/fig01.png +0 -0
  59. data/doc/users-guide.html +882 -717
  60. data/examples/address-book/address-book.schema.yaml +2 -2
  61. data/examples/data-binding/BABEL.data.yaml +63 -0
  62. data/examples/data-binding/BABEL.schema.yaml +31 -0
  63. data/examples/data-binding/Makefile +8 -0
  64. data/examples/data-binding/Rakefile +13 -0
  65. data/examples/data-binding/main.rb +27 -0
  66. data/examples/invoice/invoice.schema.yaml +3 -3
  67. data/examples/tapkit/tapkit.schema.yaml +2 -2
  68. data/lib/kwalify.rb +41 -4
  69. data/lib/kwalify/errors.rb +118 -96
  70. data/lib/kwalify/kwalify.schema.yaml +58 -0
  71. data/lib/kwalify/main.rb +384 -377
  72. data/lib/kwalify/messages.rb +41 -27
  73. data/lib/kwalify/meta-validator.rb +251 -331
  74. data/lib/kwalify/parser/base.rb +127 -0
  75. data/lib/kwalify/parser/yaml.rb +837 -0
  76. data/lib/kwalify/rule.rb +545 -487
  77. data/lib/kwalify/templates/genclass-java.eruby +189 -162
  78. data/lib/kwalify/templates/genclass-php.eruby +104 -0
  79. data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
  80. data/lib/kwalify/types.rb +107 -106
  81. data/lib/kwalify/util.rb +157 -0
  82. data/lib/kwalify/util/assert-text-equal.rb +33 -31
  83. data/lib/kwalify/util/hash-interface.rb +11 -30
  84. data/lib/kwalify/util/hashlike.rb +51 -0
  85. data/lib/kwalify/util/option-parser.rb +144 -144
  86. data/lib/kwalify/util/ordered-hash.rb +57 -0
  87. data/lib/kwalify/util/testcase-helper.rb +3 -3
  88. data/lib/kwalify/validator.rb +267 -212
  89. data/lib/kwalify/yaml-parser.rb +822 -768
  90. data/setup.rb +861 -607
  91. data/test/Rookbook.yaml +10 -0
  92. data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
  93. data/test/data/users-guide/BABEL.data.yaml +24 -0
  94. data/test/data/users-guide/BABEL.schema.yaml +30 -0
  95. data/test/data/users-guide/ExampleAddressBook.java +47 -0
  96. data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
  97. data/test/data/users-guide/Person.java.expected +44 -0
  98. data/test/data/users-guide/address_book.rb +52 -0
  99. data/test/data/users-guide/address_book.schema.yaml +28 -0
  100. data/test/data/users-guide/address_book.yaml +27 -0
  101. data/test/data/users-guide/answers-schema.yaml +12 -0
  102. data/test/data/users-guide/answers-validator.rb +52 -0
  103. data/test/data/users-guide/babel_genclass.result +26 -0
  104. data/test/data/users-guide/config.schema.yaml +7 -0
  105. data/test/data/users-guide/config.yaml +4 -0
  106. data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
  107. data/test/data/users-guide/document01b.yaml +3 -0
  108. data/test/data/users-guide/document02a.yaml +4 -0
  109. data/test/data/users-guide/document02b.yaml +4 -0
  110. data/test/data/users-guide/document03a.yaml +6 -0
  111. data/test/data/users-guide/document03b.yaml +6 -0
  112. data/test/data/users-guide/document04a.yaml +9 -0
  113. data/test/data/users-guide/document04b.yaml +9 -0
  114. data/test/data/users-guide/document05a.yaml +11 -0
  115. data/test/data/users-guide/document05b.yaml +12 -0
  116. data/test/data/users-guide/document06a.yaml +15 -0
  117. data/test/data/users-guide/document06b.yaml +16 -0
  118. data/test/data/users-guide/document07a.yaml +9 -0
  119. data/test/data/users-guide/document07b.yaml +7 -0
  120. data/test/data/users-guide/document12a.json +10 -0
  121. data/test/data/users-guide/document12b.json +6 -0
  122. data/test/data/users-guide/document13a.yaml +17 -0
  123. data/test/data/users-guide/document14a.yaml +3 -0
  124. data/test/data/users-guide/document14b.yaml +3 -0
  125. data/test/data/users-guide/document15a.yaml +6 -0
  126. data/test/data/users-guide/document15b.yaml +5 -0
  127. data/test/data/users-guide/example_address_book.rb +10 -0
  128. data/test/data/users-guide/example_address_book_java.result +32 -0
  129. data/test/data/users-guide/example_address_book_ruby.result +31 -0
  130. data/test/data/users-guide/genclass_java.result +4 -0
  131. data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
  132. data/test/data/users-guide/howto-validation.rb +25 -0
  133. data/test/data/users-guide/howto3.rb +6 -0
  134. data/test/data/users-guide/howto3.result +5 -0
  135. data/test/data/users-guide/howto3.yaml +8 -0
  136. data/test/data/users-guide/howto5_databinding.result +111 -0
  137. data/test/data/users-guide/invalid01.result +3 -0
  138. data/test/data/users-guide/invalid02.result +5 -0
  139. data/test/data/users-guide/invalid03.result +5 -0
  140. data/test/data/users-guide/invalid04.result +4 -0
  141. data/test/data/users-guide/invalid05.result +11 -0
  142. data/test/data/users-guide/invalid06.result +4 -0
  143. data/test/data/users-guide/invalid07.result +3 -0
  144. data/test/data/users-guide/invalid08.result +3 -0
  145. data/test/data/users-guide/invalid12.json +8 -0
  146. data/test/data/users-guide/invalid14.result +4 -0
  147. data/test/data/users-guide/invalid15.result +4 -0
  148. data/test/data/users-guide/loadbabel.rb +27 -0
  149. data/test/data/users-guide/loadconfig.rb +15 -0
  150. data/test/data/users-guide/loadconfig.result +2 -0
  151. data/test/data/users-guide/models.rb +22 -0
  152. data/test/data/users-guide/option_ha.result +6 -0
  153. data/test/data/users-guide/option_ha_genclass_java.result +7 -0
  154. data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
  155. data/test/data/users-guide/schema02.yaml +12 -0
  156. data/test/data/users-guide/schema03.yaml +9 -0
  157. data/test/data/users-guide/schema04.yaml +20 -0
  158. data/test/data/users-guide/schema05.yaml +29 -0
  159. data/test/data/users-guide/schema06.yaml +11 -0
  160. data/test/data/users-guide/schema12.json +12 -0
  161. data/test/data/users-guide/schema13.yaml +13 -0
  162. data/test/data/users-guide/schema14.yaml +5 -0
  163. data/test/data/users-guide/schema15.yaml +21 -0
  164. data/test/data/users-guide/valid01.result +2 -0
  165. data/test/data/users-guide/valid02.result +2 -0
  166. data/test/data/users-guide/valid03.result +2 -0
  167. data/test/data/users-guide/valid04.result +2 -0
  168. data/test/data/users-guide/valid05.result +2 -0
  169. data/test/data/users-guide/valid06.result +2 -0
  170. data/test/data/users-guide/valid07.result +2 -0
  171. data/test/data/users-guide/valid08.result +2 -0
  172. data/test/data/users-guide/valid12.result +2 -0
  173. data/test/data/users-guide/valid13.result +2 -0
  174. data/test/data/users-guide/valid14.result +2 -0
  175. data/test/data/users-guide/valid15.result +2 -0
  176. data/test/data/users-guide/validate08.rb +37 -0
  177. data/test/test-action.rb +78 -0
  178. data/test/test-action.yaml +738 -0
  179. data/test/test-databinding.rb +80 -0
  180. data/test/test-databinding.yaml +301 -0
  181. data/test/test-main.rb +129 -150
  182. data/test/test-main.yaml +126 -321
  183. data/test/test-metavalidator.rb +47 -47
  184. data/test/test-metavalidator.yaml +77 -21
  185. data/test/test-parser-yaml.rb +57 -0
  186. data/test/test-parser-yaml.yaml +1749 -0
  187. data/test/test-rule.rb +14 -15
  188. data/test/test-rule.yaml +6 -3
  189. data/test/test-users-guide.rb +75 -0
  190. data/test/test-validator.rb +77 -52
  191. data/test/test-validator.yaml +168 -6
  192. data/test/test-yaml-parser.rb +47 -0
  193. data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
  194. data/test/test.rb +37 -21
  195. metadata +136 -37
  196. data/COPYING +0 -340
  197. data/ChangeLog +0 -70
  198. data/doc-api/classes/YamlHelper.html +0 -259
  199. data/lib/kwalify/util/yaml-helper.rb +0 -82
  200. data/test/test-yamlparser.rb +0 -58
  201. data/test/tmp.dir/User.java +0 -43
  202. data/test/tmp.dir/action1.document +0 -18
  203. data/test/tmp.dir/action1.schema +0 -32
  204. data/test/tmp.dir/action2.document +0 -18
  205. data/test/tmp.dir/action2.schema +0 -32
  206. data/test/tmp.dir/emacs.document +0 -6
  207. data/test/tmp.dir/emacs.schema +0 -6
  208. data/test/tmp.dir/meta1.document +0 -0
  209. data/test/tmp.dir/meta2.document +0 -0
  210. data/test/tmp.dir/meta2.schema +0 -3
  211. data/test/tmp.dir/silent1.schema +0 -3
  212. data/test/tmp.dir/silent2.document +0 -7
  213. data/test/tmp.dir/silent2.schema +0 -3
  214. data/test/tmp.dir/stream.invalid +0 -8
  215. data/test/tmp.dir/stream.schema +0 -3
  216. data/test/tmp.dir/stream.valid +0 -8
  217. data/test/tmp.dir/untabify.document +0 -5
  218. data/test/tmp.dir/untabify.schema +0 -10
  219. data/todo.txt +0 -34
@@ -0,0 +1,738 @@
1
+ ##
2
+ ## $Rev: 95 $
3
+ ## $Release: 0.7.0 $
4
+ ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
+ ##
6
+ ---
7
+ - name: action_genclass_ruby1
8
+ desc: action 'genclass-ruby'
9
+ action: genclass-ruby
10
+ method: action
11
+ args: [ -a, genclass-ruby, -tf, action_genclass_ruby1.schema ]
12
+ schema: &action_schema1 |
13
+ type: map
14
+ class: Context
15
+ mapping:
16
+ "groups":
17
+ type: seq
18
+ sequence:
19
+ - type: map
20
+ class: Group
21
+ mapping:
22
+ "name":
23
+ type: str
24
+ required: yes
25
+ "desc":
26
+ type: str
27
+ "owner": &userschema
28
+ type: map
29
+ class: User
30
+ mapping:
31
+ "name":
32
+ type: str
33
+ required: yes
34
+ "desc":
35
+ type: str
36
+ "gender":
37
+ type: bool
38
+ "mail":
39
+ type: str
40
+ "manager": *userschema
41
+ "deleted":
42
+ type: bool
43
+ default: false
44
+ "users":
45
+ type: seq
46
+ sequence:
47
+ - *userschema
48
+ document: &action_document1 |
49
+ groups:
50
+ - name: admin
51
+ desc: administrator group
52
+ owner: &root
53
+ name: root
54
+ desc: root user
55
+ - name: users
56
+ desc: user group
57
+ owner: &guest
58
+ name: guest
59
+ desc: guest user
60
+ users:
61
+ - *root
62
+ - *guest
63
+ - &user1
64
+ name: user1
65
+ - name: user2
66
+ manager: *user1
67
+ expected: |
68
+ ##
69
+ class Context
70
+ def initialize(hash=nil)
71
+ if hash.nil?
72
+ return
73
+ end
74
+ @groups = (v=hash['groups']) ? v.map!{|e| e.is_a?(Group) ? e : Group.new(e)} : v
75
+ @users = (v=hash['users']) ? v.map!{|e| e.is_a?(User) ? e : User.new(e)} : v
76
+ end
77
+ attr_accessor :groups # seq
78
+ attr_accessor :users # seq
79
+ end
80
+
81
+ ##
82
+ class Group
83
+ def initialize(hash=nil)
84
+ if hash.nil?
85
+ return
86
+ end
87
+ @name = hash['name']
88
+ @desc = hash['desc']
89
+ @owner = (v=hash['owner']) && v.is_a?(Hash) ? User.new(v) : v
90
+ end
91
+ attr_accessor :name # str
92
+ attr_accessor :desc # str
93
+ attr_accessor :owner # map
94
+ end
95
+
96
+ ##
97
+ class User
98
+ def initialize(hash=nil)
99
+ if hash.nil?
100
+ @deleted = false
101
+ return
102
+ end
103
+ @name = hash['name']
104
+ @desc = hash['desc']
105
+ @gender = hash['gender']
106
+ @mail = hash['mail']
107
+ @manager = (v=hash['manager']) && v.is_a?(Hash) ? User.new(v) : v
108
+ @deleted = (v=hash['deleted']).nil? ? false : v
109
+ end
110
+ attr_accessor :name # str
111
+ attr_accessor :desc # str
112
+ attr_accessor :gender # bool
113
+ attr_accessor :mail # str
114
+ attr_accessor :manager # map
115
+ attr_accessor :deleted # bool
116
+ def gender? ; @gender ; end
117
+ def deleted? ; @deleted ; end
118
+ end
119
+
120
+ ##
121
+ - name: action_genclass_php1
122
+ desc: action 'genclass-php'
123
+ action: genclass-php
124
+ method: action
125
+ args: [ -a, genclass-php, -tf, action_genclass_php1.schema ]
126
+ schema: *action_schema1
127
+ document: *action_document1
128
+ expected: |
129
+ <?php
130
+
131
+ ///
132
+ class Context {
133
+ var $groups; // seq
134
+ var $users; // seq
135
+ function __construct($arr=NULL) {
136
+ if (! $arr) return;
137
+ if (is_array(@$arr['groups']))
138
+ foreach ($arr['groups'] as $k=>$v)
139
+ $this->groups[$k] = is_array($v) ? new Group($v) : $v;
140
+ //else
141
+ // $this->groups = @$arr['groups'];
142
+ if (is_array(@$arr['users']))
143
+ foreach ($arr['users'] as $k=>$v)
144
+ $this->users[$k] = is_array($v) ? new User($v) : $v;
145
+ //else
146
+ // $this->users = @$arr['users'];
147
+ }
148
+ }
149
+
150
+ ///
151
+ class Group {
152
+ var $name; // str
153
+ var $desc; // str
154
+ var $owner; // map
155
+ function __construct($arr=NULL) {
156
+ if (! $arr) return;
157
+ $this->name = @$arr['name'];
158
+ $this->desc = @$arr['desc'];
159
+ $this->owner = is_array(@$arr['owner']) ? new User($arr['owner']) : @$arr['owner'];
160
+ }
161
+ }
162
+
163
+ ///
164
+ class User {
165
+ var $name; // str
166
+ var $desc; // str
167
+ var $gender; // bool
168
+ var $mail; // str
169
+ var $manager; // map
170
+ var $deleted = false; // bool
171
+ function __construct($arr=NULL) {
172
+ if (! $arr) return;
173
+ $this->name = @$arr['name'];
174
+ $this->desc = @$arr['desc'];
175
+ $this->gender = @$arr['gender'];
176
+ $this->mail = @$arr['mail'];
177
+ $this->manager = is_array(@$arr['manager']) ? new User($arr['manager']) : @$arr['manager'];
178
+ if (array_key_exists('deleted', $arr)) $this->deleted = $arr['deleted'];
179
+ }
180
+ }
181
+
182
+ ?>
183
+
184
+ ##
185
+ - name: action_genclass_java1
186
+ desc: action 'genclass-java'
187
+ action: genclass-java
188
+ method: action
189
+ args: [ -a, genclass-java, -tf, action_genclass_java1.schema ]
190
+ schema: *action_schema1
191
+ document: *action_document1
192
+ output_files: [ Context.java, Group.java, User.java ]
193
+ output_message: |+
194
+ generating ./Context.java...done.
195
+ generating ./Group.java...done.
196
+ generating ./User.java...done.
197
+ expected:
198
+ 'Context.java': |
199
+ // generated by kwalify from action_genclass_java1.schema
200
+
201
+ import java.util.*;
202
+
203
+ /**
204
+ *
205
+ */
206
+ public class Context {
207
+
208
+ private List _groups;
209
+ private List _users;
210
+
211
+ public Context() {}
212
+
213
+ public Context(Map map) {
214
+ List seq;
215
+ Object obj;
216
+ if ((seq = (List)map.get("groups")) != null) {
217
+ for (int i = 0; i < seq.size(); i++) {
218
+ if ((obj = seq.get(i)) instanceof Map) {
219
+ seq.set(i, new Group((Map)obj));
220
+ }
221
+ }
222
+ }
223
+ _groups = seq;
224
+ if ((seq = (List)map.get("users")) != null) {
225
+ for (int i = 0; i < seq.size(); i++) {
226
+ if ((obj = seq.get(i)) instanceof Map) {
227
+ seq.set(i, new User((Map)obj));
228
+ }
229
+ }
230
+ }
231
+ _users = seq;
232
+ }
233
+
234
+ public List getGroups() { return _groups; }
235
+ public void setGroups(List groups_) { _groups = groups_; }
236
+ public List getUsers() { return _users; }
237
+ public void setUsers(List users_) { _users = users_; }
238
+ }
239
+
240
+ 'Group.java': |
241
+ // generated by kwalify from action_genclass_java1.schema
242
+
243
+ import java.util.*;
244
+
245
+ /**
246
+ *
247
+ */
248
+ public class Group {
249
+
250
+ private String _name;
251
+ private String _desc;
252
+ private User _owner;
253
+
254
+ public Group() {}
255
+
256
+ public Group(Map map) {
257
+ _name = (String)map.get("name");
258
+ _desc = (String)map.get("desc");
259
+ Object obj;
260
+ if ((obj = map.get("owner")) != null && obj instanceof Map) {
261
+ _owner = new User((Map)obj);
262
+ } else {
263
+ _owner = (User)obj;
264
+ }
265
+ }
266
+
267
+ public String getName() { return _name; }
268
+ public void setName(String name_) { _name = name_; }
269
+ public String getDesc() { return _desc; }
270
+ public void setDesc(String desc_) { _desc = desc_; }
271
+ public User getOwner() { return _owner; }
272
+ public void setOwner(User owner_) { _owner = owner_; }
273
+ }
274
+
275
+ 'User.java': |
276
+ // generated by kwalify from action_genclass_java1.schema
277
+
278
+ import java.util.*;
279
+
280
+ /**
281
+ *
282
+ */
283
+ public class User {
284
+
285
+ private String _name;
286
+ private String _desc;
287
+ private boolean _gender;
288
+ private String _mail;
289
+ private User _manager;
290
+ private boolean _deleted = false;
291
+
292
+ public User() {}
293
+
294
+ public User(Map map) {
295
+ _name = (String)map.get("name");
296
+ _desc = (String)map.get("desc");
297
+ if (map.get("gender") != null) {
298
+ _gender = ((Boolean)map.get("gender")).booleanValue();
299
+ }
300
+ _mail = (String)map.get("mail");
301
+ Object obj;
302
+ if ((obj = map.get("manager")) != null && obj instanceof Map) {
303
+ _manager = new User((Map)obj);
304
+ } else {
305
+ _manager = (User)obj;
306
+ }
307
+ if (map.get("deleted") != null) {
308
+ _deleted = ((Boolean)map.get("deleted")).booleanValue();
309
+ }
310
+ }
311
+
312
+ public String getName() { return _name; }
313
+ public void setName(String name_) { _name = name_; }
314
+ public String getDesc() { return _desc; }
315
+ public void setDesc(String desc_) { _desc = desc_; }
316
+ public boolean isGender() { return _gender; }
317
+ public void setGender(boolean gender_) { _gender = gender_; }
318
+ public String getMail() { return _mail; }
319
+ public void setMail(String mail_) { _mail = mail_; }
320
+ public User getManager() { return _manager; }
321
+ public void setManager(User manager_) { _manager = manager_; }
322
+ public boolean isDeleted() { return _deleted; }
323
+ public void setDeleted(boolean deleted_) { _deleted = deleted_; }
324
+ }
325
+
326
+ ## not used
327
+ main_file:
328
+ name: Example.java
329
+ content: |
330
+ import kwalify.*;
331
+ import java.util.*;
332
+
333
+ public class Example {
334
+ public static void main(String[] args) throws Exception {
335
+ String input = kwalify.Util.readFile("action_genclass_java1.document");
336
+ input = kwalify.Util.untabify(input);
337
+ YamlParser parser = new YamlParser(input);
338
+ Object ydoc = parser.parse();
339
+ //
340
+ Context context = new Context((Map)ydoc);
341
+ //
342
+ List groups = context.getGroups();
343
+ if (groups != null) {
344
+ for (Iterator it = groups.iterator(); it.hasNext(); ) {
345
+ Group g = (Group)it.next();
346
+ System.out.println("group.name = " + g.getName());
347
+ System.out.println("group.desc = " + g.getDesc());
348
+ System.out.println("group.owner.name = " + g.getOwner().getName());
349
+ System.out.println();
350
+ }
351
+ }
352
+ //
353
+ List users = context.getUsers();
354
+ if (users != null) {
355
+ for (Iterator it = users.iterator(); it.hasNext(); ) {
356
+ User u = (User)it.next();
357
+ System.out.println("user.name = " + u.getName());
358
+ System.out.println("user.desc = " + u.getDesc());
359
+ System.out.println("user.manager.name = " + (u.getManager() != null ? u.getManager().getName() : null));
360
+ System.out.println();
361
+ }
362
+ }
363
+ }
364
+ }
365
+
366
+ ##
367
+ - name: action_genclass_ruby2
368
+ desc: action 'genclass-ruby'
369
+ action: genclass-ruby
370
+ method: action
371
+ args: [ -a, genclass-ruby, -tf, action_genclass_ruby2.schema, --module=My::DTO, --parent=BaseObject, "--include=Enumerable,Comparable", --hashlike ]
372
+ schema: &action_schema2 |
373
+ type: map
374
+ mapping:
375
+ "tables":
376
+ type: seq
377
+ sequence:
378
+ - type: map
379
+ class: Table
380
+ mapping:
381
+ "name": {type: str}
382
+ "desc": {type: text}
383
+ "columns":
384
+ type: seq
385
+ sequence:
386
+ - type: map
387
+ class: Column
388
+ mapping: &column
389
+ "name": {type: str}
390
+ "type": {type: str}
391
+ "desc": {type: str}
392
+ "not-null": {type: bool}
393
+ "primary-key": {type: bool}
394
+ "default": {type: any}
395
+ "ref": {type: str}
396
+ "columns":
397
+ type: seq
398
+ sequence:
399
+ - type: map
400
+ class: Column
401
+ mapping:
402
+ <<: *column
403
+ "namepattern": {type: str}
404
+ "columnsets":
405
+ type: seq
406
+ sequence:
407
+ - type: map
408
+ class: Columnset
409
+ mapping:
410
+ "name": {type: str}
411
+ "columns":
412
+ type: seq
413
+ sequence:
414
+ - type: map
415
+ class: Column
416
+ mapping: *column
417
+ document: &action_document3 |
418
+ columns:
419
+ - name: id
420
+ type: int
421
+ primary-key: yes
422
+ not-null: yes
423
+ - name: updated_at
424
+ type: timestamp
425
+ not-null: yes
426
+ default: current_timestamp
427
+ - name: created_at
428
+ type: timestamp
429
+ not-null: yes
430
+ default: current_timestamp
431
+ columnsets:
432
+ - name: common
433
+ columns:
434
+ - name: created_at
435
+ - name: updated_at
436
+ tables:
437
+ - name: customers
438
+ desc: Customer master table
439
+ columns:
440
+ - name: id
441
+ - name: name
442
+ type: str
443
+ not-null: yes
444
+ - name: common
445
+ - name: sales_orders
446
+ desc: Sales orders master table
447
+ columns:
448
+ - name: id
449
+ - name: customer_id
450
+ ref: customers.id
451
+ not-null: yes
452
+ - name: ordered_date
453
+ type: date
454
+ not-null: yes
455
+ - name: delivery_date
456
+ type: date
457
+ expected: |
458
+ require 'kwalify/util/hashlike'
459
+
460
+ module My::DTO
461
+
462
+ ##
463
+ class Table < BaseObject
464
+ include Kwalify::Util::HashLike
465
+ include Enumerable,Comparable
466
+ def initialize(hash=nil)
467
+ if hash.nil?
468
+ return
469
+ end
470
+ @name = hash['name']
471
+ @desc = hash['desc']
472
+ @columns = (v=hash['columns']) ? v.map!{|e| e.is_a?(Column) ? e : Column.new(e)} : v
473
+ end
474
+ attr_accessor :name # str
475
+ attr_accessor :desc # text
476
+ attr_accessor :columns # seq
477
+ end
478
+
479
+ ##
480
+ class Column < BaseObject
481
+ include Kwalify::Util::HashLike
482
+ include Enumerable,Comparable
483
+ def initialize(hash=nil)
484
+ if hash.nil?
485
+ return
486
+ end
487
+ @name = hash['name']
488
+ @type = hash['type']
489
+ @desc = hash['desc']
490
+ @not_null = hash['not-null']
491
+ @primary_key = hash['primary-key']
492
+ @default = hash['default']
493
+ @ref = hash['ref']
494
+ @namepattern = hash['namepattern']
495
+ end
496
+ attr_accessor :name # str
497
+ attr_accessor :type # str
498
+ attr_accessor :desc # str
499
+ attr_accessor :not_null # bool
500
+ attr_accessor :primary_key # bool
501
+ attr_accessor :default # any
502
+ attr_accessor :ref # str
503
+ attr_accessor :namepattern # str
504
+ def not_null? ; @not_null ; end
505
+ def primary_key? ; @primary_key ; end
506
+ end
507
+
508
+ ##
509
+ class Columnset < BaseObject
510
+ include Kwalify::Util::HashLike
511
+ include Enumerable,Comparable
512
+ def initialize(hash=nil)
513
+ if hash.nil?
514
+ return
515
+ end
516
+ @name = hash['name']
517
+ @columns = (v=hash['columns']) ? v.map!{|e| e.is_a?(Column) ? e : Column.new(e)} : v
518
+ end
519
+ attr_accessor :name # str
520
+ attr_accessor :columns # seq
521
+ end
522
+
523
+ end
524
+
525
+ ##
526
+ - name: action_genclass_php2
527
+ desc: action 'genclass-php'
528
+ action: genclass-php
529
+ method: action
530
+ args: [ -a, genclass-php, -tf, action_genclass_php2.schema, --namespace=My, --extends=BaseObject, --implements=Serializable ]
531
+ schema: *action_schema2
532
+ document: *action_document2
533
+ expected: |
534
+ <?php
535
+
536
+ ///
537
+ class My_Table extends BaseObject implements Serializable {
538
+ var $name; // str
539
+ var $desc; // text
540
+ var $columns; // seq
541
+ function __construct($arr=NULL) {
542
+ if (! $arr) return;
543
+ $this->name = @$arr['name'];
544
+ $this->desc = @$arr['desc'];
545
+ if (is_array(@$arr['columns']))
546
+ foreach ($arr['columns'] as $k=>$v)
547
+ $this->columns[$k] = is_array($v) ? new Column($v) : $v;
548
+ //else
549
+ // $this->columns = @$arr['columns'];
550
+ }
551
+ }
552
+
553
+ ///
554
+ class My_Column extends BaseObject implements Serializable {
555
+ var $name; // str
556
+ var $type; // str
557
+ var $desc; // str
558
+ var $not_null; // bool
559
+ var $primary_key; // bool
560
+ var $default; // any
561
+ var $ref; // str
562
+ var $namepattern; // str
563
+ function __construct($arr=NULL) {
564
+ if (! $arr) return;
565
+ $this->name = @$arr['name'];
566
+ $this->type = @$arr['type'];
567
+ $this->desc = @$arr['desc'];
568
+ $this->not_null = @$arr['not-null'];
569
+ $this->primary_key = @$arr['primary-key'];
570
+ $this->default = @$arr['default'];
571
+ $this->ref = @$arr['ref'];
572
+ $this->namepattern = @$arr['namepattern'];
573
+ }
574
+ }
575
+
576
+ ///
577
+ class My_Columnset extends BaseObject implements Serializable {
578
+ var $name; // str
579
+ var $columns; // seq
580
+ function __construct($arr=NULL) {
581
+ if (! $arr) return;
582
+ $this->name = @$arr['name'];
583
+ if (is_array(@$arr['columns']))
584
+ foreach ($arr['columns'] as $k=>$v)
585
+ $this->columns[$k] = is_array($v) ? new Column($v) : $v;
586
+ //else
587
+ // $this->columns = @$arr['columns'];
588
+ }
589
+ }
590
+
591
+ ?>
592
+
593
+
594
+ ##
595
+ - name: action_genclass_java2
596
+ desc: action 'genclass-java'
597
+ action: genclass-java
598
+ method: action
599
+ args: [ -a, genclass-java, -tf, action_genclass_java2.schema, --extends=java.lang.Object, --implements=java.io.Serializable, --package=my.dto, --dir=. ]
600
+ schema: *action_schema2
601
+ document: *action_document2
602
+ output_files: [ Table.java, Column.java, Columnset.java ]
603
+ output_message: |+
604
+ generating ./Table.java...done.
605
+ generating ./Column.java...done.
606
+ generating ./Columnset.java...done.
607
+ expected:
608
+ "Table.java": |
609
+ // generated by kwalify from action_genclass_java2.schema
610
+
611
+ package my.dto;
612
+ import java.util.*;
613
+
614
+ /**
615
+ *
616
+ */
617
+ public class Table extends java.lang.Object implements java.io.Serializable {
618
+
619
+ private String _name;
620
+ private String _desc;
621
+ private List _columns;
622
+
623
+ public Table() {}
624
+
625
+ public Table(Map map) {
626
+ _name = (String)map.get("name");
627
+ _desc = (String)map.get("desc");
628
+ List seq;
629
+ Object obj;
630
+ if ((seq = (List)map.get("columns")) != null) {
631
+ for (int i = 0; i < seq.size(); i++) {
632
+ if ((obj = seq.get(i)) instanceof Map) {
633
+ seq.set(i, new Column((Map)obj));
634
+ }
635
+ }
636
+ }
637
+ _columns = seq;
638
+ }
639
+
640
+ public String getName() { return _name; }
641
+ public void setName(String name_) { _name = name_; }
642
+ public String getDesc() { return _desc; }
643
+ public void setDesc(String desc_) { _desc = desc_; }
644
+ public List getColumns() { return _columns; }
645
+ public void setColumns(List columns_) { _columns = columns_; }
646
+ }
647
+
648
+ "Column.java": |
649
+ // generated by kwalify from action_genclass_java2.schema
650
+
651
+ package my.dto;
652
+ import java.util.*;
653
+
654
+ /**
655
+ *
656
+ */
657
+ public class Column extends java.lang.Object implements java.io.Serializable {
658
+
659
+ private String _name;
660
+ private String _type;
661
+ private String _desc;
662
+ private boolean _not_null;
663
+ private boolean _primary_key;
664
+ private Object _default;
665
+ private String _ref;
666
+ private String _namepattern;
667
+
668
+ public Column() {}
669
+
670
+ public Column(Map map) {
671
+ _name = (String)map.get("name");
672
+ _type = (String)map.get("type");
673
+ _desc = (String)map.get("desc");
674
+ if (map.get("not-null") != null) {
675
+ _not_null = ((Boolean)map.get("not-null")).booleanValue();
676
+ }
677
+ if (map.get("primary-key") != null) {
678
+ _primary_key = ((Boolean)map.get("primary-key")).booleanValue();
679
+ }
680
+ _default = (Object)map.get("default");
681
+ _ref = (String)map.get("ref");
682
+ _namepattern = (String)map.get("namepattern");
683
+ }
684
+
685
+ public String getName() { return _name; }
686
+ public void setName(String name_) { _name = name_; }
687
+ public String getType() { return _type; }
688
+ public void setType(String type_) { _type = type_; }
689
+ public String getDesc() { return _desc; }
690
+ public void setDesc(String desc_) { _desc = desc_; }
691
+ public boolean isNotNull() { return _not_null; }
692
+ public void setNotNull(boolean not_null_) { _not_null = not_null_; }
693
+ public boolean isPrimaryKey() { return _primary_key; }
694
+ public void setPrimaryKey(boolean primary_key_) { _primary_key = primary_key_; }
695
+ public Object getDefault() { return _default; }
696
+ public void setDefault(Object default_) { _default = default_; }
697
+ public String getRef() { return _ref; }
698
+ public void setRef(String ref_) { _ref = ref_; }
699
+ public String getNamepattern() { return _namepattern; }
700
+ public void setNamepattern(String namepattern_) { _namepattern = namepattern_; }
701
+ }
702
+
703
+ "Columnset.java": |
704
+ // generated by kwalify from action_genclass_java2.schema
705
+
706
+ package my.dto;
707
+ import java.util.*;
708
+
709
+ /**
710
+ *
711
+ */
712
+ public class Columnset extends java.lang.Object implements java.io.Serializable {
713
+
714
+ private String _name;
715
+ private List _columns;
716
+
717
+ public Columnset() {}
718
+
719
+ public Columnset(Map map) {
720
+ _name = (String)map.get("name");
721
+ List seq;
722
+ Object obj;
723
+ if ((seq = (List)map.get("columns")) != null) {
724
+ for (int i = 0; i < seq.size(); i++) {
725
+ if ((obj = seq.get(i)) instanceof Map) {
726
+ seq.set(i, new Column((Map)obj));
727
+ }
728
+ }
729
+ }
730
+ _columns = seq;
731
+ }
732
+
733
+ public String getName() { return _name; }
734
+ public void setName(String name_) { _name = name_; }
735
+ public List getColumns() { return _columns; }
736
+ public void setColumns(List columns_) { _columns = columns_; }
737
+ }
738
+ ##