soybean 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/soybean +22 -0
- data/bin/xsd2ruby +90 -0
- data/lib/soybean.rb +11 -0
- data/lib/soybean/actions/generate_classes.rb +33 -0
- data/soybean.gemspec +236 -0
- data/spec/soybean_spec.rb +5 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/soap4r/soap/attachment.rb +109 -0
- data/vendor/soap4r/soap/attrproxy.rb +35 -0
- data/vendor/soap4r/soap/base_data.rb +1095 -0
- data/vendor/soap4r/soap/element.rb +278 -0
- data/vendor/soap4r/soap/encodingstyle/asp_dot_net_handler.rb +208 -0
- data/vendor/soap4r/soap/encodingstyle/handler.rb +121 -0
- data/vendor/soap4r/soap/encodingstyle/literal_handler.rb +196 -0
- data/vendor/soap4r/soap/encodingstyle/soap_handler.rb +560 -0
- data/vendor/soap4r/soap/filter.rb +14 -0
- data/vendor/soap4r/soap/filter/filterchain.rb +52 -0
- data/vendor/soap4r/soap/filter/handler.rb +32 -0
- data/vendor/soap4r/soap/filter/streamhandler.rb +30 -0
- data/vendor/soap4r/soap/generator.rb +299 -0
- data/vendor/soap4r/soap/header/handler.rb +62 -0
- data/vendor/soap4r/soap/header/handlerset.rb +71 -0
- data/vendor/soap4r/soap/header/mappinghandler.rb +48 -0
- data/vendor/soap4r/soap/header/simplehandler.rb +45 -0
- data/vendor/soap4r/soap/httpconfigloader.rb +140 -0
- data/vendor/soap4r/soap/mapping.rb +13 -0
- data/vendor/soap4r/soap/mapping/encodedregistry.rb +539 -0
- data/vendor/soap4r/soap/mapping/factory.rb +389 -0
- data/vendor/soap4r/soap/mapping/literalregistry.rb +392 -0
- data/vendor/soap4r/soap/mapping/mapping.rb +577 -0
- data/vendor/soap4r/soap/mapping/registry.rb +296 -0
- data/vendor/soap4r/soap/mapping/rubytype_factory.rb +446 -0
- data/vendor/soap4r/soap/mapping/schemadefinition.rb +171 -0
- data/vendor/soap4r/soap/mapping/type_map.rb +107 -0
- data/vendor/soap4r/soap/mapping/wsdlencodedregistry.rb +212 -0
- data/vendor/soap4r/soap/mapping/wsdlliteralregistry.rb +249 -0
- data/vendor/soap4r/soap/marshal.rb +60 -0
- data/vendor/soap4r/soap/mimemessage.rb +243 -0
- data/vendor/soap4r/soap/nestedexception.rb +43 -0
- data/vendor/soap4r/soap/net_http_client.rb +242 -0
- data/vendor/soap4r/soap/ns.rb +39 -0
- data/vendor/soap4r/soap/parser.rb +253 -0
- data/vendor/soap4r/soap/processor.rb +67 -0
- data/vendor/soap4r/soap/property.rb +340 -0
- data/vendor/soap4r/soap/proxy.rb +15 -0
- data/vendor/soap4r/soap/rpc/cgistub.rb +248 -0
- data/vendor/soap4r/soap/rpc/driver.rb +222 -0
- data/vendor/soap4r/soap/rpc/element.rb +375 -0
- data/vendor/soap4r/soap/rpc/httpserver.rb +143 -0
- data/vendor/soap4r/soap/rpc/method_def.rb +69 -0
- data/vendor/soap4r/soap/rpc/proxy.rb +573 -0
- data/vendor/soap4r/soap/rpc/router.rb +663 -0
- data/vendor/soap4r/soap/rpc/rpc.rb +26 -0
- data/vendor/soap4r/soap/rpc/soaplet.rb +201 -0
- data/vendor/soap4r/soap/rpc/standalone_server.rb +44 -0
- data/vendor/soap4r/soap/soap.rb +154 -0
- data/vendor/soap4r/soap/stream_handler.rb +302 -0
- data/vendor/soap4r/soap/version.rb +9 -0
- data/vendor/soap4r/soap/wsdl_driver.rb +165 -0
- data/vendor/soap4r/wsdl/binding.rb +66 -0
- data/vendor/soap4r/wsdl/data.rb +65 -0
- data/vendor/soap4r/wsdl/definitions.rb +237 -0
- data/vendor/soap4r/wsdl/documentation.rb +33 -0
- data/vendor/soap4r/wsdl/import.rb +81 -0
- data/vendor/soap4r/wsdl/importer.rb +39 -0
- data/vendor/soap4r/wsdl/info.rb +51 -0
- data/vendor/soap4r/wsdl/message.rb +55 -0
- data/vendor/soap4r/wsdl/operation.rb +152 -0
- data/vendor/soap4r/wsdl/operation_binding.rb +241 -0
- data/vendor/soap4r/wsdl/param.rb +94 -0
- data/vendor/soap4r/wsdl/parser.rb +165 -0
- data/vendor/soap4r/wsdl/part.rb +53 -0
- data/vendor/soap4r/wsdl/port.rb +67 -0
- data/vendor/soap4r/wsdl/port_type.rb +76 -0
- data/vendor/soap4r/wsdl/service.rb +62 -0
- data/vendor/soap4r/wsdl/soap/address.rb +41 -0
- data/vendor/soap4r/wsdl/soap/binding.rb +50 -0
- data/vendor/soap4r/wsdl/soap/body.rb +59 -0
- data/vendor/soap4r/wsdl/soap/cgi_stub_creator.rb +93 -0
- data/vendor/soap4r/wsdl/soap/class_def_creator.rb +437 -0
- data/vendor/soap4r/wsdl/soap/class_def_creator_support.rb +241 -0
- data/vendor/soap4r/wsdl/soap/class_name_creator.rb +55 -0
- data/vendor/soap4r/wsdl/soap/client_skelton_creator.rb +107 -0
- data/vendor/soap4r/wsdl/soap/complex_type.rb +174 -0
- data/vendor/soap4r/wsdl/soap/data.rb +43 -0
- data/vendor/soap4r/wsdl/soap/definitions.rb +201 -0
- data/vendor/soap4r/wsdl/soap/driver_creator.rb +121 -0
- data/vendor/soap4r/wsdl/soap/element.rb +34 -0
- data/vendor/soap4r/wsdl/soap/encoded_mapping_registry_creator.rb +74 -0
- data/vendor/soap4r/wsdl/soap/fault.rb +57 -0
- data/vendor/soap4r/wsdl/soap/header.rb +87 -0
- data/vendor/soap4r/wsdl/soap/headerfault.rb +57 -0
- data/vendor/soap4r/wsdl/soap/literal_mapping_registry_creator.rb +116 -0
- data/vendor/soap4r/wsdl/soap/mapping_registry_creator.rb +59 -0
- data/vendor/soap4r/wsdl/soap/mapping_registry_creator_support.rb +377 -0
- data/vendor/soap4r/wsdl/soap/method_def_creator.rb +200 -0
- data/vendor/soap4r/wsdl/soap/operation.rb +113 -0
- data/vendor/soap4r/wsdl/soap/servant_skelton_creator.rb +92 -0
- data/vendor/soap4r/wsdl/soap/servlet_stub_creator.rb +105 -0
- data/vendor/soap4r/wsdl/soap/standalone_server_stub_creator.rb +101 -0
- data/vendor/soap4r/wsdl/soap/wsdl2ruby.rb +226 -0
- data/vendor/soap4r/wsdl/types.rb +45 -0
- data/vendor/soap4r/wsdl/wsdl.rb +25 -0
- data/vendor/soap4r/wsdl/xml_schema/all.rb +25 -0
- data/vendor/soap4r/wsdl/xml_schema/annotation.rb +35 -0
- data/vendor/soap4r/wsdl/xml_schema/any.rb +62 -0
- data/vendor/soap4r/wsdl/xml_schema/any_attribute.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/attribute.rb +105 -0
- data/vendor/soap4r/wsdl/xml_schema/attribute_group.rb +69 -0
- data/vendor/soap4r/wsdl/xml_schema/choice.rb +59 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_content.rb +98 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_extension.rb +120 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_restriction.rb +105 -0
- data/vendor/soap4r/wsdl/xml_schema/complex_type.rb +194 -0
- data/vendor/soap4r/wsdl/xml_schema/content.rb +96 -0
- data/vendor/soap4r/wsdl/xml_schema/data.rb +117 -0
- data/vendor/soap4r/wsdl/xml_schema/element.rb +154 -0
- data/vendor/soap4r/wsdl/xml_schema/enumeration.rb +37 -0
- data/vendor/soap4r/wsdl/xml_schema/fractiondigits.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/group.rb +101 -0
- data/vendor/soap4r/wsdl/xml_schema/import.rb +54 -0
- data/vendor/soap4r/wsdl/xml_schema/import_handler.rb +46 -0
- data/vendor/soap4r/wsdl/xml_schema/importer.rb +103 -0
- data/vendor/soap4r/wsdl/xml_schema/include.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/length.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/list.rb +49 -0
- data/vendor/soap4r/wsdl/xml_schema/maxexclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/maxinclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/maxlength.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/minexclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/mininclusive.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/minlength.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/parser.rb +168 -0
- data/vendor/soap4r/wsdl/xml_schema/pattern.rb +37 -0
- data/vendor/soap4r/wsdl/xml_schema/ref.rb +34 -0
- data/vendor/soap4r/wsdl/xml_schema/schema.rb +179 -0
- data/vendor/soap4r/wsdl/xml_schema/sequence.rb +55 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_content.rb +70 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_extension.rb +63 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_restriction.rb +133 -0
- data/vendor/soap4r/wsdl/xml_schema/simple_type.rb +88 -0
- data/vendor/soap4r/wsdl/xml_schema/totaldigits.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/union.rb +36 -0
- data/vendor/soap4r/wsdl/xml_schema/unique.rb +35 -0
- data/vendor/soap4r/wsdl/xml_schema/whitespace.rb +38 -0
- data/vendor/soap4r/wsdl/xml_schema/xsd2ruby.rb +176 -0
- data/vendor/soap4r/xsd/charset.rb +190 -0
- data/vendor/soap4r/xsd/codegen.rb +13 -0
- data/vendor/soap4r/xsd/codegen/classdef.rb +209 -0
- data/vendor/soap4r/xsd/codegen/commentdef.rb +35 -0
- data/vendor/soap4r/xsd/codegen/gensupport.rb +277 -0
- data/vendor/soap4r/xsd/codegen/methoddef.rb +71 -0
- data/vendor/soap4r/xsd/codegen/moduledef.rb +209 -0
- data/vendor/soap4r/xsd/datatypes.rb +1466 -0
- data/vendor/soap4r/xsd/datatypes1999.rb +21 -0
- data/vendor/soap4r/xsd/iconvcharset.rb +34 -0
- data/vendor/soap4r/xsd/mapping.rb +69 -0
- data/vendor/soap4r/xsd/namedelements.rb +133 -0
- data/vendor/soap4r/xsd/ns.rb +183 -0
- data/vendor/soap4r/xsd/qname.rb +80 -0
- data/vendor/soap4r/xsd/xmlparser.rb +77 -0
- data/vendor/soap4r/xsd/xmlparser/libxmlparser.rb +116 -0
- data/vendor/soap4r/xsd/xmlparser/parser.rb +101 -0
- data/vendor/soap4r/xsd/xmlparser/rexmlparser.rb +59 -0
- data/vendor/soap4r/xsd/xmlparser/xmlparser.rb +51 -0
- data/vendor/soap4r/xsd/xmlparser/xmlscanner.rb +150 -0
- metadata +316 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# WSDL4R - XMLSchema union definition for WSDL.
|
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 'wsdl/info'
|
11
|
+
require 'xsd/namedelements'
|
12
|
+
|
13
|
+
|
14
|
+
module WSDL
|
15
|
+
module XMLSchema
|
16
|
+
|
17
|
+
|
18
|
+
class Union < Info
|
19
|
+
attr_reader :member_types
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
@member_types = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_attr(attr, value)
|
27
|
+
case attr
|
28
|
+
when MemberTypesAttrName
|
29
|
+
@member_types = value.source
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# WSDL4R - XMLSchema unique element.
|
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 'wsdl/info'
|
11
|
+
|
12
|
+
|
13
|
+
module WSDL
|
14
|
+
module XMLSchema
|
15
|
+
|
16
|
+
|
17
|
+
class Unique < Info
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_element(element)
|
23
|
+
# Accepts any element.
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_attr(attr, value)
|
28
|
+
# Accepts any attribute.
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# WSDL4R - XMLSchema whiteSpace definition for WSDL.
|
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 'wsdl/info'
|
11
|
+
|
12
|
+
|
13
|
+
module WSDL
|
14
|
+
module XMLSchema
|
15
|
+
|
16
|
+
|
17
|
+
class WhiteSpace < Info
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_element(element)
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_attr(attr, value)
|
27
|
+
case attr
|
28
|
+
when FixedAttrName
|
29
|
+
parent.fixed[:whitespace] = to_boolean(value)
|
30
|
+
when ValueAttrName
|
31
|
+
parent.whitespace = value.source
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - XSD to ruby mapping library.
|
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/codegen/gensupport'
|
11
|
+
require 'wsdl/xml_schema/importer'
|
12
|
+
require 'wsdl/soap/classDefCreator'
|
13
|
+
require 'wsdl/soap/classDefCreatorSupport'
|
14
|
+
require 'wsdl/soap/literalMappingRegistryCreator'
|
15
|
+
require 'wsdl/soap/classNameCreator'
|
16
|
+
require 'logger'
|
17
|
+
|
18
|
+
|
19
|
+
module WSDL
|
20
|
+
module XMLSchema
|
21
|
+
|
22
|
+
|
23
|
+
class XSD2Ruby
|
24
|
+
include WSDL::SOAP::ClassDefCreatorSupport
|
25
|
+
|
26
|
+
attr_accessor :location
|
27
|
+
attr_reader :opt
|
28
|
+
attr_accessor :logger
|
29
|
+
attr_accessor :basedir
|
30
|
+
|
31
|
+
def run
|
32
|
+
unless @location
|
33
|
+
raise RuntimeError, "XML Schema location not given"
|
34
|
+
end
|
35
|
+
@xsd = import(@location)
|
36
|
+
@name = @opt['classdef'] || create_classname(@xsd)
|
37
|
+
create_file
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@location = nil
|
44
|
+
@opt = {}
|
45
|
+
@logger = Logger.new(STDERR)
|
46
|
+
@basedir = nil
|
47
|
+
@xsd = nil
|
48
|
+
@name = nil
|
49
|
+
@name_creator = WSDL::SOAP::ClassNameCreator.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_file
|
53
|
+
@modulepath = @opt['module_path']
|
54
|
+
create_classdef if @opt.key?('classdef')
|
55
|
+
create_mapping_registry if @opt.key?('mapping_registry')
|
56
|
+
create_mapper if @opt.key?('mapper')
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_classdef
|
60
|
+
@logger.info { "Creating class definition." }
|
61
|
+
@classdef_filename = @name + '.rb'
|
62
|
+
check_file(@classdef_filename) or return
|
63
|
+
write_file(@classdef_filename) do |f|
|
64
|
+
f << WSDL::SOAP::ClassDefCreator.new(@xsd, @name_creator, @modulepath).dump
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_mapping_registry
|
69
|
+
@logger.info { "Creating mapping registry definition." }
|
70
|
+
@mr_filename = @name + '_mapping_registry.rb'
|
71
|
+
check_file(@mr_filename) or return
|
72
|
+
write_file(@mr_filename) do |f|
|
73
|
+
f << dump_mapping_registry
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_mapper
|
78
|
+
@logger.info { "Creating mapper definition." }
|
79
|
+
@mapper_filename = @name + '_mapper.rb'
|
80
|
+
check_file(@mapper_filename) or return
|
81
|
+
write_file(@mapper_filename) do |f|
|
82
|
+
f << dump_mapper
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def dump_mapping_registry
|
87
|
+
defined_const = {}
|
88
|
+
creator = WSDL::SOAP::LiteralMappingRegistryCreator.new(@xsd, @name_creator, @modulepath, defined_const)
|
89
|
+
module_name = XSD::CodeGen::GenSupport.safeconstname(@name + 'MappingRegistry')
|
90
|
+
if @modulepath
|
91
|
+
module_name = [@modulepath, module_name].join('::')
|
92
|
+
end
|
93
|
+
m = XSD::CodeGen::ModuleDef.new(module_name)
|
94
|
+
m.def_require("xsd/mapping")
|
95
|
+
m.def_require("#{@classdef_filename}")
|
96
|
+
varname = 'Registry'
|
97
|
+
m.def_const(varname, '::SOAP::Mapping::LiteralRegistry.new')
|
98
|
+
m.def_code(creator.dump(varname))
|
99
|
+
#
|
100
|
+
defined_const.each do |ns, tag|
|
101
|
+
m.def_const(tag, dq(ns))
|
102
|
+
end
|
103
|
+
m.dump
|
104
|
+
end
|
105
|
+
|
106
|
+
def dump_mapper
|
107
|
+
class_name = XSD::CodeGen::GenSupport.safeconstname(@name + 'Mapper')
|
108
|
+
if @modulepath
|
109
|
+
class_name = [@modulepath, class_name].join('::')
|
110
|
+
end
|
111
|
+
mr_name = XSD::CodeGen::GenSupport.safeconstname(@name + 'MappingRegistry')
|
112
|
+
c = XSD::CodeGen::ClassDef.new(class_name, 'XSD::Mapping::Mapper')
|
113
|
+
c.def_require("#{@mr_filename}")
|
114
|
+
c.def_method("initialize") do
|
115
|
+
"super(#{mr_name}::Registry)"
|
116
|
+
end
|
117
|
+
c.dump
|
118
|
+
end
|
119
|
+
|
120
|
+
def write_file(filename)
|
121
|
+
if @basedir
|
122
|
+
filename = File.join(basedir, filename)
|
123
|
+
end
|
124
|
+
File.open(filename, "w") do |f|
|
125
|
+
f.puts "# encoding: ASCII-8BIT"
|
126
|
+
yield f
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def check_file(filename)
|
131
|
+
if @basedir
|
132
|
+
filename = File.join(basedir, filename)
|
133
|
+
end
|
134
|
+
if FileTest.exist?(filename)
|
135
|
+
if @opt.key?('force')
|
136
|
+
@logger.warn {
|
137
|
+
"File '#{filename}' exists but overrides it."
|
138
|
+
}
|
139
|
+
true
|
140
|
+
else
|
141
|
+
@logger.warn {
|
142
|
+
"File '#{filename}' exists. #{$0} did not override it."
|
143
|
+
}
|
144
|
+
false
|
145
|
+
end
|
146
|
+
else
|
147
|
+
@logger.info { "Creates file '#{filename}'." }
|
148
|
+
true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def create_classname(xsd)
|
153
|
+
name = nil
|
154
|
+
if xsd.targetnamespace
|
155
|
+
name = xsd.targetnamespace.scan(/[a-zA-Z0-9]+$/)[0]
|
156
|
+
end
|
157
|
+
if name.nil?
|
158
|
+
'default'
|
159
|
+
else
|
160
|
+
XSD::CodeGen::GenSupport.safevarname(name)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def import(location)
|
165
|
+
WSDL::XMLSchema::Importer.import(location)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
if __FILE__ == $0
|
175
|
+
warn("WARNING: #{File.expand_path(__FILE__)} is a library file used by bin/xsd2ruby.rb. Find bin/xsd2ruby.rb from tarball version of soap4r or install soap4r via gem.")
|
176
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# encoding: ASCII-8BIT
|
2
|
+
# XSD4R - Charset handling library.
|
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
|
+
module XSD
|
11
|
+
|
12
|
+
|
13
|
+
module Charset
|
14
|
+
@internal_encoding = (RUBY_VERSION.to_f >= 1.9) ? 'UTF8' : $KCODE
|
15
|
+
|
16
|
+
class XSDError < StandardError; end
|
17
|
+
class CharsetError < XSDError; end
|
18
|
+
class UnknownCharsetError < CharsetError; end
|
19
|
+
class CharsetConversionError < CharsetError; end
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
###
|
24
|
+
## Maps
|
25
|
+
#
|
26
|
+
EncodingConvertMap = {}
|
27
|
+
def Charset.init
|
28
|
+
EncodingConvertMap[['UTF8', 'X_ISO_8859_1']] =
|
29
|
+
Proc.new { |str| str.unpack('U*').pack('C*') }
|
30
|
+
EncodingConvertMap[['X_ISO_8859_1', 'UTF8']] =
|
31
|
+
Proc.new { |str| str.unpack('C*').pack('U*') }
|
32
|
+
begin
|
33
|
+
require 'xsd/iconvcharset'
|
34
|
+
@internal_encoding = 'UTF8'
|
35
|
+
sjtag = (/(mswin|bccwin|mingw|cygwin|emx)/ =~ RUBY_PLATFORM) ? 'cp932' :
|
36
|
+
'shift_jis'
|
37
|
+
EncodingConvertMap[['UTF8', 'EUC' ]] =
|
38
|
+
Proc.new { |str| IconvCharset.safe_iconv("euc-jp", "utf-8", str) }
|
39
|
+
EncodingConvertMap[['EUC' , 'UTF8']] =
|
40
|
+
Proc.new { |str| IconvCharset.safe_iconv("utf-8", "euc-jp", str) }
|
41
|
+
EncodingConvertMap[['EUC' , 'SJIS']] =
|
42
|
+
Proc.new { |str| IconvCharset.safe_iconv(sjtag, "euc-jp", str) }
|
43
|
+
EncodingConvertMap[['UTF8', 'SJIS']] =
|
44
|
+
Proc.new { |str| IconvCharset.safe_iconv(sjtag, "utf-8", str) }
|
45
|
+
EncodingConvertMap[['SJIS', 'UTF8']] =
|
46
|
+
Proc.new { |str| IconvCharset.safe_iconv("utf-8", sjtag, str) }
|
47
|
+
EncodingConvertMap[['SJIS', 'EUC' ]] =
|
48
|
+
Proc.new { |str| IconvCharset.safe_iconv("euc-jp", sjtag, str) }
|
49
|
+
rescue LoadError
|
50
|
+
begin
|
51
|
+
require 'nkf'
|
52
|
+
EncodingConvertMap[['EUC' , 'SJIS']] =
|
53
|
+
Proc.new { |str| NKF.nkf('-sXm0', str) }
|
54
|
+
EncodingConvertMap[['SJIS', 'EUC' ]] =
|
55
|
+
Proc.new { |str| NKF.nkf('-eXm0', str) }
|
56
|
+
rescue LoadError
|
57
|
+
end
|
58
|
+
|
59
|
+
begin
|
60
|
+
require 'uconv'
|
61
|
+
@internal_encoding = 'UTF8'
|
62
|
+
EncodingConvertMap[['UTF8', 'EUC' ]] = Uconv.method(:u8toeuc)
|
63
|
+
EncodingConvertMap[['UTF8', 'SJIS']] = Uconv.method(:u8tosjis)
|
64
|
+
EncodingConvertMap[['EUC' , 'UTF8']] = Uconv.method(:euctou8)
|
65
|
+
EncodingConvertMap[['SJIS', 'UTF8']] = Uconv.method(:sjistou8)
|
66
|
+
rescue LoadError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
self.init
|
71
|
+
|
72
|
+
CharsetMap = {
|
73
|
+
'NONE' => 'us-ascii',
|
74
|
+
'EUC' => 'euc-jp',
|
75
|
+
'SJIS' => 'shift_jis',
|
76
|
+
'UTF8' => 'utf-8',
|
77
|
+
'X_ISO_8859_1' => 'iso-8859-1',
|
78
|
+
'X_UNKNOWN' => nil,
|
79
|
+
}
|
80
|
+
|
81
|
+
CharsetStrCache = {}
|
82
|
+
|
83
|
+
|
84
|
+
###
|
85
|
+
## handlers
|
86
|
+
#
|
87
|
+
def Charset.encoding
|
88
|
+
@internal_encoding
|
89
|
+
end
|
90
|
+
|
91
|
+
def Charset.encoding=(encoding)
|
92
|
+
warn("xsd charset is set to #{encoding}") if $DEBUG
|
93
|
+
@internal_encoding = encoding
|
94
|
+
end
|
95
|
+
|
96
|
+
def Charset.xml_encoding_label
|
97
|
+
charset_label(@internal_encoding)
|
98
|
+
end
|
99
|
+
|
100
|
+
def Charset.encoding_to_xml(str, charset)
|
101
|
+
encoding_conv(str, @internal_encoding, charset_str(charset))
|
102
|
+
end
|
103
|
+
|
104
|
+
def Charset.encoding_from_xml(str, charset)
|
105
|
+
encoding_conv(str, charset_str(charset), @internal_encoding)
|
106
|
+
end
|
107
|
+
|
108
|
+
def Charset.encoding_conv(str, enc_from, enc_to)
|
109
|
+
if enc_from == enc_to or enc_from == 'NONE' or enc_to == 'NONE'
|
110
|
+
str
|
111
|
+
elsif converter = EncodingConvertMap[[enc_from, enc_to]]
|
112
|
+
converter.call(str)
|
113
|
+
else
|
114
|
+
raise CharsetConversionError.new(
|
115
|
+
"Converter not found: #{enc_from} -> #{enc_to}")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def Charset.charset_label(encoding)
|
120
|
+
CharsetMap[encoding.upcase]
|
121
|
+
end
|
122
|
+
|
123
|
+
def Charset.charset_str(label)
|
124
|
+
if CharsetMap.respond_to?(:key)
|
125
|
+
CharsetStrCache[label] ||= CharsetMap.key(label.downcase) || 'X_UNKNOWN'
|
126
|
+
else
|
127
|
+
CharsetStrCache[label] ||= CharsetMap.index(label.downcase) || 'X_UNKNOWN'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# us_ascii = '[\x00-\x7F]'
|
132
|
+
us_ascii = '[\x9\xa\xd\x20-\x7F]' # XML 1.0 restricted.
|
133
|
+
USASCIIRegexp = Regexp.new("\\A#{us_ascii}*\\z", nil, 'n')
|
134
|
+
|
135
|
+
twobytes_euc = '(?:[\x8E\xA1-\xFE][\xA1-\xFE])'
|
136
|
+
threebytes_euc = '(?:\x8F[\xA1-\xFE][\xA1-\xFE])'
|
137
|
+
character_euc = "(?:#{us_ascii}|#{twobytes_euc}|#{threebytes_euc})"
|
138
|
+
EUCRegexp = Regexp.new("\\A#{character_euc}*\\z", nil, 'n')
|
139
|
+
|
140
|
+
# onebyte_sjis = '[\x00-\x7F\xA1-\xDF]'
|
141
|
+
onebyte_sjis = '[\x9\xa\xd\x20-\x7F\xA1-\xDF]' # XML 1.0 restricted.
|
142
|
+
twobytes_sjis = '(?:[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC])'
|
143
|
+
character_sjis = "(?:#{onebyte_sjis}|#{twobytes_sjis})"
|
144
|
+
SJISRegexp = Regexp.new("\\A#{character_sjis}*\\z", nil, 'n')
|
145
|
+
|
146
|
+
# 0xxxxxxx
|
147
|
+
# 110yyyyy 10xxxxxx
|
148
|
+
twobytes_utf8 = '(?:[\xC0-\xDF][\x80-\xBF])'
|
149
|
+
# 1110zzzz 10yyyyyy 10xxxxxx
|
150
|
+
threebytes_utf8 = '(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF])'
|
151
|
+
# 11110uuu 10uuuzzz 10yyyyyy 10xxxxxx
|
152
|
+
fourbytes_utf8 = '(?:[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])'
|
153
|
+
character_utf8 =
|
154
|
+
"(?:#{us_ascii}|#{twobytes_utf8}|#{threebytes_utf8}|#{fourbytes_utf8})"
|
155
|
+
UTF8Regexp = Regexp.new("\\A#{character_utf8}*\\z", nil, 'n')
|
156
|
+
|
157
|
+
def Charset.is_us_ascii(str)
|
158
|
+
USASCIIRegexp =~ str
|
159
|
+
end
|
160
|
+
|
161
|
+
def Charset.is_utf8(str)
|
162
|
+
UTF8Regexp =~ str
|
163
|
+
end
|
164
|
+
|
165
|
+
def Charset.is_euc(str)
|
166
|
+
EUCRegexp =~ str
|
167
|
+
end
|
168
|
+
|
169
|
+
def Charset.is_sjis(str)
|
170
|
+
SJISRegexp =~ str
|
171
|
+
end
|
172
|
+
|
173
|
+
def Charset.is_ces(str, code = @internal_encoding)
|
174
|
+
case code
|
175
|
+
when 'NONE'
|
176
|
+
is_us_ascii(str)
|
177
|
+
when 'UTF8'
|
178
|
+
is_utf8(str)
|
179
|
+
when 'EUC'
|
180
|
+
is_euc(str)
|
181
|
+
when 'SJIS'
|
182
|
+
is_sjis(str)
|
183
|
+
else
|
184
|
+
raise UnknownCharsetError.new("Unknown charset: #{code}")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
end
|