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