reidiculous-actionwebservice 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/CHANGELOG +320 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +381 -0
  4. data/Rakefile +180 -0
  5. data/TODO +32 -0
  6. data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
  7. data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
  8. data/examples/googlesearch/delegated/google_search_service.rb +108 -0
  9. data/examples/googlesearch/delegated/search_controller.rb +7 -0
  10. data/examples/googlesearch/direct/google_search_api.rb +50 -0
  11. data/examples/googlesearch/direct/search_controller.rb +58 -0
  12. data/examples/metaWeblog/apis/blogger_api.rb +60 -0
  13. data/examples/metaWeblog/apis/blogger_service.rb +34 -0
  14. data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
  15. data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
  16. data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
  17. data/generators/web_service/USAGE +28 -0
  18. data/generators/web_service/templates/api_definition.rb +5 -0
  19. data/generators/web_service/templates/controller.rb +8 -0
  20. data/generators/web_service/templates/functional_test.rb +19 -0
  21. data/generators/web_service/web_service_generator.rb +29 -0
  22. data/lib/action_web_service.rb +71 -0
  23. data/lib/action_web_service/api.rb +297 -0
  24. data/lib/action_web_service/base.rb +38 -0
  25. data/lib/action_web_service/casting.rb +149 -0
  26. data/lib/action_web_service/client.rb +3 -0
  27. data/lib/action_web_service/client/base.rb +28 -0
  28. data/lib/action_web_service/client/soap_client.rb +113 -0
  29. data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
  30. data/lib/action_web_service/container.rb +3 -0
  31. data/lib/action_web_service/container/action_controller_container.rb +93 -0
  32. data/lib/action_web_service/container/delegated_container.rb +86 -0
  33. data/lib/action_web_service/container/direct_container.rb +69 -0
  34. data/lib/action_web_service/dispatcher.rb +2 -0
  35. data/lib/action_web_service/dispatcher/abstract.rb +207 -0
  36. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
  37. data/lib/action_web_service/invocation.rb +202 -0
  38. data/lib/action_web_service/protocol.rb +4 -0
  39. data/lib/action_web_service/protocol/abstract.rb +115 -0
  40. data/lib/action_web_service/protocol/discovery.rb +37 -0
  41. data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
  42. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
  43. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
  44. data/lib/action_web_service/scaffolding.rb +281 -0
  45. data/lib/action_web_service/soap/attachment.rb +107 -0
  46. data/lib/action_web_service/soap/baseData.rb +942 -0
  47. data/lib/action_web_service/soap/element.rb +258 -0
  48. data/lib/action_web_service/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  49. data/lib/action_web_service/soap/encodingstyle/handler.rb +100 -0
  50. data/lib/action_web_service/soap/encodingstyle/literalHandler.rb +226 -0
  51. data/lib/action_web_service/soap/encodingstyle/soapHandler.rb +582 -0
  52. data/lib/action_web_service/soap/generator.rb +268 -0
  53. data/lib/action_web_service/soap/header/handler.rb +57 -0
  54. data/lib/action_web_service/soap/header/handlerset.rb +70 -0
  55. data/lib/action_web_service/soap/header/simplehandler.rb +44 -0
  56. data/lib/action_web_service/soap/httpconfigloader.rb +119 -0
  57. data/lib/action_web_service/soap/mapping.rb +10 -0
  58. data/lib/action_web_service/soap/mapping/factory.rb +355 -0
  59. data/lib/action_web_service/soap/mapping/mapping.rb +381 -0
  60. data/lib/action_web_service/soap/mapping/registry.rb +541 -0
  61. data/lib/action_web_service/soap/mapping/rubytypeFactory.rb +475 -0
  62. data/lib/action_web_service/soap/mapping/typeMap.rb +50 -0
  63. data/lib/action_web_service/soap/mapping/wsdlencodedregistry.rb +280 -0
  64. data/lib/action_web_service/soap/mapping/wsdlliteralregistry.rb +418 -0
  65. data/lib/action_web_service/soap/marshal.rb +59 -0
  66. data/lib/action_web_service/soap/mimemessage.rb +240 -0
  67. data/lib/action_web_service/soap/netHttpClient.rb +190 -0
  68. data/lib/action_web_service/soap/parser.rb +251 -0
  69. data/lib/action_web_service/soap/processor.rb +66 -0
  70. data/lib/action_web_service/soap/property.rb +333 -0
  71. data/lib/action_web_service/soap/rpc/cgistub.rb +206 -0
  72. data/lib/action_web_service/soap/rpc/driver.rb +254 -0
  73. data/lib/action_web_service/soap/rpc/element.rb +325 -0
  74. data/lib/action_web_service/soap/rpc/httpserver.rb +129 -0
  75. data/lib/action_web_service/soap/rpc/proxy.rb +497 -0
  76. data/lib/action_web_service/soap/rpc/router.rb +594 -0
  77. data/lib/action_web_service/soap/rpc/rpc.rb +25 -0
  78. data/lib/action_web_service/soap/rpc/soaplet.rb +162 -0
  79. data/lib/action_web_service/soap/rpc/standaloneServer.rb +43 -0
  80. data/lib/action_web_service/soap/soap.rb +140 -0
  81. data/lib/action_web_service/soap/streamHandler.rb +229 -0
  82. data/lib/action_web_service/soap/wsdlDriver.rb +575 -0
  83. data/lib/action_web_service/struct.rb +64 -0
  84. data/lib/action_web_service/support/class_inheritable_options.rb +28 -0
  85. data/lib/action_web_service/support/signature_types.rb +227 -0
  86. data/lib/action_web_service/test_invoke.rb +110 -0
  87. data/lib/action_web_service/version.rb +9 -0
  88. data/lib/action_web_service/wsdl/binding.rb +65 -0
  89. data/lib/action_web_service/wsdl/data.rb +64 -0
  90. data/lib/action_web_service/wsdl/definitions.rb +250 -0
  91. data/lib/action_web_service/wsdl/documentation.rb +32 -0
  92. data/lib/action_web_service/wsdl/import.rb +80 -0
  93. data/lib/action_web_service/wsdl/importer.rb +38 -0
  94. data/lib/action_web_service/wsdl/info.rb +39 -0
  95. data/lib/action_web_service/wsdl/message.rb +54 -0
  96. data/lib/action_web_service/wsdl/operation.rb +130 -0
  97. data/lib/action_web_service/wsdl/operationBinding.rb +108 -0
  98. data/lib/action_web_service/wsdl/param.rb +85 -0
  99. data/lib/action_web_service/wsdl/parser.rb +163 -0
  100. data/lib/action_web_service/wsdl/part.rb +52 -0
  101. data/lib/action_web_service/wsdl/port.rb +84 -0
  102. data/lib/action_web_service/wsdl/portType.rb +73 -0
  103. data/lib/action_web_service/wsdl/service.rb +61 -0
  104. data/lib/action_web_service/wsdl/soap/address.rb +40 -0
  105. data/lib/action_web_service/wsdl/soap/binding.rb +49 -0
  106. data/lib/action_web_service/wsdl/soap/body.rb +56 -0
  107. data/lib/action_web_service/wsdl/soap/cgiStubCreator.rb +76 -0
  108. data/lib/action_web_service/wsdl/soap/classDefCreator.rb +314 -0
  109. data/lib/action_web_service/wsdl/soap/classDefCreatorSupport.rb +126 -0
  110. data/lib/action_web_service/wsdl/soap/clientSkeltonCreator.rb +78 -0
  111. data/lib/action_web_service/wsdl/soap/complexType.rb +161 -0
  112. data/lib/action_web_service/wsdl/soap/data.rb +42 -0
  113. data/lib/action_web_service/wsdl/soap/definitions.rb +149 -0
  114. data/lib/action_web_service/wsdl/soap/driverCreator.rb +95 -0
  115. data/lib/action_web_service/wsdl/soap/element.rb +28 -0
  116. data/lib/action_web_service/wsdl/soap/fault.rb +56 -0
  117. data/lib/action_web_service/wsdl/soap/header.rb +86 -0
  118. data/lib/action_web_service/wsdl/soap/headerfault.rb +56 -0
  119. data/lib/action_web_service/wsdl/soap/mappingRegistryCreator.rb +92 -0
  120. data/lib/action_web_service/wsdl/soap/methodDefCreator.rb +228 -0
  121. data/lib/action_web_service/wsdl/soap/operation.rb +122 -0
  122. data/lib/action_web_service/wsdl/soap/servantSkeltonCreator.rb +67 -0
  123. data/lib/action_web_service/wsdl/soap/standaloneServerStubCreator.rb +85 -0
  124. data/lib/action_web_service/wsdl/soap/wsdl2ruby.rb +176 -0
  125. data/lib/action_web_service/wsdl/types.rb +43 -0
  126. data/lib/action_web_service/wsdl/wsdl.rb +23 -0
  127. data/lib/action_web_service/wsdl/xmlSchema/all.rb +69 -0
  128. data/lib/action_web_service/wsdl/xmlSchema/annotation.rb +34 -0
  129. data/lib/action_web_service/wsdl/xmlSchema/any.rb +56 -0
  130. data/lib/action_web_service/wsdl/xmlSchema/attribute.rb +127 -0
  131. data/lib/action_web_service/wsdl/xmlSchema/choice.rb +69 -0
  132. data/lib/action_web_service/wsdl/xmlSchema/complexContent.rb +92 -0
  133. data/lib/action_web_service/wsdl/xmlSchema/complexType.rb +139 -0
  134. data/lib/action_web_service/wsdl/xmlSchema/content.rb +96 -0
  135. data/lib/action_web_service/wsdl/xmlSchema/data.rb +80 -0
  136. data/lib/action_web_service/wsdl/xmlSchema/element.rb +154 -0
  137. data/lib/action_web_service/wsdl/xmlSchema/enumeration.rb +36 -0
  138. data/lib/action_web_service/wsdl/xmlSchema/import.rb +65 -0
  139. data/lib/action_web_service/wsdl/xmlSchema/importer.rb +87 -0
  140. data/lib/action_web_service/wsdl/xmlSchema/include.rb +54 -0
  141. data/lib/action_web_service/wsdl/xmlSchema/length.rb +35 -0
  142. data/lib/action_web_service/wsdl/xmlSchema/parser.rb +166 -0
  143. data/lib/action_web_service/wsdl/xmlSchema/pattern.rb +36 -0
  144. data/lib/action_web_service/wsdl/xmlSchema/schema.rb +143 -0
  145. data/lib/action_web_service/wsdl/xmlSchema/sequence.rb +69 -0
  146. data/lib/action_web_service/wsdl/xmlSchema/simpleContent.rb +65 -0
  147. data/lib/action_web_service/wsdl/xmlSchema/simpleExtension.rb +54 -0
  148. data/lib/action_web_service/wsdl/xmlSchema/simpleRestriction.rb +73 -0
  149. data/lib/action_web_service/wsdl/xmlSchema/simpleType.rb +73 -0
  150. data/lib/action_web_service/wsdl/xmlSchema/unique.rb +34 -0
  151. data/lib/action_web_service/wsdl/xmlSchema/xsd2ruby.rb +107 -0
  152. data/lib/action_web_service/xsd/charset.rb +187 -0
  153. data/lib/action_web_service/xsd/codegen.rb +12 -0
  154. data/lib/action_web_service/xsd/codegen/classdef.rb +203 -0
  155. data/lib/action_web_service/xsd/codegen/commentdef.rb +34 -0
  156. data/lib/action_web_service/xsd/codegen/gensupport.rb +166 -0
  157. data/lib/action_web_service/xsd/codegen/methoddef.rb +63 -0
  158. data/lib/action_web_service/xsd/codegen/moduledef.rb +191 -0
  159. data/lib/action_web_service/xsd/datatypes.rb +1269 -0
  160. data/lib/action_web_service/xsd/datatypes1999.rb +20 -0
  161. data/lib/action_web_service/xsd/iconvcharset.rb +33 -0
  162. data/lib/action_web_service/xsd/mapping.rb +42 -0
  163. data/lib/action_web_service/xsd/namedelements.rb +95 -0
  164. data/lib/action_web_service/xsd/ns.rb +140 -0
  165. data/lib/action_web_service/xsd/qname.rb +78 -0
  166. data/lib/action_web_service/xsd/xmlparser.rb +61 -0
  167. data/lib/action_web_service/xsd/xmlparser/parser.rb +96 -0
  168. data/lib/action_web_service/xsd/xmlparser/rexmlparser.rb +54 -0
  169. data/lib/action_web_service/xsd/xmlparser/xmlparser.rb +50 -0
  170. data/lib/action_web_service/xsd/xmlparser/xmlscanner.rb +147 -0
  171. data/lib/actionwebservice.rb +1 -0
  172. data/setup.rb +1379 -0
  173. data/test/abstract_client.rb +183 -0
  174. data/test/abstract_dispatcher.rb +548 -0
  175. data/test/abstract_unit.rb +45 -0
  176. data/test/api_test.rb +103 -0
  177. data/test/apis/auto_load_api.rb +3 -0
  178. data/test/apis/broken_auto_load_api.rb +2 -0
  179. data/test/base_test.rb +42 -0
  180. data/test/casting_test.rb +95 -0
  181. data/test/client_soap_test.rb +156 -0
  182. data/test/client_xmlrpc_test.rb +153 -0
  183. data/test/container_test.rb +73 -0
  184. data/test/dispatcher_action_controller_soap_test.rb +139 -0
  185. data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
  186. data/test/fixtures/db_definitions/mysql.sql +8 -0
  187. data/test/fixtures/db_definitions/sqlite3.sql +8 -0
  188. data/test/fixtures/users.yml +12 -0
  189. data/test/gencov +3 -0
  190. data/test/invocation_test.rb +185 -0
  191. data/test/run +6 -0
  192. data/test/scaffolded_controller_test.rb +146 -0
  193. data/test/struct_test.rb +52 -0
  194. data/test/test_invoke_test.rb +112 -0
  195. metadata +281 -0
@@ -0,0 +1,36 @@
1
+ # WSDL4R - XMLSchema enumeration definition for WSDL.
2
+ # Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/wsdl/info'
10
+
11
+
12
+ module WSDL
13
+ module XMLSchema
14
+
15
+
16
+ class Enumeration < Info
17
+ def initialize
18
+ super
19
+ end
20
+
21
+ def parse_element(element)
22
+ nil
23
+ end
24
+
25
+ def parse_attr(attr, value)
26
+ case attr
27
+ when ValueAttrName
28
+ parent.enumeration << value.source
29
+ value.source
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ end
36
+ end
@@ -0,0 +1,65 @@
1
+ # WSDL4R - XMLSchema import definition.
2
+ # Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/wsdl/info'
10
+ require 'action_web_service/wsdl/xmlSchema/importer'
11
+
12
+
13
+ module WSDL
14
+ module XMLSchema
15
+
16
+
17
+ class Import < Info
18
+ attr_reader :namespace
19
+ attr_reader :schemalocation
20
+ attr_reader :content
21
+
22
+ def initialize
23
+ super
24
+ @namespace = nil
25
+ @schemalocation = nil
26
+ @content = nil
27
+ end
28
+
29
+ def parse_element(element)
30
+ nil
31
+ end
32
+
33
+ def parse_attr(attr, value)
34
+ case attr
35
+ when NamespaceAttrName
36
+ @namespace = value.source
37
+ when SchemaLocationAttrName
38
+ @schemalocation = URI.parse(value.source)
39
+ if @schemalocation.relative? and !parent.location.nil? and
40
+ !parent.location.relative?
41
+ @schemalocation = parent.location + @schemalocation
42
+ end
43
+ if root.importedschema.key?(@schemalocation)
44
+ @content = root.importedschema[@schemalocation]
45
+ else
46
+ root.importedschema[@schemalocation] = nil # placeholder
47
+ @content = import(@schemalocation)
48
+ root.importedschema[@schemalocation] = @content
49
+ end
50
+ @schemalocation
51
+ else
52
+ nil
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def import(location)
59
+ Importer.import(location, root)
60
+ end
61
+ end
62
+
63
+
64
+ end
65
+ end
@@ -0,0 +1,87 @@
1
+ # WSDL4R - XSD importer library.
2
+ # Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/soap/httpconfigloader'
10
+ require 'action_web_service/wsdl/xmlSchema/parser'
11
+
12
+
13
+ module WSDL
14
+ module XMLSchema
15
+
16
+
17
+ class Importer
18
+ def self.import(location, originalroot = nil)
19
+ new.import(location, originalroot)
20
+ end
21
+
22
+ def initialize
23
+ @web_client = nil
24
+ end
25
+
26
+ def import(location, originalroot = nil)
27
+ unless location.is_a?(URI)
28
+ location = URI.parse(location)
29
+ end
30
+ content = parse(fetch(location), location, originalroot)
31
+ content.location = location
32
+ content
33
+ end
34
+
35
+ private
36
+
37
+ def parse(content, location, originalroot)
38
+ opt = {
39
+ :location => location,
40
+ :originalroot => originalroot
41
+ }
42
+ WSDL::XMLSchema::Parser.new(opt).parse(content)
43
+ end
44
+
45
+ def fetch(location)
46
+ warn("importing: #{location}") if $DEBUG
47
+ content = nil
48
+ if location.scheme == 'file' or
49
+ (location.relative? and FileTest.exist?(location.path))
50
+ content = File.open(location.path).read
51
+ elsif location.scheme and location.scheme.size == 1 and
52
+ FileTest.exist?(location.to_s)
53
+ # ToDo: remove this ugly workaround for a path with drive letter
54
+ # (D://foo/bar)
55
+ content = File.open(location.to_s).read
56
+ else
57
+ client = web_client.new(nil, "WSDL4R")
58
+ client.proxy = ::SOAP::Env::HTTP_PROXY
59
+ client.no_proxy = ::SOAP::Env::NO_PROXY
60
+ if opt = ::SOAP::Property.loadproperty(::SOAP::PropertyName)
61
+ ::SOAP::HTTPConfigLoader.set_options(client,
62
+ opt["client.protocol.http"])
63
+ end
64
+ content = client.get_content(location)
65
+ end
66
+ content
67
+ end
68
+
69
+ def web_client
70
+ @web_client ||= begin
71
+ require 'http-access2'
72
+ if HTTPAccess2::VERSION < "2.0"
73
+ raise LoadError.new("http-access/2.0 or later is required.")
74
+ end
75
+ HTTPAccess2::Client
76
+ rescue LoadError
77
+ warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
78
+ require 'action_web_service/soap/netHttpClient'
79
+ ::SOAP::NetHttpClient
80
+ end
81
+ @web_client
82
+ end
83
+ end
84
+
85
+
86
+ end
87
+ end
@@ -0,0 +1,54 @@
1
+ # WSDL4R - XMLSchema include definition.
2
+ # Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/wsdl/info'
10
+ require 'action_web_service/wsdl/xmlSchema/importer'
11
+
12
+
13
+ module WSDL
14
+ module XMLSchema
15
+
16
+
17
+ class Include < Info
18
+ attr_reader :schemalocation
19
+ attr_reader :content
20
+
21
+ def initialize
22
+ super
23
+ @schemalocation = nil
24
+ @content = nil
25
+ end
26
+
27
+ def parse_element(element)
28
+ nil
29
+ end
30
+
31
+ def parse_attr(attr, value)
32
+ case attr
33
+ when SchemaLocationAttrName
34
+ @schemalocation = URI.parse(value.source)
35
+ if @schemalocation.relative?
36
+ @schemalocation = parent.location + @schemalocation
37
+ end
38
+ @content = import(@schemalocation)
39
+ @schemalocation
40
+ else
41
+ nil
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def import(location)
48
+ Importer.import(location)
49
+ end
50
+ end
51
+
52
+
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ # WSDL4R - XMLSchema length definition for WSDL.
2
+ # Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/wsdl/info'
10
+
11
+
12
+ module WSDL
13
+ module XMLSchema
14
+
15
+
16
+ class Length < Info
17
+ def initialize
18
+ super
19
+ end
20
+
21
+ def parse_element(element)
22
+ nil
23
+ end
24
+
25
+ def parse_attr(attr, value)
26
+ case attr
27
+ when ValueAttrName
28
+ value.source
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+ end
@@ -0,0 +1,166 @@
1
+ # WSDL4R - WSDL XML Instance parser library.
2
+ # Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
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 'action_web_service/xsd/qname'
10
+ require 'action_web_service/xsd/ns'
11
+ require 'action_web_service/xsd/charset'
12
+ require 'action_web_service/xsd/datatypes'
13
+ require 'action_web_service/xsd/xmlparser'
14
+ require 'action_web_service/wsdl/xmlSchema/data'
15
+
16
+
17
+ module WSDL
18
+ module XMLSchema
19
+
20
+
21
+ class Parser
22
+ include XSD
23
+
24
+ class ParseError < Error; end
25
+ class FormatDecodeError < ParseError; end
26
+ class UnknownElementError < FormatDecodeError; end
27
+ class UnknownAttributeError < FormatDecodeError; end
28
+ class UnexpectedElementError < FormatDecodeError; end
29
+ class ElementConstraintError < FormatDecodeError; end
30
+ class AttributeConstraintError < FormatDecodeError; end
31
+
32
+ private
33
+
34
+ class ParseFrame
35
+ attr_reader :ns
36
+ attr_reader :name
37
+ attr_accessor :node
38
+
39
+ private
40
+
41
+ def initialize(ns, name, node)
42
+ @ns = ns
43
+ @name = name
44
+ @node = node
45
+ end
46
+ end
47
+
48
+ public
49
+
50
+ def initialize(opt = {})
51
+ @parser = XSD::XMLParser.create_parser(self, opt)
52
+ @parsestack = nil
53
+ @lastnode = nil
54
+ @ignored = {}
55
+ @location = opt[:location]
56
+ @originalroot = opt[:originalroot]
57
+ end
58
+
59
+ def parse(string_or_readable)
60
+ @parsestack = []
61
+ @lastnode = nil
62
+ @textbuf = ''
63
+ @parser.do_parse(string_or_readable)
64
+ @lastnode
65
+ end
66
+
67
+ def charset
68
+ @parser.charset
69
+ end
70
+
71
+ def start_element(name, attrs)
72
+ lastframe = @parsestack.last
73
+ ns = parent = nil
74
+ if lastframe
75
+ ns = lastframe.ns.clone_ns
76
+ parent = lastframe.node
77
+ else
78
+ ns = XSD::NS.new
79
+ parent = nil
80
+ end
81
+ attrs = XSD::XMLParser.filter_ns(ns, attrs)
82
+ node = decode_tag(ns, name, attrs, parent)
83
+ @parsestack << ParseFrame.new(ns, name, node)
84
+ end
85
+
86
+ def characters(text)
87
+ lastframe = @parsestack.last
88
+ if lastframe
89
+ # Need not to be cloned because character does not have attr.
90
+ ns = lastframe.ns
91
+ decode_text(ns, text)
92
+ else
93
+ p text if $DEBUG
94
+ end
95
+ end
96
+
97
+ def end_element(name)
98
+ lastframe = @parsestack.pop
99
+ unless name == lastframe.name
100
+ raise UnexpectedElementError.new("closing element name '#{name}' does not match with opening element '#{lastframe.name}'")
101
+ end
102
+ decode_tag_end(lastframe.ns, lastframe.node)
103
+ @lastnode = lastframe.node
104
+ end
105
+
106
+ private
107
+
108
+ def decode_tag(ns, name, attrs, parent)
109
+ o = nil
110
+ elename = ns.parse(name)
111
+ if !parent
112
+ if elename == SchemaName
113
+ o = Schema.parse_element(elename)
114
+ o.location = @location
115
+ else
116
+ raise UnknownElementError.new("unknown element: #{elename}")
117
+ end
118
+ o.root = @originalroot if @originalroot # o.root = o otherwise
119
+ else
120
+ if elename == AnnotationName
121
+ # only the first annotation element is allowed for each element.
122
+ o = Annotation.new
123
+ else
124
+ o = parent.parse_element(elename)
125
+ end
126
+ unless o
127
+ unless @ignored.key?(elename)
128
+ warn("ignored element: #{elename} of #{parent.class}")
129
+ @ignored[elename] = elename
130
+ end
131
+ o = Documentation.new # which accepts any element.
132
+ end
133
+ # node could be a pseudo element. pseudo element has its own parent.
134
+ o.root = parent.root
135
+ o.parent = parent if o.parent.nil?
136
+ end
137
+ attrs.each do |key, value|
138
+ attr_ele = ns.parse(key, true)
139
+ value_ele = ns.parse(value, true)
140
+ value_ele.source = value # for recovery; value may not be a QName
141
+ if attr_ele == IdAttrName
142
+ o.id = value_ele
143
+ else
144
+ unless o.parse_attr(attr_ele, value_ele)
145
+ unless @ignored.key?(attr_ele)
146
+ warn("ignored attr: #{attr_ele}")
147
+ @ignored[attr_ele] = attr_ele
148
+ end
149
+ end
150
+ end
151
+ end
152
+ o
153
+ end
154
+
155
+ def decode_tag_end(ns, node)
156
+ node.parse_epilogue
157
+ end
158
+
159
+ def decode_text(ns, text)
160
+ @textbuf << text
161
+ end
162
+ end
163
+
164
+
165
+ end
166
+ end