rubyang 0.1.2.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -3
- data/lib/rubyang.rb +5 -6
- data/lib/rubyang/cli.rb +114 -114
- data/lib/rubyang/cli/parser.rb +56 -56
- data/lib/rubyang/compat.rb +14 -0
- data/lib/rubyang/component/base.rb +21 -21
- data/lib/rubyang/component/example.rb +8 -7
- data/lib/rubyang/database.rb +45 -34
- data/lib/rubyang/database/component_manager.rb +64 -64
- data/lib/rubyang/database/data_tree.rb +1110 -1077
- data/lib/rubyang/database/helper.rb +31 -30
- data/lib/rubyang/database/logger.rb +58 -0
- data/lib/rubyang/database/schema_tree.rb +1198 -1298
- data/lib/rubyang/model.rb +1139 -923
- data/lib/rubyang/model/logger.rb +58 -0
- data/lib/rubyang/model/parser.rb +197 -195
- data/lib/rubyang/model/parser/parser.tab.rb +1373 -1263
- data/lib/rubyang/model/parser/parser.y +393 -215
- data/lib/rubyang/restapi.rb +4 -3
- data/lib/rubyang/restapi/app.rb +52 -53
- data/lib/rubyang/server.rb +4 -3
- data/lib/rubyang/server/base.rb +20 -20
- data/lib/rubyang/server/example.rb +2 -1
- data/lib/rubyang/version.rb +4 -1
- data/lib/rubyang/webui.rb +4 -3
- data/lib/rubyang/webui/app.rb +62 -63
- data/lib/rubyang/webui/make_json_schema.rb +49 -48
- data/lib/rubyang/xpath.rb +458 -456
- data/lib/rubyang/xpath/logger.rb +58 -0
- data/lib/rubyang/xpath/parser.rb +134 -144
- data/lib/rubyang/xpath/parser/parser.tab.rb +373 -616
- data/lib/rubyang/xpath/parser/parser.y +249 -492
- data/rubyang.gemspec +11 -15
- metadata +49 -32
- data/lib/rubyang/logger.rb +0 -19
@@ -1,44 +1,45 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'json'
|
4
5
|
require 'rexml/document'
|
5
6
|
|
6
7
|
def json_to_xml( json_str )
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
hash = JSON.parse( json_str )
|
9
|
+
if hash.keys.size > 1
|
10
|
+
raise 'root key size must be 1'
|
11
|
+
end
|
12
|
+
#doc_xml = REXML::Document.new( "<#{hash.keys.first} />" )
|
13
|
+
doc_xml = REXML::Document.new
|
14
|
+
json_to_xml_recursive( hash.keys.first, hash.values.first, doc_xml )
|
15
|
+
return doc_xml.to_s
|
15
16
|
end
|
16
17
|
|
17
18
|
def json_to_xml_recursive( _key, _value, _doc_xml )
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
doc_xml = _doc_xml.add_element( _key )
|
20
|
+
case _value
|
21
|
+
when Hash
|
22
|
+
_value.each{ |key, value|
|
23
|
+
case value
|
24
|
+
when Hash
|
25
|
+
json_to_xml_recursive( key, value, doc_xml )
|
26
|
+
when Array
|
27
|
+
value.each{ |hash|
|
28
|
+
json_to_xml_recursive( key, hash, doc_xml )
|
29
|
+
}
|
30
|
+
else
|
31
|
+
doc_xml.add_element( key ).add_text value
|
32
|
+
end
|
33
|
+
}
|
34
|
+
else
|
35
|
+
raise "case value when other than Hash is not implemented"
|
36
|
+
end
|
36
37
|
end
|
37
38
|
|
38
39
|
|
39
40
|
if __FILE__ == $0
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
json_str = '{"config": {"a": [{"b1": {"c1": "c1"}}, {"b2": {"c2": "c2"}}]}}'
|
42
|
+
puts json_to_xml( json_str )
|
43
|
+
json_str = '{"config":{"leaf1":"0"}}'
|
44
|
+
puts json_to_xml( json_str )
|
44
45
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
3
|
+
|
4
|
+
module Rubyang
|
5
|
+
class Database
|
6
|
+
class Logger
|
7
|
+
@@logger = nil
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def initialize logger
|
11
|
+
@@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def uninitialize
|
15
|
+
@@logger = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialized?
|
19
|
+
@@logger != nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize name
|
24
|
+
@name = name
|
25
|
+
end
|
26
|
+
|
27
|
+
def fatal
|
28
|
+
if @@logger
|
29
|
+
@@logger.fatal { "#{@name}: #{yield}" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def error
|
34
|
+
if @@logger
|
35
|
+
@@logger.error { "#{@name}: #{yield}" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def warn
|
40
|
+
if @@logger
|
41
|
+
@@logger.warn { "#{@name}: #{yield}" }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def info
|
46
|
+
if @@logger
|
47
|
+
@@logger.info { "#{@name}: #{yield}" }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def debug
|
52
|
+
if @@logger
|
53
|
+
@@logger.debug { "#{@name}: #{yield}" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,1339 +1,1239 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'json'
|
5
|
+
require 'yaml'
|
4
6
|
require 'base64'
|
5
|
-
|
6
|
-
|
7
|
-
require_relative '../xpath'
|
7
|
+
require 'rubyang/model'
|
8
|
+
require 'rubyang/xpath'
|
8
9
|
|
9
10
|
module Rubyang
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
# end
|
11
|
+
class Database
|
12
|
+
class SchemaTree
|
13
|
+
# when start
|
14
|
+
class When
|
15
|
+
attr_reader :arg, :xpath
|
16
|
+
def initialize schema_node, schema
|
17
|
+
@logger = Logger.new(self.class.name)
|
18
|
+
@schema_node = schema_node
|
19
|
+
@schema = schema
|
20
|
+
@arg = schema.arg
|
21
|
+
@xpath = Rubyang::Xpath::Parser.parse @arg
|
22
|
+
@logger.debug { 'when xpath:' }
|
23
|
+
@logger.debug { @xpath.to_yaml }
|
24
|
+
@schema_node.evaluate_xpath @xpath
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
# must start
|
30
|
+
class Must
|
31
|
+
attr_reader :arg, :xpath
|
32
|
+
def initialize schema_node, schema
|
33
|
+
@schema_node = schema_node
|
34
|
+
@schema = schema
|
35
|
+
@arg = schema.arg
|
36
|
+
@xpath = Rubyang::Xpath::Parser.parse @arg
|
37
|
+
@logger = Logger.new(self.class.name)
|
38
|
+
@logger.debug { @xpath }
|
39
|
+
@schema_node.evaluate_xpath @xpath
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
# min-elements start
|
45
|
+
class MinElements
|
46
|
+
attr_reader :arg
|
47
|
+
def initialize schema_node
|
48
|
+
@schema_node = schema_node
|
49
|
+
@arg = schema_node.arg
|
50
|
+
end
|
51
|
+
end
|
52
|
+
# end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
# max-elements start
|
55
|
+
class MaxElements
|
56
|
+
attr_reader :arg
|
57
|
+
def initialize schema_node
|
58
|
+
@schema_node = schema_node
|
59
|
+
@arg = schema_node.arg
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
64
|
+
class Type
|
65
|
+
attr_reader :arg
|
66
|
+
end
|
67
|
+
class IntegerType < Type
|
68
|
+
def initialize arg
|
69
|
+
@arg = arg
|
70
|
+
range = case arg
|
71
|
+
when 'int8' then '-128..127'
|
72
|
+
when 'int16' then '-32768..32767'
|
73
|
+
when 'int32' then '-2147483648..2147483647'
|
74
|
+
when 'int64' then '-9223372036854775808..9223372036854775807'
|
75
|
+
when 'uint8' then '0..255'
|
76
|
+
when 'uint16' then '0..65535'
|
77
|
+
when 'uint32' then '0..4294967295'
|
78
|
+
when 'uint64' then '0..18446744073709551615'
|
79
|
+
end
|
80
|
+
@range = Range.new range
|
81
|
+
end
|
82
|
+
def update_range arg
|
83
|
+
@range.update arg
|
84
|
+
end
|
85
|
+
def valid? value
|
86
|
+
result = true
|
87
|
+
result &&= @range.valid? value
|
88
|
+
result
|
89
|
+
end
|
90
|
+
end
|
91
|
+
class Decimal64Type < Type
|
92
|
+
def initialize arg
|
93
|
+
@arg = arg
|
94
|
+
end
|
95
|
+
def valid? value
|
96
|
+
result = true
|
97
|
+
result
|
98
|
+
end
|
99
|
+
end
|
100
|
+
class StringType < Type
|
101
|
+
attr_reader :length, :pattern
|
102
|
+
def initialize
|
103
|
+
@arg = 'string'
|
104
|
+
@length = Length.new
|
105
|
+
@pattern = Pattern.new
|
106
|
+
end
|
107
|
+
def update_length arg
|
108
|
+
@length.update arg
|
109
|
+
end
|
110
|
+
def update_pattern arg
|
111
|
+
@pattern.update arg
|
112
|
+
end
|
113
|
+
def valid? value
|
114
|
+
result = true
|
115
|
+
result &&= @length.valid? value
|
116
|
+
result &&= @pattern.valid? value
|
117
|
+
result
|
118
|
+
end
|
119
|
+
end
|
120
|
+
class BooleanType < Type
|
121
|
+
def initialize
|
122
|
+
@arg = 'boolean'
|
123
|
+
end
|
124
|
+
def valid? value
|
125
|
+
if 'true' == value
|
126
|
+
true
|
127
|
+
elsif 'false' == value
|
128
|
+
true
|
129
|
+
else
|
130
|
+
false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
class EnumerationType < Type
|
135
|
+
def initialize
|
136
|
+
@arg = 'enumeration'
|
137
|
+
@enum = Enum.new
|
138
|
+
end
|
139
|
+
def update_enum arg
|
140
|
+
@enum.update arg
|
141
|
+
end
|
142
|
+
def valid? value
|
143
|
+
result = true
|
144
|
+
result &&= @enum.valid? value
|
145
|
+
result
|
146
|
+
end
|
147
|
+
end
|
148
|
+
class BitsType < Type
|
149
|
+
def initialize
|
150
|
+
@arg = 'bits'
|
151
|
+
@bit = Bit.new
|
152
|
+
end
|
153
|
+
def update_bit arg
|
154
|
+
@bit.update arg
|
155
|
+
end
|
156
|
+
def valid? value
|
157
|
+
result = true
|
158
|
+
result &&= @bit.valid? value
|
159
|
+
result
|
160
|
+
end
|
161
|
+
end
|
162
|
+
class BinaryType < Type
|
163
|
+
def initialize
|
164
|
+
@arg = 'binary'
|
165
|
+
@length = Length.new
|
166
|
+
end
|
167
|
+
def update_length arg
|
168
|
+
@length.update arg
|
169
|
+
end
|
170
|
+
def valid? value
|
171
|
+
result = true
|
172
|
+
result &&= @length.valid? Base64.strict_decode64( value )
|
173
|
+
result
|
174
|
+
end
|
175
|
+
end
|
176
|
+
class LeafrefType < Type
|
177
|
+
def initialize schema_node, path_arg
|
178
|
+
@arg = 'leafref'
|
179
|
+
@path_arg = path_arg
|
180
|
+
@path = Path.new schema_node, path_arg
|
181
|
+
end
|
182
|
+
def path
|
183
|
+
@path.xpath
|
184
|
+
end
|
185
|
+
def valid? data_tree, value
|
186
|
+
result = true
|
187
|
+
result &&= @path.valid? data_tree, true
|
188
|
+
result
|
189
|
+
end
|
190
|
+
end
|
191
|
+
class EmptyType < Type
|
192
|
+
def initialize
|
193
|
+
@arg = 'empty'
|
194
|
+
end
|
195
|
+
def valid?
|
196
|
+
result = true
|
197
|
+
result
|
198
|
+
end
|
199
|
+
end
|
200
|
+
class UnionType < Type
|
201
|
+
def initialize
|
202
|
+
@arg = 'union'
|
203
|
+
@types = Array.new
|
204
|
+
end
|
205
|
+
def add_type type
|
206
|
+
@types.push type
|
207
|
+
end
|
208
|
+
def valid? value
|
209
|
+
result = false
|
210
|
+
result ||= @types.inject( false ){ |r, t| r || t.valid?( value ) }
|
211
|
+
result
|
212
|
+
end
|
213
|
+
end
|
214
|
+
class Identityref < Type
|
215
|
+
def initialize identity_list, type_stmt
|
216
|
+
@arg = 'identityref'
|
217
|
+
@base_arg = type_stmt.substmt( 'base' ).first.arg
|
218
|
+
@identity_list = identity_list
|
219
|
+
end
|
220
|
+
def valid? value
|
221
|
+
@identity_list.select{ |identity| (identity.substmt( 'base' ).first.arg rescue nil) == @base_arg }.any?{ |identity| identity.arg == value }
|
222
|
+
end
|
223
|
+
end
|
225
224
|
|
226
|
-
|
227
|
-
|
225
|
+
class Path
|
226
|
+
attr_reader :xpath
|
228
227
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
if @bit.find{ |b| b == arg }
|
394
|
-
raise ArgumentError, "#{arg} is not valid"
|
395
|
-
end
|
396
|
-
@bit.push arg
|
397
|
-
end
|
398
|
-
end
|
228
|
+
def initialize schema_node, arg
|
229
|
+
@xpath = Rubyang::Xpath::Parser.parse arg
|
230
|
+
@logger = Logger.new(self.class.name)
|
231
|
+
#if !(@xpath[0].axis.name == Rubyang::Xpath::Axis::PARENT && @xpath[0].node_test.node_test == Rubyang::Xpath::NodeTest::NodeType::NODE)
|
232
|
+
#raise "unsupported path: #{@xpath}"
|
233
|
+
#end
|
234
|
+
@logger.debug { 'in Path:' }
|
235
|
+
@logger.debug { 'schema_node:' }
|
236
|
+
@logger.debug { schema_node.to_yaml }
|
237
|
+
@logger.debug { '@xpath:' }
|
238
|
+
@logger.debug { @xpath.to_yaml }
|
239
|
+
target = schema_node.evaluate_xpath( @xpath )
|
240
|
+
if target.class != Array || target.size == 0
|
241
|
+
raise ArgumentError, "#{arg} is not valid"
|
242
|
+
end
|
243
|
+
@target = target
|
244
|
+
end
|
245
|
+
def valid? data_tree, value
|
246
|
+
true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
class Range
|
250
|
+
def initialize arg
|
251
|
+
@range = [[-Float::INFINITY, Float::INFINITY]]
|
252
|
+
self.update arg
|
253
|
+
end
|
254
|
+
def valid? value
|
255
|
+
if @range.find{ |min2, max2| (min2..max2).include?( Integer(value) ) }
|
256
|
+
true
|
257
|
+
else
|
258
|
+
false
|
259
|
+
end
|
260
|
+
end
|
261
|
+
def update arg
|
262
|
+
new_range = Array.new
|
263
|
+
arg.delete( ' ' ).split( '|' ).each{ |range_part|
|
264
|
+
case range_part
|
265
|
+
when /[^\.]+\.\.[^\.]+/
|
266
|
+
min, max = range_part.split('..')
|
267
|
+
else
|
268
|
+
min = max = range_part
|
269
|
+
end
|
270
|
+
case min
|
271
|
+
when /^min$/
|
272
|
+
min = @range.map{ |r| r[0] }.min
|
273
|
+
else
|
274
|
+
min = min.to_i
|
275
|
+
end
|
276
|
+
case max
|
277
|
+
when /^max$/
|
278
|
+
max = @range.map{ |r| r[1] }.max
|
279
|
+
else
|
280
|
+
max = max.to_i
|
281
|
+
end
|
282
|
+
unless @range.find{ |min2, max2| (min2..max2).include?( min ) && (min2..max2).include?( max ) }
|
283
|
+
raise ArgumentError, "#{range_part} is not valid"
|
284
|
+
end
|
285
|
+
new_range.push [min, max]
|
286
|
+
}
|
287
|
+
@range = new_range
|
288
|
+
end
|
289
|
+
def to_s
|
290
|
+
@range.map{ |l| "#{l[0]}..#{l[1]}" }.join( "|" )
|
291
|
+
end
|
292
|
+
end
|
293
|
+
class Length
|
294
|
+
def initialize
|
295
|
+
@length = [[0, 18446744073709551615]]
|
296
|
+
end
|
297
|
+
def valid? value
|
298
|
+
if @length.find{ |min2, max2| (min2..max2).include?( value.size ) }
|
299
|
+
true
|
300
|
+
else
|
301
|
+
false
|
302
|
+
end
|
303
|
+
end
|
304
|
+
def update arg
|
305
|
+
new_length = Array.new
|
306
|
+
arg.delete( ' ' ).split( '|' ).each{ |length_part|
|
307
|
+
case length_part
|
308
|
+
when /[^\.]+\.\.[^\.]+/
|
309
|
+
min, max = length_part.split('..')
|
310
|
+
else
|
311
|
+
min = max = length_part
|
312
|
+
end
|
313
|
+
case min
|
314
|
+
when /^min$/
|
315
|
+
min = @length.map{ |r| r[0] }.min
|
316
|
+
else
|
317
|
+
min = min.to_i
|
318
|
+
end
|
319
|
+
case max
|
320
|
+
when /^max$/
|
321
|
+
max = @length.map{ |r| r[1] }.max
|
322
|
+
else
|
323
|
+
max = max.to_i
|
324
|
+
end
|
325
|
+
unless @length.find{ |min2, max2| (min2..max2).include?( min ) && (min2..max2).include?( max ) }
|
326
|
+
raise ArgumentError, "#{length_part} is not valid"
|
327
|
+
end
|
328
|
+
new_length.push [min, max]
|
329
|
+
}
|
330
|
+
@length = new_length
|
331
|
+
end
|
332
|
+
def to_s
|
333
|
+
@length.map{ |l| "#{l[0]}..#{l[1]}" }.join( "|" )
|
334
|
+
end
|
335
|
+
end
|
336
|
+
class Pattern
|
337
|
+
def initialize
|
338
|
+
@pattern = Regexp.new( '^.*$' )
|
339
|
+
end
|
340
|
+
def valid? value
|
341
|
+
if @pattern =~ value
|
342
|
+
true
|
343
|
+
else
|
344
|
+
false
|
345
|
+
end
|
346
|
+
end
|
347
|
+
def update arg
|
348
|
+
p arg
|
349
|
+
@pattern = Regexp.new( '^' + arg + '$' )
|
350
|
+
end
|
351
|
+
def to_s
|
352
|
+
@pattern.inspect
|
353
|
+
end
|
354
|
+
end
|
355
|
+
class Enum
|
356
|
+
def initialize
|
357
|
+
@enum = []
|
358
|
+
end
|
359
|
+
def valid? value
|
360
|
+
if @enum.find{ |e| e == value }
|
361
|
+
true
|
362
|
+
else
|
363
|
+
false
|
364
|
+
end
|
365
|
+
end
|
366
|
+
def update arg
|
367
|
+
if @enum.find{ |e| e == arg }
|
368
|
+
raise ArgumentError, "#{arg} is not valid"
|
369
|
+
end
|
370
|
+
@enum.push arg
|
371
|
+
end
|
372
|
+
end
|
373
|
+
class Bit
|
374
|
+
def initialize
|
375
|
+
@bit = []
|
376
|
+
end
|
377
|
+
def valid? value
|
378
|
+
values = value.split( ' ' )
|
379
|
+
if values.inject( true ){ |result, v| result && @bit.find{ |b| b == v } }
|
380
|
+
true
|
381
|
+
else
|
382
|
+
false
|
383
|
+
end
|
384
|
+
end
|
385
|
+
def update arg
|
386
|
+
if @bit.find{ |b| b == arg }
|
387
|
+
raise ArgumentError, "#{arg} is not valid"
|
388
|
+
end
|
389
|
+
@bit.push arg
|
390
|
+
end
|
391
|
+
end
|
399
392
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
393
|
+
# TODO: should add config_mode_context to validate and raise error if there is config true stmt in config false stmt
|
394
|
+
class SchemaNode
|
395
|
+
attr_accessor :yangs, :arg, :yang, :parent, :module
|
396
|
+
def initialize yangs, arg, yang, parent, _module
|
397
|
+
@logger = Logger.new(self.class.name)
|
398
|
+
@yangs = yangs
|
399
|
+
@arg = arg
|
400
|
+
@yang = yang
|
401
|
+
@parent = parent
|
402
|
+
@module = _module
|
403
|
+
end
|
404
|
+
def to_s parent=true
|
405
|
+
head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
|
406
|
+
if parent
|
407
|
+
vars.push "@yangs=#{@yangs.to_s}"
|
408
|
+
vars.push "@arg=#{@arg.to_s}"
|
409
|
+
vars.push "@yang=#{@yang.to_s(false) rescue @yang.to_s}"
|
410
|
+
vars.push "@parent=#{@parent.to_s(false) rescue @parent.to_s}"
|
411
|
+
vars.push "@module=#{@module.to_s(false) rescue @module.to_s}"
|
412
|
+
end
|
413
|
+
head + vars.join(', ') + tail
|
414
|
+
end
|
415
|
+
def model
|
416
|
+
@yang
|
417
|
+
end
|
418
|
+
def namespace
|
419
|
+
@module.substmt( 'namespace' )[0].arg
|
420
|
+
end
|
421
|
+
def prefix
|
422
|
+
@module.substmt( 'prefix' )[0].arg
|
423
|
+
end
|
424
|
+
def root
|
425
|
+
if @parent == nil
|
426
|
+
self
|
427
|
+
else
|
428
|
+
@parent.root
|
429
|
+
end
|
430
|
+
end
|
431
|
+
def to_json
|
432
|
+
h = Hash.new
|
433
|
+
self.to_json_recursive( h )
|
434
|
+
h.to_json
|
435
|
+
end
|
442
436
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
puts
|
452
|
-
puts 'current:'
|
453
|
-
puts current.class
|
454
|
-
puts
|
455
|
-
end
|
456
|
-
evaluate_xpath_expr xpath, current
|
457
|
-
end
|
437
|
+
def evaluate_xpath xpath, current=self
|
438
|
+
@logger.debug { 'in evaluate_xpath:' }
|
439
|
+
@logger.debug { 'xpath:' }
|
440
|
+
@logger.debug { xpath.to_yaml }
|
441
|
+
@logger.debug { 'current:' }
|
442
|
+
@logger.debug { current.class }
|
443
|
+
evaluate_xpath_expr xpath, current
|
444
|
+
end
|
458
445
|
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
puts
|
489
|
-
puts 'candidates_by_node_test:'
|
490
|
-
puts candidates_by_node_test.to_yaml
|
491
|
-
end
|
492
|
-
candidates_by_predicates = candidates_by_node_test.inject([]){ |cs, c| cs + c.evaluate_xpath_predicates( first_location_step, current ) }
|
493
|
-
if Rubyang::Xpath::Parser::DEBUG
|
494
|
-
require 'yaml'
|
495
|
-
puts
|
496
|
-
puts 'candidates_by_predicates:'
|
497
|
-
puts candidates_by_predicates.to_yaml
|
498
|
-
end
|
499
|
-
if location_path.location_step_sequence[1..-1].size == 0
|
500
|
-
candidates_by_predicates
|
501
|
-
else
|
502
|
-
candidates_by_predicates.inject([]){ |cs, c|
|
503
|
-
following_location_path = Rubyang::Xpath::LocationPath.new *(location_path.location_step_sequence[1..-1])
|
504
|
-
if Rubyang::Xpath::Parser::DEBUG
|
505
|
-
puts
|
506
|
-
puts 'following_location_path:'
|
507
|
-
puts following_location_path.to_yaml
|
508
|
-
puts
|
509
|
-
end
|
510
|
-
c.evaluate_xpath_path( following_location_path, current )
|
511
|
-
}
|
512
|
-
end
|
513
|
-
end
|
446
|
+
def evaluate_xpath_path location_path, current
|
447
|
+
@logger.debug { 'in evaluate_xpath_path:' }
|
448
|
+
@logger.debug { 'location_path:' }
|
449
|
+
@logger.debug { location_path.to_yaml }
|
450
|
+
@logger.debug { 'current:' }
|
451
|
+
@logger.debug { current.class }
|
452
|
+
first_location_step = location_path.location_step_sequence.first
|
453
|
+
@logger.debug { 'first_location_step:' }
|
454
|
+
@logger.debug { first_location_step.to_yaml }
|
455
|
+
candidates_by_axis = self.evaluate_xpath_axis( first_location_step, current )
|
456
|
+
@logger.debug { 'candidates_by_axis:' }
|
457
|
+
@logger.debug { candidates_by_axis.to_yaml }
|
458
|
+
candidates_by_node_test = candidates_by_axis.inject([]){ |cs, c| cs + c.evaluate_xpath_node_test( first_location_step, current ) }
|
459
|
+
@logger.debug { 'candidates_by_node_test:' }
|
460
|
+
@logger.debug { candidates_by_node_test.to_yaml }
|
461
|
+
candidates_by_predicates = candidates_by_node_test.inject([]){ |cs, c| cs + c.evaluate_xpath_predicates( first_location_step, current ) }
|
462
|
+
@logger.debug { 'candidates_by_predicates:' }
|
463
|
+
@logger.debug { candidates_by_predicates.to_yaml }
|
464
|
+
if location_path.location_step_sequence[1..-1].size == 0
|
465
|
+
candidates_by_predicates
|
466
|
+
else
|
467
|
+
candidates_by_predicates.inject([]){ |cs, c|
|
468
|
+
following_location_path = Rubyang::Xpath::LocationPath.new *(location_path.location_step_sequence[1..-1])
|
469
|
+
@logger.debug { 'following_location_path:' }
|
470
|
+
@logger.debug { following_location_path.to_yaml }
|
471
|
+
c.evaluate_xpath_path( following_location_path, current )
|
472
|
+
}
|
473
|
+
end
|
474
|
+
end
|
514
475
|
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
[@parent]
|
533
|
-
when Rubyang::Xpath::Axis::CHILD
|
534
|
-
@children
|
535
|
-
else
|
536
|
-
raise "location_step.axis.name: #{location_step.axis.name} NOT implemented"
|
537
|
-
end
|
538
|
-
end
|
476
|
+
def evaluate_xpath_axis location_step, current
|
477
|
+
@logger.debug { 'in evaluate_xpath_axis:' }
|
478
|
+
@logger.debug { 'location_step:' }
|
479
|
+
@logger.debug { location_step.to_yaml }
|
480
|
+
@logger.debug { 'current:' }
|
481
|
+
@logger.debug { current.class }
|
482
|
+
case location_step.axis.name
|
483
|
+
when Rubyang::Xpath::Axis::SELF
|
484
|
+
[self]
|
485
|
+
when Rubyang::Xpath::Axis::PARENT
|
486
|
+
[@parent]
|
487
|
+
when Rubyang::Xpath::Axis::CHILD
|
488
|
+
@children
|
489
|
+
else
|
490
|
+
raise "location_step.axis.name: #{location_step.axis.name} NOT implemented"
|
491
|
+
end
|
492
|
+
end
|
539
493
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
494
|
+
def evaluate_xpath_node_test location_step, current
|
495
|
+
case location_step.node_test.node_test_type
|
496
|
+
when Rubyang::Xpath::NodeTest::NodeTestType::NAME_TEST
|
497
|
+
if self.model.arg == location_step.node_test.node_test
|
498
|
+
[self]
|
499
|
+
else
|
500
|
+
[]
|
501
|
+
end
|
502
|
+
when Rubyang::Xpath::NodeTest::NodeTestType::NODE_TYPE
|
503
|
+
case location_step.node_test.node_test
|
504
|
+
when Rubyang::Xpath::NodeTest::NodeType::COMMENT
|
505
|
+
raise "node-type: comment is not implemented"
|
506
|
+
when Rubyang::Xpath::NodeTest::NodeType::TEXT
|
507
|
+
raise "node-type: text is not implemented"
|
508
|
+
when Rubyang::Xpath::NodeTest::NodeType::NODE
|
509
|
+
[self]
|
510
|
+
else
|
511
|
+
raise "node-type not match to comment or text or node"
|
512
|
+
end
|
513
|
+
when Rubyang::Xpath::NodeTest::NodeTestType::PROCESSING_INSTRUCTION
|
514
|
+
raise "processing-instruction is not implemented"
|
515
|
+
else
|
516
|
+
raise ""
|
517
|
+
end
|
518
|
+
end
|
565
519
|
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
520
|
+
def evaluate_xpath_predicates location_step, current
|
521
|
+
case location_step.predicates.size
|
522
|
+
when 0
|
523
|
+
[self]
|
524
|
+
else
|
525
|
+
location_step.predicates.each{ |predicate|
|
526
|
+
self.evaluate_xpath_expr predicate.expr, current
|
527
|
+
}
|
528
|
+
[self]
|
529
|
+
end
|
530
|
+
end
|
577
531
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
puts
|
767
|
-
end
|
768
|
-
op1 = expr.op1
|
769
|
-
op2 = expr.op2
|
770
|
-
op1_result = self.evaluate_xpath_expr( op1, current )
|
771
|
-
if op2 == nil
|
772
|
-
op1_result
|
773
|
-
else
|
774
|
-
op2_result = self.evaluate_xpath_expr( op2.expr, current )
|
775
|
-
Rubyang::Xpath::BasicType::NodeSet
|
776
|
-
end
|
777
|
-
when Rubyang::Xpath::PrimaryExpr
|
778
|
-
if Rubyang::Xpath::Parser::DEBUG
|
779
|
-
puts
|
780
|
-
puts "in PrimaryExpr"
|
781
|
-
puts "op1: #{expr.op1}"
|
782
|
-
puts
|
783
|
-
end
|
784
|
-
op1 = expr.op1
|
785
|
-
case op1
|
786
|
-
when Rubyang::Xpath::VariableReference
|
787
|
-
Rubyang::Xpath::BasicType::String
|
788
|
-
when Rubyang::Xpath::Expr
|
789
|
-
op1_result = self.evaluate_xpath_expr( op1, current )
|
790
|
-
when Rubyang::Xpath::Literal
|
791
|
-
Rubyang::Xpath::BasicType::String
|
792
|
-
when Rubyang::Xpath::Number
|
793
|
-
Rubyang::Xpath::BasicType::Boolean
|
794
|
-
when Rubyang::Xpath::FunctionCall
|
795
|
-
op1_result = self.evaluate_xpath_expr( op1, current )
|
796
|
-
else
|
797
|
-
raise "Primary Expr: '#{op1}' not implemented"
|
798
|
-
end
|
799
|
-
when Rubyang::Xpath::FunctionCall
|
800
|
-
if Rubyang::Xpath::Parser::DEBUG
|
801
|
-
puts
|
802
|
-
puts "in FunctionCall"
|
803
|
-
puts "name: #{expr.name}"
|
804
|
-
puts "args: #{expr.args}"
|
805
|
-
puts
|
806
|
-
end
|
807
|
-
name = expr.name
|
808
|
-
case name
|
809
|
-
when Rubyang::Xpath::FunctionCall::CURRENT
|
810
|
-
Rubyang::Xpath::BasicType::NodeSet
|
811
|
-
else
|
812
|
-
raise "FunctionCall: #{name} not implemented"
|
813
|
-
end
|
814
|
-
else
|
815
|
-
raise "Unrecognized Expr: #{expr}"
|
816
|
-
end
|
817
|
-
end
|
532
|
+
def evaluate_xpath_expr expr, current
|
533
|
+
case expr
|
534
|
+
when Rubyang::Xpath::Expr
|
535
|
+
@logger.debug { "in Expr" }
|
536
|
+
@logger.debug { "op: #{expr.op}" }
|
537
|
+
op = expr.op
|
538
|
+
op_result = self.evaluate_xpath_expr( op, current )
|
539
|
+
when Rubyang::Xpath::OrExpr
|
540
|
+
@logger.debug { "in OrExpr" }
|
541
|
+
@logger.debug { "op1: #{expr.op1}" }
|
542
|
+
@logger.debug { "op2: #{expr.op2}" }
|
543
|
+
op1 = expr.op1
|
544
|
+
op2 = expr.op2
|
545
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
546
|
+
if op2 == nil
|
547
|
+
op1_result
|
548
|
+
else
|
549
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
550
|
+
Rubyang::Xpath::BasicType::Boolean
|
551
|
+
end
|
552
|
+
when Rubyang::Xpath::AndExpr
|
553
|
+
@logger.debug { "in AndExpr" }
|
554
|
+
@logger.debug { "op1: #{expr.op1}" }
|
555
|
+
@logger.debug { "op2: #{expr.op2}" }
|
556
|
+
op1 = expr.op1
|
557
|
+
op2 = expr.op2
|
558
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
559
|
+
if op2 == nil
|
560
|
+
op1_result
|
561
|
+
else
|
562
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
563
|
+
Rubyang::Xpath::BasicType::Boolean
|
564
|
+
end
|
565
|
+
when Rubyang::Xpath::EqualityExpr
|
566
|
+
@logger.debug { "in EqualityExpr" }
|
567
|
+
@logger.debug { "op1: #{expr.op1}" }
|
568
|
+
@logger.debug { "op2: #{expr.op2}" }
|
569
|
+
@logger.debug { "operator: #{expr.operator}" }
|
570
|
+
op1 = expr.op1
|
571
|
+
op2 = expr.op2
|
572
|
+
operator = expr.operator
|
573
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
574
|
+
if op2 == nil
|
575
|
+
op1_result
|
576
|
+
else
|
577
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
578
|
+
Rubyang::Xpath::BasicType::Boolean
|
579
|
+
end
|
580
|
+
when Rubyang::Xpath::RelationalExpr
|
581
|
+
@logger.debug { "in RelationalExpr" }
|
582
|
+
@logger.debug { "op1: #{expr.op1}" }
|
583
|
+
@logger.debug { "op2: #{expr.op2}" }
|
584
|
+
@logger.debug { "operator: #{expr.operator}" }
|
585
|
+
op1 = expr.op1
|
586
|
+
op2 = expr.op2
|
587
|
+
operator = expr.operator
|
588
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
589
|
+
if op2 == nil
|
590
|
+
op1_result
|
591
|
+
else
|
592
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
593
|
+
Rubyang::Xpath::BasicType::Boolean
|
594
|
+
end
|
595
|
+
when Rubyang::Xpath::AdditiveExpr
|
596
|
+
@logger.debug { "in AdditiveExpr" }
|
597
|
+
@logger.debug { "op1: #{expr.op1}" }
|
598
|
+
@logger.debug { "op2: #{expr.op2}" }
|
599
|
+
@logger.debug { "operator: #{expr.operator}" }
|
600
|
+
op1 = expr.op1
|
601
|
+
op2 = expr.op2
|
602
|
+
operator = expr.operator
|
603
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
604
|
+
if op2 == nil
|
605
|
+
op1_result
|
606
|
+
else
|
607
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
608
|
+
Rubyang::Xpath::BasicType::Number
|
609
|
+
end
|
610
|
+
when Rubyang::Xpath::MultiplicativeExpr
|
611
|
+
@logger.debug { "in MultiplicativeExpr" }
|
612
|
+
@logger.debug { "op1: #{expr.op1}" }
|
613
|
+
@logger.debug { "op2: #{expr.op2}" }
|
614
|
+
@logger.debug { "operator: #{expr.operator}" }
|
615
|
+
op1 = expr.op1
|
616
|
+
op2 = expr.op2
|
617
|
+
operator = expr.operator
|
618
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
619
|
+
if op2 == nil
|
620
|
+
op1_result
|
621
|
+
else
|
622
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
623
|
+
Rubyang::Xpath::BasicType::Number
|
624
|
+
end
|
625
|
+
when Rubyang::Xpath::UnaryExpr
|
626
|
+
@logger.debug { "in UnaryExpr" }
|
627
|
+
@logger.debug { "op1: #{expr.op1}" }
|
628
|
+
@logger.debug { "operator: #{expr.operator}" }
|
629
|
+
op1 = expr.op1
|
630
|
+
operator = expr.operator
|
631
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
632
|
+
if operator == nil
|
633
|
+
op1_result
|
634
|
+
else
|
635
|
+
Rubyang::Xpath::BasicType::Number
|
636
|
+
end
|
637
|
+
when Rubyang::Xpath::UnionExpr
|
638
|
+
@logger.debug { "in UnionExpr" }
|
639
|
+
@logger.debug { "op1: #{expr.op1}" }
|
640
|
+
@logger.debug { "op2: #{expr.op2}" }
|
641
|
+
@logger.debug { "operator: #{expr.operator}" }
|
642
|
+
op1 = expr.op1
|
643
|
+
op2 = expr.op2
|
644
|
+
operator = expr.operator
|
645
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
646
|
+
if op2 == nil
|
647
|
+
op1_result
|
648
|
+
else
|
649
|
+
op2_result = self.evaluate_xpath_expr( op2, current )
|
650
|
+
Rubyang::Xpath::BasicType::NodeSet
|
651
|
+
end
|
652
|
+
when Rubyang::Xpath::PathExpr
|
653
|
+
@logger.debug { "in PathExpr" }
|
654
|
+
@logger.debug { "op1: #{expr.op1}" }
|
655
|
+
@logger.debug { "op2: #{expr.op2}" }
|
656
|
+
@logger.debug { "operator: #{expr.operator}" }
|
657
|
+
op1 = expr.op1
|
658
|
+
op2 = expr.op2
|
659
|
+
operator = expr.operator
|
660
|
+
op1_result = case op1
|
661
|
+
when Rubyang::Xpath::LocationPath
|
662
|
+
self.evaluate_xpath_path( op1, current )
|
663
|
+
when Rubyang::Xpath::FilterExpr
|
664
|
+
self.evaluate_xpath_expr( op1, current )
|
665
|
+
else
|
666
|
+
raise "PathExpr: #{op1} not supported"
|
667
|
+
end
|
668
|
+
if op2 == nil
|
669
|
+
op1_result
|
670
|
+
else
|
671
|
+
op2_result = self.evaluate_xpath_path( op2, current )
|
672
|
+
Rubyang::Xpath::BasicType::NodeSet
|
673
|
+
end
|
674
|
+
when Rubyang::Xpath::FilterExpr
|
675
|
+
@logger.debug { "in FilterExpr" }
|
676
|
+
@logger.debug { "op1: #{expr.op1}" }
|
677
|
+
@logger.debug { "op2: #{expr.op2}" }
|
678
|
+
op1 = expr.op1
|
679
|
+
op2 = expr.op2
|
680
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
681
|
+
if op2 == nil
|
682
|
+
op1_result
|
683
|
+
else
|
684
|
+
op2_result = self.evaluate_xpath_expr( op2.expr, current )
|
685
|
+
Rubyang::Xpath::BasicType::NodeSet
|
686
|
+
end
|
687
|
+
when Rubyang::Xpath::PrimaryExpr
|
688
|
+
@logger.debug { "in PrimaryExpr" }
|
689
|
+
@logger.debug { "op1: #{expr.op1}" }
|
690
|
+
op1 = expr.op1
|
691
|
+
case op1
|
692
|
+
when Rubyang::Xpath::VariableReference
|
693
|
+
Rubyang::Xpath::BasicType::String
|
694
|
+
when Rubyang::Xpath::Expr
|
695
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
696
|
+
when Rubyang::Xpath::Literal
|
697
|
+
Rubyang::Xpath::BasicType::String
|
698
|
+
when Rubyang::Xpath::Number
|
699
|
+
Rubyang::Xpath::BasicType::Boolean
|
700
|
+
when Rubyang::Xpath::FunctionCall
|
701
|
+
op1_result = self.evaluate_xpath_expr( op1, current )
|
702
|
+
else
|
703
|
+
raise "Primary Expr: '#{op1}' not implemented"
|
704
|
+
end
|
705
|
+
when Rubyang::Xpath::FunctionCall
|
706
|
+
@logger.debug { "in FunctionCall" }
|
707
|
+
@logger.debug { "name: #{expr.name}" }
|
708
|
+
@logger.debug { "args: #{expr.args}" }
|
709
|
+
name = expr.name
|
710
|
+
case name
|
711
|
+
when Rubyang::Xpath::FunctionCall::CURRENT
|
712
|
+
Rubyang::Xpath::BasicType::NodeSet
|
713
|
+
else
|
714
|
+
raise "FunctionCall: #{name} not implemented"
|
715
|
+
end
|
716
|
+
else
|
717
|
+
raise "Unrecognized Expr: #{expr}"
|
718
|
+
end
|
719
|
+
end
|
818
720
|
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
end
|
949
|
-
end
|
721
|
+
def load_yang yang, yangs=@yangs, parent_module=yang, current_module=yang, grouping_list=[], typedef_list=[], identity_list=[]
|
722
|
+
case yang
|
723
|
+
when Rubyang::Model::Module
|
724
|
+
yangs.push yang
|
725
|
+
module_arg = yang.arg
|
726
|
+
namespace_arg = yang.substmt( 'namespace' )[0].arg
|
727
|
+
prefix_arg = yang.substmt( 'prefix' )[0].arg
|
728
|
+
grouping_list += yang.substmt( 'grouping' )
|
729
|
+
typedef_list += yang.substmt( 'typedef' )
|
730
|
+
identity_list += yang.substmt( 'identity' )
|
731
|
+
yang.substmt( 'include' ).each{ |i|
|
732
|
+
i.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
733
|
+
self.load_yang s, yangs, parent_module, i, i.substmt( 'grouping' ), i.substmt( 'typedef' ), i.substmt( 'identity' )
|
734
|
+
}
|
735
|
+
}
|
736
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
737
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
738
|
+
}
|
739
|
+
when Rubyang::Model::Submodule
|
740
|
+
yangs.push yang
|
741
|
+
when Rubyang::Model::Anyxml
|
742
|
+
arg = yang.arg
|
743
|
+
self.children.push Anyxml.new( yangs, arg, yang, self, parent_module )
|
744
|
+
when Rubyang::Model::Container
|
745
|
+
container_arg = yang.arg
|
746
|
+
grouping_list += yang.substmt( 'grouping' )
|
747
|
+
typedef_list += yang.substmt( 'typedef' )
|
748
|
+
identity_list += yang.substmt( 'identity' )
|
749
|
+
self.children.push Container.new( yangs, container_arg, yang, self, parent_module )
|
750
|
+
# when start
|
751
|
+
yang.substmt( "when" ).each{ |s|
|
752
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
753
|
+
}
|
754
|
+
# end
|
755
|
+
# must start
|
756
|
+
yang.substmt( "must" ).each{ |s|
|
757
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
758
|
+
}
|
759
|
+
# end
|
760
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
761
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
762
|
+
}
|
763
|
+
when Rubyang::Model::Leaf
|
764
|
+
leaf_arg = yang.arg
|
765
|
+
self.children.push Leaf.new( yangs, leaf_arg, yang, self, parent_module, current_module, typedef_list, identity_list )
|
766
|
+
when Rubyang::Model::LeafList
|
767
|
+
leaf_arg = yang.arg
|
768
|
+
self.children.push LeafList.new( yangs, leaf_arg, yang, self, parent_module, current_module, typedef_list, identity_list )
|
769
|
+
# min-elements start
|
770
|
+
yang.substmt( "min-elements" ).each{ |s|
|
771
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
772
|
+
}
|
773
|
+
# end
|
774
|
+
# max-elements start
|
775
|
+
yang.substmt( "max-elements" ).each{ |s|
|
776
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
777
|
+
}
|
778
|
+
# end
|
779
|
+
when Rubyang::Model::List
|
780
|
+
list_arg = yang.arg
|
781
|
+
grouping_list += yang.substmt( 'grouping' )
|
782
|
+
typedef_list += yang.substmt( 'typedef' )
|
783
|
+
identity_list += yang.substmt( 'identity' )
|
784
|
+
self.children.push List.new( yangs, list_arg, yang, self, parent_module )
|
785
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
786
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
787
|
+
}
|
788
|
+
# min-elements start
|
789
|
+
yang.substmt( "min-elements" ).each{ |s|
|
790
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
791
|
+
}
|
792
|
+
# end
|
793
|
+
# max-elements start
|
794
|
+
yang.substmt( "max-elements" ).each{ |s|
|
795
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
796
|
+
}
|
797
|
+
# end
|
798
|
+
when Rubyang::Model::Choice
|
799
|
+
choice_arg = yang.arg
|
800
|
+
grouping_list += yang.substmt( 'grouping' )
|
801
|
+
typedef_list += yang.substmt( 'typedef' )
|
802
|
+
identity_list += yang.substmt( 'identity' )
|
803
|
+
self.children.push Choice.new( yangs, choice_arg, yang, self, parent_module )
|
804
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
805
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
806
|
+
}
|
807
|
+
when Rubyang::Model::Case
|
808
|
+
case_arg = yang.arg
|
809
|
+
grouping_list += yang.substmt( 'grouping' )
|
810
|
+
typedef_list += yang.substmt( 'typedef' )
|
811
|
+
self.children.push Case.new( yangs, case_arg, yang, self, parent_module )
|
812
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
813
|
+
self.children.last.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
814
|
+
}
|
815
|
+
when Rubyang::Model::Augment
|
816
|
+
target_node = self.resolve_node( yang.arg )
|
817
|
+
yang.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
818
|
+
target_node.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
819
|
+
}
|
820
|
+
when Rubyang::Model::Uses
|
821
|
+
self.resolve_uses( yang, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list )
|
822
|
+
# when start
|
823
|
+
when Rubyang::Model::When
|
824
|
+
@logger.debug { 'when statement' }
|
825
|
+
@logger.debug { '' }
|
826
|
+
@logger.debug { 'yang' }
|
827
|
+
@logger.debug { yang.to_yaml }
|
828
|
+
self.whens.push When.new( self, yang )
|
829
|
+
# end
|
830
|
+
# must start
|
831
|
+
when Rubyang::Model::Must
|
832
|
+
@logger.debug { yang }
|
833
|
+
self.musts.push Must.new( self, yang )
|
834
|
+
# end
|
835
|
+
# min-elements start
|
836
|
+
when Rubyang::Model::MinElements
|
837
|
+
@logger.debug { yang }
|
838
|
+
self.min_elements.push MinElements.new( yang )
|
839
|
+
# end
|
840
|
+
# max-elements start
|
841
|
+
when Rubyang::Model::MaxElements
|
842
|
+
@logger.debug { yang }
|
843
|
+
self.max_elements.push MaxElements.new( yang )
|
844
|
+
# end
|
845
|
+
else
|
846
|
+
raise "#{yang.class} is not impletented yet"
|
847
|
+
end
|
848
|
+
end
|
849
|
+
end
|
950
850
|
|
951
|
-
|
952
|
-
|
851
|
+
class InteriorSchemaNode < SchemaNode
|
852
|
+
attr_accessor :yangs, :arg, :yang, :parent, :children
|
953
853
|
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
854
|
+
def initialize yangs, arg, yang, parent, _module
|
855
|
+
super yangs, arg, yang, parent, _module
|
856
|
+
@children = []
|
857
|
+
@logger = Logger.new(self.class.name)
|
858
|
+
end
|
959
859
|
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
860
|
+
def resolve_uses uses_stmt, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
861
|
+
case uses_stmt.arg
|
862
|
+
when /^[^:]+$/
|
863
|
+
arg = uses_stmt.arg
|
864
|
+
if grouping_list.find{ |s| s.arg == arg }
|
865
|
+
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
866
|
+
grouping_list += grouping_stmt.substmt( 'grouping' )
|
867
|
+
typedef_list += grouping_stmt.substmt( 'typedef' )
|
868
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
869
|
+
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
870
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
871
|
+
}
|
872
|
+
else
|
873
|
+
include_submodule = current_module.substmt( 'include' ).map{ |s|
|
874
|
+
yangs.find{ |y| y.arg == s.arg }
|
875
|
+
}.find{ |s|
|
876
|
+
s.substmt( 'grouping' ).find{ |t| t.arg == arg }
|
877
|
+
}
|
878
|
+
grouping_stmt = include_submodule.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
879
|
+
grouping_list = include_submodule.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
880
|
+
typedef_list = include_submodule.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
881
|
+
identity_list = include_submodule.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
882
|
+
grouping_stmt.substmt( Rubyang::Model::DataDefStmtList ).each{ |s|
|
883
|
+
self.load_yang s, yangs, parent_module, include_submodule, grouping_list, typedef_list, identity_list
|
884
|
+
}
|
885
|
+
end
|
886
|
+
when /^[^:]+:[^:]+$/
|
887
|
+
prefix, arg = uses_stmt.arg.split(':')
|
888
|
+
case current_module
|
889
|
+
when Rubyang::Model::Module
|
890
|
+
case prefix
|
891
|
+
when current_module.substmt( 'prefix' )[0].arg
|
892
|
+
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
893
|
+
grouping_list += grouping_stmt.substmt( 'grouping' )
|
894
|
+
typedef_list += grouping_stmt.substmt( 'typedef' )
|
895
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
896
|
+
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
897
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
898
|
+
}
|
899
|
+
else
|
900
|
+
import_module = yangs.find{ |y|
|
901
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
902
|
+
}
|
903
|
+
grouping_stmt = import_module.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
904
|
+
grouping_list = import_module.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
905
|
+
typedef_list = import_module.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
906
|
+
identity_list = import_module.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
907
|
+
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
908
|
+
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list, identity_list
|
909
|
+
}
|
910
|
+
end
|
911
|
+
when Rubyang::Model::Submodule
|
912
|
+
case prefix
|
913
|
+
when current_module.substmt( 'belongs-to' )[0].substmt( 'prefix' )[0].arg
|
914
|
+
grouping_stmt = grouping_list.find{ |s| s.arg == arg }
|
915
|
+
grouping_list += grouping_stmt.substmt( 'grouping' )
|
916
|
+
typedef_list += grouping_stmt.substmt( 'typedef' )
|
917
|
+
identity_list += grouping_stmt.substmt( 'identity' )
|
918
|
+
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
919
|
+
self.load_yang s, yangs, parent_module, current_module, grouping_list, typedef_list, identity_list
|
920
|
+
}
|
921
|
+
else
|
922
|
+
import_module = yangs.find{ |y|
|
923
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
924
|
+
}
|
925
|
+
grouping_stmt = import_module.substmt( 'grouping' ).find{ |s| s.arg == arg }
|
926
|
+
grouping_list = import_module.substmt( 'grouping' ) + grouping_stmt.substmt( 'grouping' )
|
927
|
+
typedef_list = import_module.substmt( 'typedef' ) + grouping_stmt.substmt( 'typedef' )
|
928
|
+
identity_list = import_module.substmt( 'identity' ) + grouping_stmt.substmt( 'identity' )
|
929
|
+
grouping_stmt.substmts( Rubyang::Model::DataDefStmtList ).each{ |s|
|
930
|
+
self.load_yang s, yangs, parent_module, import_module, grouping_list, typedef_list, identity_list
|
931
|
+
}
|
932
|
+
end
|
933
|
+
else
|
934
|
+
raise
|
935
|
+
end
|
936
|
+
end
|
937
|
+
end
|
938
|
+
def resolve_node path
|
939
|
+
path_splitted = path.split( '/' )
|
940
|
+
next_node = case path_splitted.first
|
941
|
+
when '', '.'
|
942
|
+
self
|
943
|
+
when '..'
|
944
|
+
self
|
945
|
+
when /[^:]+:[^:]+/
|
946
|
+
@children.find{ |c| [c.prefix, c.model.arg].join(':') == path_splitted.first }
|
947
|
+
else
|
948
|
+
@children.find{ |c| c.model.arg == path_splitted.first }
|
949
|
+
end
|
950
|
+
if path_splitted.size == 1
|
951
|
+
next_node
|
952
|
+
else
|
953
|
+
next_node.resolve_node( path_splitted[1..-1].join( '/' ) )
|
954
|
+
end
|
955
|
+
end
|
956
|
+
end
|
1057
957
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
958
|
+
class LeafSchemaNode < SchemaNode
|
959
|
+
attr_reader :yangs, :arg, :yang, :parent, :module, :current_module, :typedef_list, :identity_list
|
960
|
+
def initialize yangs, arg, yang, parent, _module, current_module, typedef_list, identity_list
|
961
|
+
super yangs, arg, yang, parent, _module
|
962
|
+
@type = self.resolve_type yang.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
963
|
+
end
|
1064
964
|
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
965
|
+
def type
|
966
|
+
@type
|
967
|
+
end
|
1068
968
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
969
|
+
def resolve_type type_stmt, yangs, current_module, typedef_list, identity_list
|
970
|
+
case type_stmt.arg
|
971
|
+
when 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'
|
972
|
+
type = IntegerType.new type_stmt.arg
|
973
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
974
|
+
case s
|
975
|
+
when Rubyang::Model::Range
|
976
|
+
type.update_range s.arg
|
977
|
+
else
|
978
|
+
raise ArgumentError, "#{s} is not valid"
|
979
|
+
end
|
980
|
+
}
|
981
|
+
when 'decimal64'
|
982
|
+
type = Decimal64Type.new type_stmt.arg
|
983
|
+
when 'string'
|
984
|
+
type = StringType.new
|
985
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
986
|
+
case s
|
987
|
+
when Rubyang::Model::Length
|
988
|
+
type.update_length s.arg
|
989
|
+
when Rubyang::Model::Pattern
|
990
|
+
type.update_pattern s.arg
|
991
|
+
else
|
992
|
+
raise ArgumentError, "#{s} is not valid"
|
993
|
+
end
|
994
|
+
}
|
995
|
+
when 'boolean'
|
996
|
+
type = BooleanType.new
|
997
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
998
|
+
raise ArgumentError, "#{s} is not valid"
|
999
|
+
}
|
1000
|
+
when 'enumeration'
|
1001
|
+
type = EnumerationType.new
|
1002
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1003
|
+
case s
|
1004
|
+
when Rubyang::Model::Enum
|
1005
|
+
type.update_enum s.arg
|
1006
|
+
else
|
1007
|
+
raise ArgumentError, "#{s} is not valid"
|
1008
|
+
end
|
1009
|
+
}
|
1010
|
+
when 'bits'
|
1011
|
+
type = BitsType.new
|
1012
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1013
|
+
case s
|
1014
|
+
when Rubyang::Model::Bit
|
1015
|
+
type.update_bit s.arg
|
1016
|
+
else
|
1017
|
+
raise ArgumentError, "#{s} is not valid"
|
1018
|
+
end
|
1019
|
+
}
|
1020
|
+
when 'binary'
|
1021
|
+
type = BinaryType.new
|
1022
|
+
type_stmt.substmts( Rubyang::Model::TypeBodyStmtList ).each{ |s|
|
1023
|
+
case s
|
1024
|
+
when Rubyang::Model::Length
|
1025
|
+
type.update_length s.arg
|
1026
|
+
else
|
1027
|
+
raise ArgumentError, "#{s} is not valid"
|
1028
|
+
end
|
1029
|
+
}
|
1030
|
+
when 'leafref'
|
1031
|
+
type = LeafrefType.new self, type_stmt.substmt( 'path' )[0].arg
|
1032
|
+
when 'empty'
|
1033
|
+
type = EmptyType.new
|
1034
|
+
when 'union'
|
1035
|
+
type = UnionType.new
|
1036
|
+
type_stmt.substmt( "type" ).each{ |s|
|
1037
|
+
type.add_type( resolve_type s, yangs, current_module, typedef_list, identity_list )
|
1038
|
+
}
|
1039
|
+
when 'identityref'
|
1040
|
+
type = Identityref.new identity_list, type_stmt
|
1041
|
+
else
|
1042
|
+
case type_stmt.arg
|
1043
|
+
when /^[^:]+$/
|
1044
|
+
arg = type_stmt.arg
|
1045
|
+
if typedef_list.find{ |s| s.arg == arg }
|
1046
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1047
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1048
|
+
else
|
1049
|
+
include_submodule = current_module.substmt( 'include' ).map{ |s|
|
1050
|
+
yangs.find{ |y| y.arg == s.arg }
|
1051
|
+
}.find{ |s|
|
1052
|
+
s.substmt( 'typedef' ).find{ |t| t.arg == arg }
|
1053
|
+
}
|
1054
|
+
typedef_stmt = include_submodule.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1055
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, include_submodule, include_submodule.substmt( 'typedef' ), include_submodule.substmt( 'identity' )
|
1056
|
+
end
|
1057
|
+
when /^[^:]+:[^:]+$/
|
1058
|
+
prefix, arg = type_stmt.arg.split(':')
|
1059
|
+
case current_module
|
1060
|
+
when Rubyang::Model::Module
|
1061
|
+
case prefix
|
1062
|
+
when current_module.substmt( 'prefix' )[0].arg
|
1063
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1064
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1065
|
+
else
|
1066
|
+
import_module = yangs.find{ |y|
|
1067
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
1068
|
+
}
|
1069
|
+
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1070
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' ), import_module.substmt( 'identity' )
|
1071
|
+
end
|
1072
|
+
when Rubyang::Model::Submodule
|
1073
|
+
case prefix
|
1074
|
+
when current_module.substmt( 'belongs-to' )[0].substmt( 'prefix' )[0].arg
|
1075
|
+
typedef_stmt = typedef_list.find{ |s| s.arg == arg }
|
1076
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, current_module, typedef_list, identity_list
|
1077
|
+
else
|
1078
|
+
import_module = yangs.find{ |y|
|
1079
|
+
y.arg == current_module.substmt( 'import' ).find{ |s| s.substmt( 'prefix' )[0].arg == prefix }.arg
|
1080
|
+
}
|
1081
|
+
typedef_stmt = import_module.substmt( 'typedef' ).find{ |s| s.arg == arg }
|
1082
|
+
type = resolve_type typedef_stmt.substmt( 'type' )[0], yangs, import_module, import_module.substmt( 'typedef' ), import_module.substmt( 'identity' )
|
1083
|
+
end
|
1084
|
+
else
|
1085
|
+
raise
|
1086
|
+
end
|
1087
|
+
end
|
1088
|
+
end
|
1089
|
+
type
|
1090
|
+
end
|
1091
|
+
end
|
1192
1092
|
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1093
|
+
class Root < InteriorSchemaNode
|
1094
|
+
def initialize yangs, arg=nil, yang=nil, parent=nil, _module=nil
|
1095
|
+
super
|
1096
|
+
end
|
1097
|
+
def namespace
|
1098
|
+
'http://rubyang/0.1'
|
1099
|
+
end
|
1100
|
+
def prefix
|
1101
|
+
''
|
1102
|
+
end
|
1103
|
+
def to_json_recursive h
|
1104
|
+
@children.each{ |c|
|
1105
|
+
c.to_json_recursive h
|
1106
|
+
}
|
1107
|
+
h
|
1108
|
+
end
|
1109
|
+
end
|
1210
1110
|
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1111
|
+
class Anyxml < SchemaNode
|
1112
|
+
def initialize *args
|
1113
|
+
super
|
1114
|
+
@logger = Logger.new(self.class.name)
|
1115
|
+
end
|
1116
|
+
end
|
1217
1117
|
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1118
|
+
class Container < InteriorSchemaNode
|
1119
|
+
attr_accessor :whens, :musts
|
1120
|
+
def initialize *args
|
1121
|
+
super
|
1122
|
+
@whens = []
|
1123
|
+
@musts = []
|
1124
|
+
end
|
1125
|
+
def to_json_recursive h
|
1126
|
+
h['type'] = 'container'
|
1127
|
+
h['arg'] = @arg
|
1128
|
+
h['children'] = Hash.new
|
1129
|
+
@children.each{ |c|
|
1130
|
+
c.to_json_recursive h['children']
|
1131
|
+
}
|
1132
|
+
h
|
1133
|
+
end
|
1134
|
+
end
|
1235
1135
|
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1136
|
+
class Leaf < LeafSchemaNode
|
1137
|
+
def to_json_recursive h
|
1138
|
+
h['type'] = 'leaf'
|
1139
|
+
h['arg'] = @arg
|
1140
|
+
case @type
|
1141
|
+
when Rubyang::Database::SchemaTree::StringType
|
1142
|
+
h['datatype'] = 'string'
|
1143
|
+
h['parameters'] = Hash.new
|
1144
|
+
h['parameters']['length'] = @type.length.to_s
|
1145
|
+
h['parameters']['pattern'] = @type.pattern.to_s
|
1146
|
+
else
|
1147
|
+
raise
|
1148
|
+
end
|
1149
|
+
h
|
1150
|
+
end
|
1151
|
+
end
|
1252
1152
|
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1153
|
+
class List < InteriorSchemaNode
|
1154
|
+
# min-elements start
|
1155
|
+
# max-elements start
|
1156
|
+
attr_reader :min_elements, :max_elements
|
1157
|
+
def initialize *args
|
1158
|
+
super
|
1159
|
+
@min_elements = []
|
1160
|
+
@max_elements = []
|
1161
|
+
end
|
1162
|
+
# end
|
1163
|
+
# end
|
1264
1164
|
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1165
|
+
def keys
|
1166
|
+
@yang.substmt( 'key' )[0].arg.split( /[ \t]+/ )
|
1167
|
+
end
|
1168
|
+
end
|
1269
1169
|
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1170
|
+
class LeafList < LeafSchemaNode
|
1171
|
+
# min-elements start
|
1172
|
+
# max-elements start
|
1173
|
+
attr_reader :min_elements, :max_elements
|
1174
|
+
def initialize *args
|
1175
|
+
super
|
1176
|
+
@min_elements = []
|
1177
|
+
@max_elements = []
|
1178
|
+
end
|
1179
|
+
# end
|
1180
|
+
# end
|
1181
|
+
end
|
1282
1182
|
|
1283
|
-
|
1284
|
-
|
1183
|
+
class Choice < InteriorSchemaNode
|
1184
|
+
end
|
1285
1185
|
|
1286
|
-
|
1287
|
-
|
1186
|
+
class Case < InteriorSchemaNode
|
1187
|
+
end
|
1288
1188
|
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1189
|
+
class Rpc < SchemaNode
|
1190
|
+
end
|
1191
|
+
class Input < SchemaNode
|
1192
|
+
end
|
1193
|
+
class Output < SchemaNode
|
1194
|
+
end
|
1195
|
+
class Notification < SchemaNode
|
1196
|
+
end
|
1297
1197
|
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1198
|
+
def initialize yangs
|
1199
|
+
@yangs = yangs
|
1200
|
+
@root = Root.new @yangs
|
1201
|
+
end
|
1202
|
+
def to_s parent=true
|
1203
|
+
head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">"
|
1204
|
+
if parent
|
1205
|
+
vars.push "@yangs=#{@yangs.to_s}"
|
1206
|
+
vars.push "@root=#{@root.to_s( false )}"
|
1207
|
+
end
|
1208
|
+
head + vars.join(', ') + tail
|
1209
|
+
end
|
1210
|
+
def root
|
1211
|
+
@root
|
1212
|
+
end
|
1213
|
+
def load model
|
1214
|
+
@root.load_yang( model )
|
1215
|
+
end
|
1216
|
+
end
|
1217
|
+
end
|
1318
1218
|
end
|
1319
1219
|
|
1320
1220
|
if __FILE__ == $0
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1221
|
+
require_relative '../../rubyang'
|
1222
|
+
yang_str =<<-EOB
|
1223
|
+
module module1 {
|
1224
|
+
namespace "http://module1.rspec/";
|
1225
|
+
prefix module1;
|
1226
|
+
container container1 {
|
1227
|
+
leaf leaf1 {
|
1228
|
+
type string {
|
1229
|
+
length 0..10;
|
1230
|
+
pattern '[0-9]+';
|
1231
|
+
}
|
1232
|
+
}
|
1233
|
+
}
|
1234
|
+
}
|
1235
|
+
EOB
|
1236
|
+
db = Rubyang::Database.new
|
1237
|
+
db.load_model Rubyang::Model::Parser.parse( yang_str )
|
1238
|
+
@logger.debug { db.configure.schema.to_json }
|
1339
1239
|
end
|