source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/wsdl/xmlSchema/simpleRestriction.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.5 KB
Line 
1# WSDL4R - XMLSchema simpleContent restriction definition for WSDL.
2# Copyright (C) 2004 NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'wsdl/info'
10require 'xsd/namedelements'
11
12
13module WSDL
14module XMLSchema
15
16
17class SimpleRestriction < Info
18 attr_reader :base
19 attr_reader :enumeration
20 attr_accessor :length
21 attr_accessor :pattern
22
23 def initialize
24 super
25 @base = nil
26 @enumeration = [] # NamedElements?
27 @length = nil
28 @pattern = nil
29 end
30
31 def valid?(value)
32 return false unless check_restriction(value)
33 return false unless check_length(value)
34 return false unless check_pattern(value)
35 true
36 end
37
38 def parse_element(element)
39 case element
40 when EnumerationName
41 Enumeration.new # just a parsing handler
42 when LengthName
43 Length.new # just a parsing handler
44 when PatternName
45 Pattern.new # just a parsing handler
46 end
47 end
48
49 def parse_attr(attr, value)
50 case attr
51 when BaseAttrName
52 @base = value
53 end
54 end
55
56private
57
58 def check_restriction(value)
59 @enumeration.empty? or @enumeration.include?(value)
60 end
61
62 def check_length(value)
63 @length.nil? or value.size == @length
64 end
65
66 def check_pattern(value)
67 @pattern.nil? or @pattern =~ value
68 end
69end
70
71
72end
73end
Note: See TracBrowser for help on using the repository browser.