Line | |
---|
1 | # WSDL4R - XMLSchema simpleType definition for WSDL.
|
---|
2 | # Copyright (C) 2004, 2005 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 |
|
---|
9 | require 'wsdl/info'
|
---|
10 | require 'xsd/namedelements'
|
---|
11 |
|
---|
12 |
|
---|
13 | module WSDL
|
---|
14 | module XMLSchema
|
---|
15 |
|
---|
16 |
|
---|
17 | class SimpleType < Info
|
---|
18 | attr_accessor :name
|
---|
19 | attr_reader :restriction
|
---|
20 |
|
---|
21 | def check_lexical_format(value)
|
---|
22 | if @restriction
|
---|
23 | check_restriction(value)
|
---|
24 | else
|
---|
25 | raise ArgumentError.new("incomplete simpleType")
|
---|
26 | end
|
---|
27 | end
|
---|
28 |
|
---|
29 | def base
|
---|
30 | if @restriction
|
---|
31 | @restriction.base
|
---|
32 | else
|
---|
33 | raise ArgumentError.new("incomplete simpleType")
|
---|
34 | end
|
---|
35 | end
|
---|
36 |
|
---|
37 | def initialize(name = nil)
|
---|
38 | super()
|
---|
39 | @name = name
|
---|
40 | @restriction = nil
|
---|
41 | end
|
---|
42 |
|
---|
43 | def targetnamespace
|
---|
44 | parent.targetnamespace
|
---|
45 | end
|
---|
46 |
|
---|
47 | def parse_element(element)
|
---|
48 | case element
|
---|
49 | when RestrictionName
|
---|
50 | @restriction = SimpleRestriction.new
|
---|
51 | @restriction
|
---|
52 | end
|
---|
53 | end
|
---|
54 |
|
---|
55 | def parse_attr(attr, value)
|
---|
56 | case attr
|
---|
57 | when NameAttrName
|
---|
58 | @name = XSD::QName.new(targetnamespace, value.source)
|
---|
59 | end
|
---|
60 | end
|
---|
61 |
|
---|
62 | private
|
---|
63 |
|
---|
64 | def check_restriction(value)
|
---|
65 | unless @restriction.valid?(value)
|
---|
66 | raise XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'")
|
---|
67 | end
|
---|
68 | end
|
---|
69 | end
|
---|
70 |
|
---|
71 |
|
---|
72 | end
|
---|
73 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.