soap4r_es 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/wsdl2ruby.rb +140 -0
- data/bin/wsdl2ruby_rails.rb +140 -0
- data/bin/xsd2ruby.rb +92 -0
- data/lib/soap/attachment.rb +109 -0
- data/lib/soap/attrproxy.rb +35 -0
- data/lib/soap/baseData.rb +1095 -0
- data/lib/soap/element.rb +278 -0
- data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
- data/lib/soap/encodingstyle/handler.rb +121 -0
- data/lib/soap/encodingstyle/literalHandler.rb +196 -0
- data/lib/soap/encodingstyle/soapHandler.rb +560 -0
- data/lib/soap/filter/filterchain.rb +52 -0
- data/lib/soap/filter/handler.rb +32 -0
- data/lib/soap/filter/streamhandler.rb +30 -0
- data/lib/soap/filter.rb +14 -0
- data/lib/soap/generator.rb +299 -0
- data/lib/soap/header/handler.rb +64 -0
- data/lib/soap/header/handlerset.rb +78 -0
- data/lib/soap/header/mappinghandler.rb +48 -0
- data/lib/soap/header/simplehandler.rb +45 -0
- data/lib/soap/httpconfigloader.rb +140 -0
- data/lib/soap/mapping/encodedregistry.rb +541 -0
- data/lib/soap/mapping/factory.rb +389 -0
- data/lib/soap/mapping/literalregistry.rb +392 -0
- data/lib/soap/mapping/mapping.rb +577 -0
- data/lib/soap/mapping/registry.rb +297 -0
- data/lib/soap/mapping/rubytypeFactory.rb +446 -0
- data/lib/soap/mapping/schemadefinition.rb +171 -0
- data/lib/soap/mapping/typeMap.rb +107 -0
- data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
- data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
- data/lib/soap/mapping.rb +13 -0
- data/lib/soap/marshal.rb +60 -0
- data/lib/soap/mimemessage.rb +243 -0
- data/lib/soap/nestedexception.rb +43 -0
- data/lib/soap/netHttpClient.rb +242 -0
- data/lib/soap/ns.rb +39 -0
- data/lib/soap/parser.rb +253 -0
- data/lib/soap/processor.rb +67 -0
- data/lib/soap/property.rb +330 -0
- data/lib/soap/proxy.rb +15 -0
- data/lib/soap/rpc/cgistub.rb +249 -0
- data/lib/soap/rpc/driver.rb +222 -0
- data/lib/soap/rpc/element.rb +375 -0
- data/lib/soap/rpc/httpserver.rb +144 -0
- data/lib/soap/rpc/methodDef.rb +69 -0
- data/lib/soap/rpc/proxy.rb +573 -0
- data/lib/soap/rpc/router.rb +672 -0
- data/lib/soap/rpc/rpc.rb +26 -0
- data/lib/soap/rpc/soaplet.rb +201 -0
- data/lib/soap/rpc/standaloneServer.rb +44 -0
- data/lib/soap/soap.rb +163 -0
- data/lib/soap/streamHandler.rb +302 -0
- data/lib/soap/version.rb +12 -0
- data/lib/soap/wsdlDriver.rb +165 -0
- data/lib/wsdl/binding.rb +66 -0
- data/lib/wsdl/data.rb +65 -0
- data/lib/wsdl/definitions.rb +237 -0
- data/lib/wsdl/documentation.rb +33 -0
- data/lib/wsdl/import.rb +81 -0
- data/lib/wsdl/importer.rb +39 -0
- data/lib/wsdl/info.rb +51 -0
- data/lib/wsdl/message.rb +55 -0
- data/lib/wsdl/operation.rb +152 -0
- data/lib/wsdl/operationBinding.rb +241 -0
- data/lib/wsdl/param.rb +94 -0
- data/lib/wsdl/parser.rb +180 -0
- data/lib/wsdl/part.rb +53 -0
- data/lib/wsdl/port.rb +67 -0
- data/lib/wsdl/portType.rb +76 -0
- data/lib/wsdl/service.rb +62 -0
- data/lib/wsdl/soap/address.rb +41 -0
- data/lib/wsdl/soap/binding.rb +50 -0
- data/lib/wsdl/soap/body.rb +59 -0
- data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
- data/lib/wsdl/soap/classDefCreator.rb +529 -0
- data/lib/wsdl/soap/classDefCreatorSupport.rb +242 -0
- data/lib/wsdl/soap/classNameCreator.rb +57 -0
- data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
- data/lib/wsdl/soap/complexType.rb +174 -0
- data/lib/wsdl/soap/data.rb +43 -0
- data/lib/wsdl/soap/definitions.rb +201 -0
- data/lib/wsdl/soap/driverCreator.rb +121 -0
- data/lib/wsdl/soap/element.rb +34 -0
- data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
- data/lib/wsdl/soap/fault.rb +57 -0
- data/lib/wsdl/soap/header.rb +87 -0
- data/lib/wsdl/soap/headerfault.rb +57 -0
- data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
- data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
- data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +380 -0
- data/lib/wsdl/soap/methodDefCreator.rb +200 -0
- data/lib/wsdl/soap/operation.rb +113 -0
- data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
- data/lib/wsdl/soap/servletStubCreator.rb +105 -0
- data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
- data/lib/wsdl/soap/wsdl2ruby.rb +249 -0
- data/lib/wsdl/types.rb +45 -0
- data/lib/wsdl/wsdl.rb +25 -0
- data/lib/wsdl/xmlSchema/all.rb +25 -0
- data/lib/wsdl/xmlSchema/annotation.rb +35 -0
- data/lib/wsdl/xmlSchema/any.rb +62 -0
- data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
- data/lib/wsdl/xmlSchema/attribute.rb +105 -0
- data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
- data/lib/wsdl/xmlSchema/choice.rb +59 -0
- data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
- data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
- data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
- data/lib/wsdl/xmlSchema/complexType.rb +194 -0
- data/lib/wsdl/xmlSchema/content.rb +96 -0
- data/lib/wsdl/xmlSchema/data.rb +117 -0
- data/lib/wsdl/xmlSchema/element.rb +154 -0
- data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
- data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
- data/lib/wsdl/xmlSchema/group.rb +101 -0
- data/lib/wsdl/xmlSchema/import.rb +53 -0
- data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
- data/lib/wsdl/xmlSchema/importer.rb +103 -0
- data/lib/wsdl/xmlSchema/include.rb +48 -0
- data/lib/wsdl/xmlSchema/length.rb +38 -0
- data/lib/wsdl/xmlSchema/list.rb +49 -0
- data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
- data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/minlength.rb +38 -0
- data/lib/wsdl/xmlSchema/parser.rb +168 -0
- data/lib/wsdl/xmlSchema/pattern.rb +37 -0
- data/lib/wsdl/xmlSchema/ref.rb +34 -0
- data/lib/wsdl/xmlSchema/schema.rb +179 -0
- data/lib/wsdl/xmlSchema/sequence.rb +55 -0
- data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
- data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
- data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
- data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
- data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
- data/lib/wsdl/xmlSchema/union.rb +36 -0
- data/lib/wsdl/xmlSchema/unique.rb +35 -0
- data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
- data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
- data/lib/xsd/charset.rb +190 -0
- data/lib/xsd/codegen/classdef.rb +230 -0
- data/lib/xsd/codegen/commentdef.rb +35 -0
- data/lib/xsd/codegen/gensupport.rb +277 -0
- data/lib/xsd/codegen/methoddef.rb +71 -0
- data/lib/xsd/codegen/moduledef.rb +209 -0
- data/lib/xsd/codegen.rb +13 -0
- data/lib/xsd/datatypes.rb +1465 -0
- data/lib/xsd/datatypes1999.rb +21 -0
- data/lib/xsd/iconvcharset.rb +33 -0
- data/lib/xsd/mapping.rb +69 -0
- data/lib/xsd/namedelements.rb +133 -0
- data/lib/xsd/ns.rb +183 -0
- data/lib/xsd/qname.rb +80 -0
- data/lib/xsd/xmlparser/libxmlparser.rb +136 -0
- data/lib/xsd/xmlparser/nokogiriparser.rb +63 -0
- data/lib/xsd/xmlparser/ogaparser.rb +53 -0
- data/lib/xsd/xmlparser/oxparser.rb +97 -0
- data/lib/xsd/xmlparser/parser.rb +101 -0
- data/lib/xsd/xmlparser/rexmlparser.rb +54 -0
- data/lib/xsd/xmlparser.rb +81 -0
- metadata +240 -0
@@ -0,0 +1,1465 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# XSD4R - XML Schema Datatype implementation.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/qname'
|
11
|
+
require 'xsd/charset'
|
12
|
+
require 'soap/nestedexception'
|
13
|
+
require 'uri'
|
14
|
+
|
15
|
+
###
|
16
|
+
## XMLSchamaDatatypes general definitions.
|
17
|
+
#
|
18
|
+
module XSD
|
19
|
+
|
20
|
+
|
21
|
+
Namespace = 'http://www.w3.org/2001/XMLSchema'
|
22
|
+
InstanceNamespace = 'http://www.w3.org/2001/XMLSchema-instance'
|
23
|
+
|
24
|
+
AttrType = 'type'
|
25
|
+
NilValue = 'true'
|
26
|
+
|
27
|
+
AnyTypeLiteral = 'anyType'
|
28
|
+
AnySimpleTypeLiteral = 'anySimpleType'
|
29
|
+
NilLiteral = 'nil'
|
30
|
+
StringLiteral = 'string'
|
31
|
+
BooleanLiteral = 'boolean'
|
32
|
+
DecimalLiteral = 'decimal'
|
33
|
+
FloatLiteral = 'float'
|
34
|
+
DoubleLiteral = 'double'
|
35
|
+
DurationLiteral = 'duration'
|
36
|
+
DateTimeLiteral = 'dateTime'
|
37
|
+
TimeLiteral = 'time'
|
38
|
+
DateLiteral = 'date'
|
39
|
+
GYearMonthLiteral = 'gYearMonth'
|
40
|
+
GYearLiteral = 'gYear'
|
41
|
+
GMonthDayLiteral = 'gMonthDay'
|
42
|
+
GDayLiteral = 'gDay'
|
43
|
+
GMonthLiteral = 'gMonth'
|
44
|
+
HexBinaryLiteral = 'hexBinary'
|
45
|
+
Base64BinaryLiteral = 'base64Binary'
|
46
|
+
AnyURILiteral = 'anyURI'
|
47
|
+
QNameLiteral = 'QName'
|
48
|
+
|
49
|
+
NormalizedStringLiteral = 'normalizedString'
|
50
|
+
TokenLiteral = 'token'
|
51
|
+
LanguageLiteral = 'language'
|
52
|
+
NMTOKENLiteral = 'NMTOKEN'
|
53
|
+
NMTOKENSLiteral = 'NMTOKENS'
|
54
|
+
NameLiteral = 'Name'
|
55
|
+
NCNameLiteral = 'NCName'
|
56
|
+
IDLiteral = 'ID'
|
57
|
+
IDREFLiteral = 'IDREF'
|
58
|
+
IDREFSLiteral = 'IDREFS'
|
59
|
+
ENTITYLiteral = 'ENTITY'
|
60
|
+
ENTITIESLiteral = 'ENTITIES'
|
61
|
+
IntegerLiteral = 'integer'
|
62
|
+
NonPositiveIntegerLiteral = 'nonPositiveInteger'
|
63
|
+
NegativeIntegerLiteral = 'negativeInteger'
|
64
|
+
LongLiteral = 'long'
|
65
|
+
IntLiteral = 'int'
|
66
|
+
ShortLiteral = 'short'
|
67
|
+
ByteLiteral = 'byte'
|
68
|
+
NonNegativeIntegerLiteral = 'nonNegativeInteger'
|
69
|
+
UnsignedLongLiteral = 'unsignedLong'
|
70
|
+
UnsignedIntLiteral = 'unsignedInt'
|
71
|
+
UnsignedShortLiteral = 'unsignedShort'
|
72
|
+
UnsignedByteLiteral = 'unsignedByte'
|
73
|
+
PositiveIntegerLiteral = 'positiveInteger'
|
74
|
+
|
75
|
+
AttrTypeName = QName.new(InstanceNamespace, AttrType)
|
76
|
+
AttrNilName = QName.new(InstanceNamespace, NilLiteral)
|
77
|
+
|
78
|
+
AnyTypeName = QName.new(Namespace, AnyTypeLiteral)
|
79
|
+
AnySimpleTypeName = QName.new(Namespace, AnySimpleTypeLiteral)
|
80
|
+
|
81
|
+
class Error < StandardError; include ::SOAP::NestedException; end
|
82
|
+
class ValueSpaceError < Error; end
|
83
|
+
|
84
|
+
|
85
|
+
###
|
86
|
+
## The base class of all datatypes with Namespace.
|
87
|
+
#
|
88
|
+
class NSDBase
|
89
|
+
@@types = []
|
90
|
+
|
91
|
+
attr_accessor :type
|
92
|
+
|
93
|
+
def self.inherited(klass)
|
94
|
+
@@types << klass
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.types
|
98
|
+
@@types
|
99
|
+
end
|
100
|
+
|
101
|
+
def initialize
|
102
|
+
end
|
103
|
+
|
104
|
+
def init(type)
|
105
|
+
@type = type
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
###
|
111
|
+
## The base class of XSD datatypes.
|
112
|
+
#
|
113
|
+
class XSDAnySimpleType < NSDBase
|
114
|
+
include XSD
|
115
|
+
Type = QName.new(Namespace, AnySimpleTypeLiteral)
|
116
|
+
|
117
|
+
# @data represents canonical space (ex. Integer: 123).
|
118
|
+
attr_reader :data
|
119
|
+
# @is_nil represents this data is nil or not.
|
120
|
+
attr_accessor :is_nil
|
121
|
+
|
122
|
+
def initialize(value = nil)
|
123
|
+
init(Type, value)
|
124
|
+
end
|
125
|
+
|
126
|
+
# true or raise
|
127
|
+
def check_lexical_format(value)
|
128
|
+
screen_data(value)
|
129
|
+
true
|
130
|
+
end
|
131
|
+
|
132
|
+
# set accepts a string which follows lexical space (ex. String: "+123"), or
|
133
|
+
# an object which follows canonical space (ex. Integer: 123).
|
134
|
+
def set(value)
|
135
|
+
if value.nil?
|
136
|
+
@is_nil = true
|
137
|
+
@data = nil
|
138
|
+
_set(nil)
|
139
|
+
else
|
140
|
+
@is_nil = false
|
141
|
+
_set(screen_data(value))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# to_s creates a string which follows lexical space (ex. String: "123").
|
146
|
+
def to_s()
|
147
|
+
if @is_nil
|
148
|
+
""
|
149
|
+
else
|
150
|
+
_to_s
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def init(type, value)
|
157
|
+
super(type)
|
158
|
+
set(value)
|
159
|
+
end
|
160
|
+
|
161
|
+
# raises ValueSpaceError if check failed
|
162
|
+
def screen_data(value)
|
163
|
+
value
|
164
|
+
end
|
165
|
+
|
166
|
+
def _set(value)
|
167
|
+
@data = value
|
168
|
+
end
|
169
|
+
|
170
|
+
def _to_s
|
171
|
+
@data.to_s
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class XSDNil < XSDAnySimpleType
|
176
|
+
Type = QName.new(Namespace, NilLiteral)
|
177
|
+
Value = 'true'
|
178
|
+
|
179
|
+
def initialize(value = nil)
|
180
|
+
init(Type, value)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
###
|
186
|
+
## Primitive datatypes.
|
187
|
+
#
|
188
|
+
class XSDString < XSDAnySimpleType
|
189
|
+
Type = QName.new(Namespace, StringLiteral)
|
190
|
+
|
191
|
+
def initialize(value = nil)
|
192
|
+
init(Type, value)
|
193
|
+
end
|
194
|
+
|
195
|
+
@@strict_ces_validation = false
|
196
|
+
|
197
|
+
def self.strict_ces_validation=(strict_ces_validation)
|
198
|
+
@@strict_ces_validation = strict_ces_validation
|
199
|
+
end
|
200
|
+
|
201
|
+
def self.strict_ces_validation
|
202
|
+
@@strict_ces_validation
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
def screen_data(value)
|
208
|
+
if ::XSD::XSDString.strict_ces_validation
|
209
|
+
externalces = XSD::Charset.encoding
|
210
|
+
unless XSD::Charset.is_ces(value, externalces)
|
211
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
value
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class XSDBoolean < XSDAnySimpleType
|
219
|
+
Type = QName.new(Namespace, BooleanLiteral)
|
220
|
+
|
221
|
+
def initialize(value = nil)
|
222
|
+
init(Type, value)
|
223
|
+
end
|
224
|
+
|
225
|
+
private
|
226
|
+
|
227
|
+
def screen_data(value)
|
228
|
+
if value.is_a?(String)
|
229
|
+
str = value.strip
|
230
|
+
if str == 'true' || str == '1'
|
231
|
+
true
|
232
|
+
elsif str == 'false' || str == '0'
|
233
|
+
false
|
234
|
+
else
|
235
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
|
236
|
+
end
|
237
|
+
else
|
238
|
+
value ? true : false
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class XSDDecimal < XSDAnySimpleType
|
244
|
+
Type = QName.new(Namespace, DecimalLiteral)
|
245
|
+
|
246
|
+
def initialize(value = nil)
|
247
|
+
init(Type, value)
|
248
|
+
end
|
249
|
+
|
250
|
+
def nonzero?
|
251
|
+
(@number != '0')
|
252
|
+
end
|
253
|
+
|
254
|
+
private
|
255
|
+
|
256
|
+
def screen_data(d)
|
257
|
+
if d.is_a?(String)
|
258
|
+
# Integer("00012") => 10 in Ruby.
|
259
|
+
d.sub!(/^([+\-]?)0*(?=\d)/, "\\1")
|
260
|
+
end
|
261
|
+
screen_data_str(d)
|
262
|
+
end
|
263
|
+
|
264
|
+
def screen_data_str(str)
|
265
|
+
/^([+\-]?)(\d*)(?:\.(\d*)?)?$/ =~ str.to_s.strip
|
266
|
+
unless Regexp.last_match
|
267
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
|
268
|
+
end
|
269
|
+
sign = $1 || '+'
|
270
|
+
int_part = $2
|
271
|
+
frac_part = $3
|
272
|
+
int_part = '0' if int_part.empty?
|
273
|
+
frac_part = frac_part ? frac_part.sub(/0+$/, '') : ''
|
274
|
+
point = - frac_part.size
|
275
|
+
number = int_part + frac_part
|
276
|
+
# normalize
|
277
|
+
if sign == '+'
|
278
|
+
sign = ''
|
279
|
+
elsif sign == '-'
|
280
|
+
if number == '0'
|
281
|
+
sign = ''
|
282
|
+
end
|
283
|
+
end
|
284
|
+
[sign, point, number]
|
285
|
+
end
|
286
|
+
|
287
|
+
def _set(data)
|
288
|
+
if data.nil?
|
289
|
+
@sign = @point = @number = @data = nil
|
290
|
+
return
|
291
|
+
end
|
292
|
+
@sign, @point, @number = data
|
293
|
+
@data = _to_s
|
294
|
+
@data.freeze
|
295
|
+
end
|
296
|
+
|
297
|
+
# 0.0 -> 0; right?
|
298
|
+
def _to_s
|
299
|
+
str = @number.dup
|
300
|
+
if @point.nonzero?
|
301
|
+
str[@number.size + @point, 0] = '.'
|
302
|
+
end
|
303
|
+
@sign + str
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
module FloatConstants
|
308
|
+
NaN = 0.0/0.0
|
309
|
+
POSITIVE_INF = +1.0/0.0
|
310
|
+
NEGATIVE_INF = -1.0/0.0
|
311
|
+
POSITIVE_ZERO = +1.0/POSITIVE_INF
|
312
|
+
NEGATIVE_ZERO = -1.0/POSITIVE_INF
|
313
|
+
MIN_POSITIVE_SINGLE = 2.0 ** -149
|
314
|
+
end
|
315
|
+
|
316
|
+
class XSDFloat < XSDAnySimpleType
|
317
|
+
include FloatConstants
|
318
|
+
Type = QName.new(Namespace, FloatLiteral)
|
319
|
+
|
320
|
+
def initialize(value = nil)
|
321
|
+
init(Type, value)
|
322
|
+
end
|
323
|
+
|
324
|
+
private
|
325
|
+
|
326
|
+
def screen_data(value)
|
327
|
+
# "NaN".to_f => 0 in some environment. libc?
|
328
|
+
if value.is_a?(Float)
|
329
|
+
return narrow32bit(value)
|
330
|
+
end
|
331
|
+
str = value.to_s.strip
|
332
|
+
if str == 'NaN'
|
333
|
+
NaN
|
334
|
+
elsif str == 'INF'
|
335
|
+
POSITIVE_INF
|
336
|
+
elsif str == '-INF'
|
337
|
+
NEGATIVE_INF
|
338
|
+
else
|
339
|
+
if /^[+\-\.\deE]+$/ !~ str
|
340
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
|
341
|
+
end
|
342
|
+
# Float("-1.4E") might fail on some system.
|
343
|
+
str << '0' if /e$/i =~ str
|
344
|
+
begin
|
345
|
+
return narrow32bit(Float(str))
|
346
|
+
rescue ArgumentError
|
347
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def _to_s
|
353
|
+
if @data.nan?
|
354
|
+
'NaN'
|
355
|
+
elsif @data.infinite? == 1
|
356
|
+
'INF'
|
357
|
+
elsif @data.infinite? == -1
|
358
|
+
'-INF'
|
359
|
+
else
|
360
|
+
sign = XSDFloat.positive?(@data) ? '+' : '-'
|
361
|
+
sign + sprintf("%.10g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 }
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
# Convert to single-precision 32-bit floating point value.
|
366
|
+
def narrow32bit(f)
|
367
|
+
if f.nan? || f.infinite?
|
368
|
+
f
|
369
|
+
elsif f.abs < MIN_POSITIVE_SINGLE
|
370
|
+
XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO
|
371
|
+
else
|
372
|
+
f
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def self.positive?(value)
|
377
|
+
(1 / value) > 0.0
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
# Ruby's Float is double-precision 64-bit floating point value.
|
382
|
+
class XSDDouble < XSDAnySimpleType
|
383
|
+
include FloatConstants
|
384
|
+
Type = QName.new(Namespace, DoubleLiteral)
|
385
|
+
|
386
|
+
def initialize(value = nil)
|
387
|
+
init(Type, value)
|
388
|
+
end
|
389
|
+
|
390
|
+
private
|
391
|
+
|
392
|
+
def screen_data(value)
|
393
|
+
# "NaN".to_f => 0 in some environment. libc?
|
394
|
+
if value.is_a?(Float)
|
395
|
+
return value
|
396
|
+
end
|
397
|
+
str = value.to_s.strip
|
398
|
+
if str == 'NaN'
|
399
|
+
NaN
|
400
|
+
elsif str == 'INF'
|
401
|
+
POSITIVE_INF
|
402
|
+
elsif str == '-INF'
|
403
|
+
NEGATIVE_INF
|
404
|
+
else
|
405
|
+
begin
|
406
|
+
return Float(str)
|
407
|
+
rescue ArgumentError
|
408
|
+
# '1.4e' cannot be parsed on some architecture.
|
409
|
+
if /e\z/i =~ str
|
410
|
+
begin
|
411
|
+
return Float(str + '0')
|
412
|
+
rescue ArgumentError
|
413
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!)
|
414
|
+
end
|
415
|
+
else
|
416
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def _to_s
|
423
|
+
if @data.nan?
|
424
|
+
'NaN'
|
425
|
+
elsif @data.infinite? == 1
|
426
|
+
'INF'
|
427
|
+
elsif @data.infinite? == -1
|
428
|
+
'-INF'
|
429
|
+
else
|
430
|
+
sign = (1 / @data > 0.0) ? '+' : '-'
|
431
|
+
sign + sprintf("%.16g", @data.abs).sub(/[eE]([+-])?0+/) { 'e' + $1 }
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
class XSDDuration < XSDAnySimpleType
|
437
|
+
Type = QName.new(Namespace, DurationLiteral)
|
438
|
+
|
439
|
+
attr_accessor :sign
|
440
|
+
attr_accessor :year
|
441
|
+
attr_accessor :month
|
442
|
+
attr_accessor :day
|
443
|
+
attr_accessor :hour
|
444
|
+
attr_accessor :min
|
445
|
+
attr_accessor :sec
|
446
|
+
|
447
|
+
def initialize(value = nil)
|
448
|
+
init(Type, value)
|
449
|
+
end
|
450
|
+
|
451
|
+
private
|
452
|
+
|
453
|
+
def screen_data(value)
|
454
|
+
/^([+\-]?)P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/ =~ value.to_s.strip
|
455
|
+
unless Regexp.last_match
|
456
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
457
|
+
end
|
458
|
+
if $5 and !$6 and !$7 and !$8
|
459
|
+
# allows durations lower than a day such as 'PT5S'.
|
460
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
461
|
+
end
|
462
|
+
sign = $1
|
463
|
+
year = $2.to_i
|
464
|
+
month = $3.to_i
|
465
|
+
day = $4.to_i
|
466
|
+
hour = $6.to_i
|
467
|
+
min = $7.to_i
|
468
|
+
sec = $8 ? XSDDecimal.new($8) : 0
|
469
|
+
[sign, year, month, day, hour, min, sec]
|
470
|
+
end
|
471
|
+
|
472
|
+
def _set(data)
|
473
|
+
if data.nil?
|
474
|
+
@sign = @year = @month = @day = @hour = @min = @sec = @data = nil
|
475
|
+
return
|
476
|
+
end
|
477
|
+
@sign, @year, @month, @day, @hour, @min, @sec = data
|
478
|
+
@data = _to_s
|
479
|
+
@data.freeze
|
480
|
+
end
|
481
|
+
|
482
|
+
def _to_s
|
483
|
+
str = ''
|
484
|
+
str << @sign if @sign
|
485
|
+
str << 'P'
|
486
|
+
l = ''
|
487
|
+
l << "#{ @year }Y" if @year.nonzero?
|
488
|
+
l << "#{ @month }M" if @month.nonzero?
|
489
|
+
l << "#{ @day }D" if @day.nonzero?
|
490
|
+
r = ''
|
491
|
+
r << "#{ @hour }H" if @hour.nonzero?
|
492
|
+
r << "#{ @min }M" if @min.nonzero?
|
493
|
+
r << "#{ @sec }S" if @sec.nonzero?
|
494
|
+
str << l
|
495
|
+
unless r.empty?
|
496
|
+
str << "T" << r
|
497
|
+
end
|
498
|
+
if l.empty? and r.empty?
|
499
|
+
str << "0D"
|
500
|
+
end
|
501
|
+
str
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
|
506
|
+
require 'date'
|
507
|
+
|
508
|
+
module XSDDateTimeImpl
|
509
|
+
SecInMicro = 1000000 # 1 second = 1 million microseconds
|
510
|
+
DayInSec = 86400 # 24 Hours/Day * 60 Minutes/Hour * 60 Seconds/Minute
|
511
|
+
DayInMicro = (DayInSec * SecInMicro)
|
512
|
+
|
513
|
+
def to_obj(klass)
|
514
|
+
if klass == Time
|
515
|
+
to_time
|
516
|
+
elsif klass == Date
|
517
|
+
to_date
|
518
|
+
elsif klass == DateTime
|
519
|
+
to_datetime
|
520
|
+
else
|
521
|
+
nil
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
def to_time
|
526
|
+
begin
|
527
|
+
if @data.offset * DayInSec == Time.now.utc_offset
|
528
|
+
d = @data
|
529
|
+
usec = (RUBY_VERSION.to_f >= 1.9) ? (d.sec_fraction * SecInMicro).to_i : (d.sec_fraction * DayInMicro).round
|
530
|
+
Time.local(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
|
531
|
+
else
|
532
|
+
d = @data.newof
|
533
|
+
usec = (RUBY_VERSION.to_f >= 1.9) ? (d.sec_fraction * SecInMicro).to_i : (d.sec_fraction * DayInMicro).round
|
534
|
+
Time.gm(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
|
535
|
+
end
|
536
|
+
rescue ArgumentError
|
537
|
+
nil
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
def to_date
|
542
|
+
@data.respond_to?(:to_date) ? @data.to_date : Date.new!(@data.class.send(:jd_to_ajd, @data.jd, 0, 0), 0, @data.start)
|
543
|
+
end
|
544
|
+
|
545
|
+
def to_datetime
|
546
|
+
data
|
547
|
+
end
|
548
|
+
|
549
|
+
def tz2of(str)
|
550
|
+
/^(?:Z|(?:([+\-])(\d\d):(\d\d))?)$/ =~ str
|
551
|
+
sign = $1
|
552
|
+
hour = $2.to_i
|
553
|
+
min = $3.to_i
|
554
|
+
|
555
|
+
of = case sign
|
556
|
+
when '+'
|
557
|
+
of = +(hour.to_r * 60 + min) / 1440 # 24 * 60
|
558
|
+
when '-'
|
559
|
+
of = -(hour.to_r * 60 + min) / 1440 # 24 * 60
|
560
|
+
else
|
561
|
+
0
|
562
|
+
end
|
563
|
+
of
|
564
|
+
end
|
565
|
+
|
566
|
+
def of2tz(offset)
|
567
|
+
diffmin = offset * 24 * 60
|
568
|
+
if diffmin.zero?
|
569
|
+
'Z'
|
570
|
+
else
|
571
|
+
((diffmin < 0) ? '-' : '+') << format('%02d:%02d',
|
572
|
+
(diffmin.abs / 60.0).to_i, (diffmin.abs % 60.0).to_i)
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
def screen_data(t)
|
577
|
+
# convert t to a DateTime as an internal representation.
|
578
|
+
if t.respond_to?(:to_datetime) # 1.9 or later
|
579
|
+
t.to_datetime
|
580
|
+
elsif t.is_a?(DateTime)
|
581
|
+
t
|
582
|
+
elsif t.is_a?(Date)
|
583
|
+
t = screen_data_str(t)
|
584
|
+
t <<= 12 if t.year < 0
|
585
|
+
t
|
586
|
+
elsif t.is_a?(Time)
|
587
|
+
jd = DateTime.send(:civil_to_jd, t.year, t.mon, t.mday, DateTime::ITALY)
|
588
|
+
fr = DateTime.send(:time_to_day_fraction, t.hour, t.min, [t.sec, 59].min) + t.usec.to_r / DayInMicro
|
589
|
+
of = t.utc_offset.to_r / DayInSec
|
590
|
+
DateTime.new!(DateTime.send(:jd_to_ajd, jd, fr, of), of, DateTime::ITALY)
|
591
|
+
else
|
592
|
+
screen_data_str(t)
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
def add_tz(s)
|
597
|
+
s + of2tz(@data.offset)
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
class XSDDateTime < XSDAnySimpleType
|
602
|
+
include XSDDateTimeImpl
|
603
|
+
Type = QName.new(Namespace, DateTimeLiteral)
|
604
|
+
|
605
|
+
def initialize(value = nil)
|
606
|
+
init(Type, value)
|
607
|
+
end
|
608
|
+
|
609
|
+
private
|
610
|
+
|
611
|
+
def screen_data_str(t)
|
612
|
+
/^([+\-]?\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip
|
613
|
+
unless Regexp.last_match
|
614
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
615
|
+
end
|
616
|
+
if $1 == '0000'
|
617
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
618
|
+
end
|
619
|
+
year = $1.to_i
|
620
|
+
if year < 0
|
621
|
+
year += 1
|
622
|
+
end
|
623
|
+
mon = $2.to_i
|
624
|
+
mday = $3.to_i
|
625
|
+
hour = $4.to_i
|
626
|
+
min = $5.to_i
|
627
|
+
sec = $6.to_i
|
628
|
+
secfrac = $7
|
629
|
+
zonestr = $8
|
630
|
+
data = DateTime.civil(year, mon, mday, hour, min, sec, tz2of(zonestr))
|
631
|
+
if secfrac
|
632
|
+
diffday = secfrac.to_i.to_r / (10 ** secfrac.size) / DayInSec
|
633
|
+
data += diffday
|
634
|
+
# FYI: new! and jd_to_rjd are not necessary to use if you don't have
|
635
|
+
# exceptional reason.
|
636
|
+
end
|
637
|
+
[data, secfrac]
|
638
|
+
end
|
639
|
+
|
640
|
+
def _set(data)
|
641
|
+
if data.nil?
|
642
|
+
@data = @secfrac = nil
|
643
|
+
return
|
644
|
+
end
|
645
|
+
@data, @secfrac = data
|
646
|
+
end
|
647
|
+
|
648
|
+
def _to_s
|
649
|
+
year = (@data.year > 0) ? @data.year : @data.year - 1
|
650
|
+
s = format('%.4d-%02d-%02dT%02d:%02d:%02d', year, @data.mon, @data.mday, @data.hour, @data.min, @data.sec)
|
651
|
+
if @data.sec_fraction.nonzero?
|
652
|
+
if @secfrac
|
653
|
+
s << ".#{ @secfrac }"
|
654
|
+
elsif (RUBY_VERSION.to_f >= 1.9)
|
655
|
+
s << sprintf("%.16f",@data.sec_fraction.to_f).sub(/^0/, '').sub(/0*$/, '')
|
656
|
+
else
|
657
|
+
s << sprintf("%.16f",(@data.sec_fraction * DayInSec).to_f).sub(/^0/, '').sub(/0*$/, '')
|
658
|
+
end
|
659
|
+
end
|
660
|
+
add_tz(s)
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
664
|
+
class XSDTime < XSDAnySimpleType
|
665
|
+
include XSDDateTimeImpl
|
666
|
+
Type = QName.new(Namespace, TimeLiteral)
|
667
|
+
|
668
|
+
def initialize(value = nil)
|
669
|
+
init(Type, value)
|
670
|
+
end
|
671
|
+
|
672
|
+
private
|
673
|
+
|
674
|
+
def screen_data_str(t)
|
675
|
+
/^(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip
|
676
|
+
unless Regexp.last_match
|
677
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
678
|
+
end
|
679
|
+
hour = $1.to_i
|
680
|
+
min = $2.to_i
|
681
|
+
sec = $3.to_i
|
682
|
+
secfrac = $4
|
683
|
+
zonestr = $5
|
684
|
+
data = DateTime.civil(1, 1, 1, hour, min, sec, tz2of(zonestr))
|
685
|
+
if secfrac
|
686
|
+
diffday = secfrac.to_i.to_r / (10 ** secfrac.size) / DayInSec
|
687
|
+
data += diffday
|
688
|
+
end
|
689
|
+
[data, secfrac]
|
690
|
+
end
|
691
|
+
|
692
|
+
def _set(data)
|
693
|
+
if data.nil?
|
694
|
+
@data = @secfrac = nil
|
695
|
+
return
|
696
|
+
end
|
697
|
+
@data, @secfrac = data
|
698
|
+
end
|
699
|
+
|
700
|
+
def _to_s
|
701
|
+
s = format('%02d:%02d:%02d', @data.hour, @data.min, @data.sec)
|
702
|
+
if @data.sec_fraction.nonzero?
|
703
|
+
if @secfrac
|
704
|
+
s << ".#{ @secfrac }"
|
705
|
+
else
|
706
|
+
s << sprintf("%.16f",
|
707
|
+
(@data.sec_fraction * DayInSec).to_f).sub(/^0/, '').sub(/0*$/, '')
|
708
|
+
end
|
709
|
+
end
|
710
|
+
add_tz(s)
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
class XSDDate < XSDAnySimpleType
|
715
|
+
include XSDDateTimeImpl
|
716
|
+
Type = QName.new(Namespace, DateLiteral)
|
717
|
+
|
718
|
+
def initialize(value = nil)
|
719
|
+
init(Type, value)
|
720
|
+
end
|
721
|
+
|
722
|
+
private
|
723
|
+
|
724
|
+
def screen_data_str(t)
|
725
|
+
/^([+\-]?\d{4,})-(\d\d)-(\d\d)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip
|
726
|
+
unless Regexp.last_match
|
727
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
728
|
+
end
|
729
|
+
year = $1.to_i
|
730
|
+
if year < 0
|
731
|
+
year += 1
|
732
|
+
end
|
733
|
+
mon = $2.to_i
|
734
|
+
mday = $3.to_i
|
735
|
+
zonestr = $4
|
736
|
+
DateTime.civil(year, mon, mday, 0, 0, 0, tz2of(zonestr))
|
737
|
+
end
|
738
|
+
|
739
|
+
def _to_s
|
740
|
+
year = (@data.year > 0) ? @data.year : @data.year - 1
|
741
|
+
s = format('%.4d-%02d-%02d', year, @data.mon, @data.mday)
|
742
|
+
add_tz(s)
|
743
|
+
end
|
744
|
+
end
|
745
|
+
|
746
|
+
class XSDGYearMonth < XSDAnySimpleType
|
747
|
+
include XSDDateTimeImpl
|
748
|
+
Type = QName.new(Namespace, GYearMonthLiteral)
|
749
|
+
|
750
|
+
def initialize(value = nil)
|
751
|
+
init(Type, value)
|
752
|
+
end
|
753
|
+
|
754
|
+
private
|
755
|
+
|
756
|
+
def screen_data_str(t)
|
757
|
+
/^([+\-]?\d{4,})-(\d\d)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip
|
758
|
+
unless Regexp.last_match
|
759
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
760
|
+
end
|
761
|
+
year = $1.to_i
|
762
|
+
if year < 0
|
763
|
+
year += 1
|
764
|
+
end
|
765
|
+
mon = $2.to_i
|
766
|
+
zonestr = $3
|
767
|
+
DateTime.civil(year, mon, 1, 0, 0, 0, tz2of(zonestr))
|
768
|
+
end
|
769
|
+
|
770
|
+
def _to_s
|
771
|
+
year = (@data.year > 0) ? @data.year : @data.year - 1
|
772
|
+
s = format('%.4d-%02d', year, @data.mon)
|
773
|
+
add_tz(s)
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
777
|
+
class XSDGYear < XSDAnySimpleType
|
778
|
+
include XSDDateTimeImpl
|
779
|
+
Type = QName.new(Namespace, GYearLiteral)
|
780
|
+
|
781
|
+
def initialize(value = nil)
|
782
|
+
init(Type, value)
|
783
|
+
end
|
784
|
+
|
785
|
+
private
|
786
|
+
|
787
|
+
def screen_data_str(t)
|
788
|
+
/^([+\-]?\d{4,})(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip
|
789
|
+
unless Regexp.last_match
|
790
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
791
|
+
end
|
792
|
+
year = $1.to_i
|
793
|
+
if year < 0
|
794
|
+
year += 1
|
795
|
+
end
|
796
|
+
zonestr = $2
|
797
|
+
DateTime.civil(year, 1, 1, 0, 0, 0, tz2of(zonestr))
|
798
|
+
end
|
799
|
+
|
800
|
+
def _to_s
|
801
|
+
year = (@data.year > 0) ? @data.year : @data.year - 1
|
802
|
+
s = format('%.4d', year)
|
803
|
+
add_tz(s)
|
804
|
+
end
|
805
|
+
end
|
806
|
+
|
807
|
+
class XSDGMonthDay < XSDAnySimpleType
|
808
|
+
include XSDDateTimeImpl
|
809
|
+
Type = QName.new(Namespace, GMonthDayLiteral)
|
810
|
+
|
811
|
+
def initialize(value = nil)
|
812
|
+
init(Type, value)
|
813
|
+
end
|
814
|
+
|
815
|
+
private
|
816
|
+
|
817
|
+
def screen_data_str(t)
|
818
|
+
/^--(\d\d)-(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip
|
819
|
+
unless Regexp.last_match
|
820
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
821
|
+
end
|
822
|
+
mon = $1.to_i
|
823
|
+
mday = $2.to_i
|
824
|
+
zonestr = $3
|
825
|
+
DateTime.civil(1, mon, mday, 0, 0, 0, tz2of(zonestr))
|
826
|
+
end
|
827
|
+
|
828
|
+
def _to_s
|
829
|
+
s = format('--%02d-%02d', @data.mon, @data.mday)
|
830
|
+
add_tz(s)
|
831
|
+
end
|
832
|
+
end
|
833
|
+
|
834
|
+
class XSDGDay < XSDAnySimpleType
|
835
|
+
include XSDDateTimeImpl
|
836
|
+
Type = QName.new(Namespace, GDayLiteral)
|
837
|
+
|
838
|
+
def initialize(value = nil)
|
839
|
+
init(Type, value)
|
840
|
+
end
|
841
|
+
|
842
|
+
private
|
843
|
+
|
844
|
+
def screen_data_str(t)
|
845
|
+
/^---(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip
|
846
|
+
unless Regexp.last_match
|
847
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
848
|
+
end
|
849
|
+
mday = $1.to_i
|
850
|
+
zonestr = $2
|
851
|
+
DateTime.civil(1, 1, mday, 0, 0, 0, tz2of(zonestr))
|
852
|
+
end
|
853
|
+
|
854
|
+
def _to_s
|
855
|
+
s = format('---%02d', @data.mday)
|
856
|
+
add_tz(s)
|
857
|
+
end
|
858
|
+
end
|
859
|
+
|
860
|
+
class XSDGMonth < XSDAnySimpleType
|
861
|
+
include XSDDateTimeImpl
|
862
|
+
Type = QName.new(Namespace, GMonthLiteral)
|
863
|
+
|
864
|
+
def initialize(value = nil)
|
865
|
+
init(Type, value)
|
866
|
+
end
|
867
|
+
|
868
|
+
private
|
869
|
+
|
870
|
+
def screen_data_str(t)
|
871
|
+
/^--(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip
|
872
|
+
unless Regexp.last_match
|
873
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ t }'.")
|
874
|
+
end
|
875
|
+
mon = $1.to_i
|
876
|
+
zonestr = $2
|
877
|
+
DateTime.civil(1, mon, 1, 0, 0, 0, tz2of(zonestr))
|
878
|
+
end
|
879
|
+
|
880
|
+
def _to_s
|
881
|
+
s = format('--%02d', @data.mon)
|
882
|
+
add_tz(s)
|
883
|
+
end
|
884
|
+
end
|
885
|
+
|
886
|
+
class XSDHexBinary < XSDAnySimpleType
|
887
|
+
Type = QName.new(Namespace, HexBinaryLiteral)
|
888
|
+
|
889
|
+
# String in Ruby could be a binary.
|
890
|
+
def initialize(value = nil)
|
891
|
+
init(Type, value)
|
892
|
+
end
|
893
|
+
|
894
|
+
def set_encoded(value)
|
895
|
+
if /^[0-9a-fA-F]*$/ !~ value
|
896
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
897
|
+
end
|
898
|
+
@data = String.new(value).strip
|
899
|
+
@is_nil = false
|
900
|
+
end
|
901
|
+
|
902
|
+
def string
|
903
|
+
[@data].pack("H*")
|
904
|
+
end
|
905
|
+
|
906
|
+
private
|
907
|
+
|
908
|
+
def screen_data(value)
|
909
|
+
value.unpack("H*")[0].tr('a-f', 'A-F')
|
910
|
+
end
|
911
|
+
end
|
912
|
+
|
913
|
+
class XSDBase64Binary < XSDAnySimpleType
|
914
|
+
Type = QName.new(Namespace, Base64BinaryLiteral)
|
915
|
+
|
916
|
+
# String in Ruby could be a binary.
|
917
|
+
def initialize(value = nil)
|
918
|
+
init(Type, value)
|
919
|
+
end
|
920
|
+
|
921
|
+
def set_encoded(value)
|
922
|
+
if /^[A-Za-z0-9+\/=]*$/ !~ value
|
923
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
924
|
+
end
|
925
|
+
@data = String.new(value).strip
|
926
|
+
@is_nil = false
|
927
|
+
end
|
928
|
+
|
929
|
+
def string
|
930
|
+
@data.unpack("m")[0]
|
931
|
+
end
|
932
|
+
|
933
|
+
private
|
934
|
+
|
935
|
+
def screen_data(value)
|
936
|
+
[value].pack("m").strip
|
937
|
+
end
|
938
|
+
end
|
939
|
+
|
940
|
+
class XSDAnyURI < XSDAnySimpleType
|
941
|
+
Type = QName.new(Namespace, AnyURILiteral)
|
942
|
+
|
943
|
+
def initialize(value = nil)
|
944
|
+
init(Type, value)
|
945
|
+
end
|
946
|
+
|
947
|
+
private
|
948
|
+
|
949
|
+
def screen_data(value)
|
950
|
+
begin
|
951
|
+
URI.parse(value.to_s.strip)
|
952
|
+
rescue URI::InvalidURIError
|
953
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.", $!)
|
954
|
+
end
|
955
|
+
end
|
956
|
+
end
|
957
|
+
|
958
|
+
class XSDQName < XSDAnySimpleType
|
959
|
+
Type = QName.new(Namespace, QNameLiteral)
|
960
|
+
|
961
|
+
def initialize(value = nil)
|
962
|
+
init(Type, value)
|
963
|
+
end
|
964
|
+
|
965
|
+
private
|
966
|
+
|
967
|
+
def screen_data(value)
|
968
|
+
/^(?:([^:]+):)?([^:]+)$/ =~ value.to_s.strip
|
969
|
+
unless Regexp.last_match
|
970
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
971
|
+
end
|
972
|
+
prefix = $1
|
973
|
+
localpart = $2
|
974
|
+
[prefix, localpart]
|
975
|
+
end
|
976
|
+
|
977
|
+
def _set(data)
|
978
|
+
if data.nil?
|
979
|
+
@prefix = @localpart = @data = nil
|
980
|
+
return
|
981
|
+
end
|
982
|
+
@prefix, @localpart = data
|
983
|
+
@data = _to_s
|
984
|
+
@data.freeze
|
985
|
+
end
|
986
|
+
|
987
|
+
def _to_s
|
988
|
+
if @prefix
|
989
|
+
"#{ @prefix }:#{ @localpart }"
|
990
|
+
else
|
991
|
+
"#{ @localpart }"
|
992
|
+
end
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
|
997
|
+
###
|
998
|
+
## Derived types
|
999
|
+
#
|
1000
|
+
class XSDNormalizedString < XSDString
|
1001
|
+
Type = QName.new(Namespace, NormalizedStringLiteral)
|
1002
|
+
|
1003
|
+
def initialize(value = nil)
|
1004
|
+
init(Type, value)
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
private
|
1008
|
+
|
1009
|
+
def screen_data(value)
|
1010
|
+
super
|
1011
|
+
if /[\t\r\n]/ =~ value
|
1012
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
1013
|
+
end
|
1014
|
+
value
|
1015
|
+
end
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
class XSDToken < XSDNormalizedString
|
1019
|
+
Type = QName.new(Namespace, TokenLiteral)
|
1020
|
+
|
1021
|
+
def initialize(value = nil)
|
1022
|
+
init(Type, value)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
private
|
1026
|
+
|
1027
|
+
def screen_data(value)
|
1028
|
+
super
|
1029
|
+
if /\A / =~ value or / \Z/ =~ value or value.index(' ')
|
1030
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
1031
|
+
end
|
1032
|
+
value
|
1033
|
+
end
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
class XSDLanguage < XSDToken
|
1037
|
+
Type = QName.new(Namespace, LanguageLiteral)
|
1038
|
+
|
1039
|
+
def initialize(value = nil)
|
1040
|
+
init(Type, value)
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
private
|
1044
|
+
|
1045
|
+
def screen_data(value)
|
1046
|
+
super
|
1047
|
+
# RFC 3066 syntax check
|
1048
|
+
if /\A[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})?\z/ !~ value
|
1049
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
|
1050
|
+
end
|
1051
|
+
value
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
class XSDNMTOKEN < XSDToken
|
1056
|
+
Type = QName.new(Namespace, NMTOKENLiteral)
|
1057
|
+
|
1058
|
+
def initialize(value = nil)
|
1059
|
+
init(Type, value)
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
private
|
1063
|
+
|
1064
|
+
def screen_data(value)
|
1065
|
+
super
|
1066
|
+
# TODO: check lexical space and convert to a value
|
1067
|
+
value
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
class XSDNMTOKENS < XSDNMTOKEN
|
1072
|
+
Type = QName.new(Namespace, NMTOKENSLiteral)
|
1073
|
+
|
1074
|
+
def initialize(value = nil)
|
1075
|
+
init(Type, value)
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
private
|
1079
|
+
|
1080
|
+
def screen_data(value)
|
1081
|
+
# derived by list
|
1082
|
+
# TODO: check lexical space and convert to a value
|
1083
|
+
value
|
1084
|
+
end
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
class XSDName < XSDToken
|
1088
|
+
Type = QName.new(Namespace, NameLiteral)
|
1089
|
+
|
1090
|
+
def initialize(value = nil)
|
1091
|
+
init(Type, value)
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
private
|
1095
|
+
|
1096
|
+
def screen_data(value)
|
1097
|
+
super
|
1098
|
+
# TODO: check lexical space and convert to a value
|
1099
|
+
value
|
1100
|
+
end
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
class XSDNCName < XSDName
|
1104
|
+
Type = QName.new(Namespace, NCNameLiteral)
|
1105
|
+
|
1106
|
+
def initialize(value = nil)
|
1107
|
+
init(Type, value)
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
private
|
1111
|
+
|
1112
|
+
def screen_data(value)
|
1113
|
+
super
|
1114
|
+
# TODO: check lexical space and convert to a value
|
1115
|
+
value
|
1116
|
+
end
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
class XSDID < XSDNCName
|
1120
|
+
Type = QName.new(Namespace, IDLiteral)
|
1121
|
+
|
1122
|
+
def initialize(value = nil)
|
1123
|
+
init(Type, value)
|
1124
|
+
end
|
1125
|
+
|
1126
|
+
private
|
1127
|
+
|
1128
|
+
def screen_data(value)
|
1129
|
+
super
|
1130
|
+
# TODO: check lexical space and convert to a value
|
1131
|
+
value
|
1132
|
+
end
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
class XSDIDREF < XSDNCName
|
1136
|
+
Type = QName.new(Namespace, IDREFLiteral)
|
1137
|
+
|
1138
|
+
def initialize(value = nil)
|
1139
|
+
init(Type, value)
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
private
|
1143
|
+
|
1144
|
+
def screen_data(value)
|
1145
|
+
super
|
1146
|
+
# TODO: check lexical space and convert to a value
|
1147
|
+
value
|
1148
|
+
end
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
class XSDIDREFS < XSDIDREF
|
1152
|
+
Type = QName.new(Namespace, IDREFSLiteral)
|
1153
|
+
|
1154
|
+
def initialize(value = nil)
|
1155
|
+
init(Type, value)
|
1156
|
+
end
|
1157
|
+
|
1158
|
+
private
|
1159
|
+
|
1160
|
+
def screen_data(value)
|
1161
|
+
# derived by list
|
1162
|
+
# TODO: check lexical space and convert to a value
|
1163
|
+
value
|
1164
|
+
end
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
class XSDENTITY < XSDNCName
|
1168
|
+
Type = QName.new(Namespace, ENTITYLiteral)
|
1169
|
+
|
1170
|
+
def initialize(value = nil)
|
1171
|
+
init(Type, value)
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
private
|
1175
|
+
|
1176
|
+
def screen_data(value)
|
1177
|
+
super
|
1178
|
+
# TODO: check lexical space and convert to a value
|
1179
|
+
value
|
1180
|
+
end
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
class XSDENTITIES < XSDENTITY
|
1184
|
+
Type = QName.new(Namespace, ENTITIESLiteral)
|
1185
|
+
|
1186
|
+
def initialize(value = nil)
|
1187
|
+
init(Type, value)
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
private
|
1191
|
+
|
1192
|
+
def screen_data(value)
|
1193
|
+
# derived by list
|
1194
|
+
# TODO: check lexical space and convert to a value
|
1195
|
+
value
|
1196
|
+
end
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
class XSDInteger < XSDDecimal
|
1200
|
+
Type = QName.new(Namespace, IntegerLiteral)
|
1201
|
+
|
1202
|
+
def initialize(value = nil)
|
1203
|
+
init(Type, value)
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
private
|
1207
|
+
|
1208
|
+
def screen_data_str(str)
|
1209
|
+
begin
|
1210
|
+
data = Integer(str)
|
1211
|
+
rescue ArgumentError
|
1212
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.", $!)
|
1213
|
+
end
|
1214
|
+
unless validate(data)
|
1215
|
+
raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
|
1216
|
+
end
|
1217
|
+
data
|
1218
|
+
end
|
1219
|
+
|
1220
|
+
def _set(value)
|
1221
|
+
@data = value
|
1222
|
+
end
|
1223
|
+
|
1224
|
+
def _to_s()
|
1225
|
+
@data.to_s
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
def validate(v)
|
1229
|
+
max = maxinclusive
|
1230
|
+
min = mininclusive
|
1231
|
+
(max.nil? or v <= max) and (min.nil? or v >= min)
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
def maxinclusive
|
1235
|
+
nil
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
def mininclusive
|
1239
|
+
nil
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
PositiveMinInclusive = 1
|
1243
|
+
def positive(v)
|
1244
|
+
PositiveMinInclusive <= v
|
1245
|
+
end
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
class XSDNonPositiveInteger < XSDInteger
|
1249
|
+
Type = QName.new(Namespace, NonPositiveIntegerLiteral)
|
1250
|
+
|
1251
|
+
def initialize(value = nil)
|
1252
|
+
init(Type, value)
|
1253
|
+
end
|
1254
|
+
|
1255
|
+
private
|
1256
|
+
|
1257
|
+
def maxinclusive
|
1258
|
+
0
|
1259
|
+
end
|
1260
|
+
|
1261
|
+
def mininclusive
|
1262
|
+
nil
|
1263
|
+
end
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
class XSDNegativeInteger < XSDNonPositiveInteger
|
1267
|
+
Type = QName.new(Namespace, NegativeIntegerLiteral)
|
1268
|
+
|
1269
|
+
def initialize(value = nil)
|
1270
|
+
init(Type, value)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
private
|
1274
|
+
|
1275
|
+
def maxinclusive
|
1276
|
+
-1
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def mininclusive
|
1280
|
+
nil
|
1281
|
+
end
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
class XSDLong < XSDInteger
|
1285
|
+
Type = QName.new(Namespace, LongLiteral)
|
1286
|
+
|
1287
|
+
def initialize(value = nil)
|
1288
|
+
init(Type, value)
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
private
|
1292
|
+
|
1293
|
+
def maxinclusive
|
1294
|
+
+9223372036854775807
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
def mininclusive
|
1298
|
+
-9223372036854775808
|
1299
|
+
end
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
class XSDInt < XSDLong
|
1303
|
+
Type = QName.new(Namespace, IntLiteral)
|
1304
|
+
|
1305
|
+
def initialize(value = nil)
|
1306
|
+
init(Type, value)
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
private
|
1310
|
+
|
1311
|
+
def maxinclusive
|
1312
|
+
+2147483647
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
def mininclusive
|
1316
|
+
-2147483648
|
1317
|
+
end
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
class XSDShort < XSDInt
|
1321
|
+
Type = QName.new(Namespace, ShortLiteral)
|
1322
|
+
|
1323
|
+
def initialize(value = nil)
|
1324
|
+
init(Type, value)
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
private
|
1328
|
+
|
1329
|
+
def maxinclusive
|
1330
|
+
+32767
|
1331
|
+
end
|
1332
|
+
|
1333
|
+
def mininclusive
|
1334
|
+
-32768
|
1335
|
+
end
|
1336
|
+
end
|
1337
|
+
|
1338
|
+
class XSDByte < XSDShort
|
1339
|
+
Type = QName.new(Namespace, ByteLiteral)
|
1340
|
+
|
1341
|
+
def initialize(value = nil)
|
1342
|
+
init(Type, value)
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
private
|
1346
|
+
|
1347
|
+
def maxinclusive
|
1348
|
+
+127
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
def mininclusive
|
1352
|
+
-128
|
1353
|
+
end
|
1354
|
+
end
|
1355
|
+
|
1356
|
+
class XSDNonNegativeInteger < XSDInteger
|
1357
|
+
Type = QName.new(Namespace, NonNegativeIntegerLiteral)
|
1358
|
+
|
1359
|
+
def initialize(value = nil)
|
1360
|
+
init(Type, value)
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
private
|
1364
|
+
|
1365
|
+
def maxinclusive
|
1366
|
+
nil
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
def mininclusive
|
1370
|
+
0
|
1371
|
+
end
|
1372
|
+
end
|
1373
|
+
|
1374
|
+
class XSDUnsignedLong < XSDNonNegativeInteger
|
1375
|
+
Type = QName.new(Namespace, UnsignedLongLiteral)
|
1376
|
+
|
1377
|
+
def initialize(value = nil)
|
1378
|
+
init(Type, value)
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
private
|
1382
|
+
|
1383
|
+
def maxinclusive
|
1384
|
+
+18446744073709551615
|
1385
|
+
end
|
1386
|
+
|
1387
|
+
def mininclusive
|
1388
|
+
0
|
1389
|
+
end
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
class XSDUnsignedInt < XSDUnsignedLong
|
1393
|
+
Type = QName.new(Namespace, UnsignedIntLiteral)
|
1394
|
+
|
1395
|
+
def initialize(value = nil)
|
1396
|
+
init(Type, value)
|
1397
|
+
end
|
1398
|
+
|
1399
|
+
private
|
1400
|
+
|
1401
|
+
def maxinclusive
|
1402
|
+
+4294967295
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
def mininclusive
|
1406
|
+
0
|
1407
|
+
end
|
1408
|
+
end
|
1409
|
+
|
1410
|
+
class XSDUnsignedShort < XSDUnsignedInt
|
1411
|
+
Type = QName.new(Namespace, UnsignedShortLiteral)
|
1412
|
+
|
1413
|
+
def initialize(value = nil)
|
1414
|
+
init(Type, value)
|
1415
|
+
end
|
1416
|
+
|
1417
|
+
private
|
1418
|
+
|
1419
|
+
def maxinclusive
|
1420
|
+
+65535
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
def mininclusive
|
1424
|
+
0
|
1425
|
+
end
|
1426
|
+
end
|
1427
|
+
|
1428
|
+
class XSDUnsignedByte < XSDUnsignedShort
|
1429
|
+
Type = QName.new(Namespace, UnsignedByteLiteral)
|
1430
|
+
|
1431
|
+
def initialize(value = nil)
|
1432
|
+
init(Type, value)
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
private
|
1436
|
+
|
1437
|
+
def maxinclusive
|
1438
|
+
+255
|
1439
|
+
end
|
1440
|
+
|
1441
|
+
def mininclusive
|
1442
|
+
0
|
1443
|
+
end
|
1444
|
+
end
|
1445
|
+
|
1446
|
+
class XSDPositiveInteger < XSDNonNegativeInteger
|
1447
|
+
Type = QName.new(Namespace, PositiveIntegerLiteral)
|
1448
|
+
|
1449
|
+
def initialize(value = nil)
|
1450
|
+
init(Type, value)
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
private
|
1454
|
+
|
1455
|
+
def maxinclusive
|
1456
|
+
nil
|
1457
|
+
end
|
1458
|
+
|
1459
|
+
def mininclusive
|
1460
|
+
1
|
1461
|
+
end
|
1462
|
+
end
|
1463
|
+
|
1464
|
+
|
1465
|
+
end
|