reidiculous-actionwebservice-client 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +320 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +180 -0
- data/TODO +32 -0
- data/lib/action_web_service.rb +71 -0
- data/lib/action_web_service/api.rb +297 -0
- data/lib/action_web_service/base.rb +38 -0
- data/lib/action_web_service/casting.rb +149 -0
- data/lib/action_web_service/client.rb +3 -0
- data/lib/action_web_service/client/base.rb +28 -0
- data/lib/action_web_service/client/soap_client.rb +113 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
- data/lib/action_web_service/container.rb +3 -0
- data/lib/action_web_service/container/action_controller_container.rb +93 -0
- data/lib/action_web_service/container/delegated_container.rb +86 -0
- data/lib/action_web_service/container/direct_container.rb +69 -0
- data/lib/action_web_service/dispatcher.rb +2 -0
- data/lib/action_web_service/dispatcher/abstract.rb +207 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol.rb +4 -0
- data/lib/action_web_service/protocol/abstract.rb +115 -0
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/soap/attachment.rb +107 -0
- data/lib/action_web_service/soap/baseData.rb +942 -0
- data/lib/action_web_service/soap/element.rb +258 -0
- data/lib/action_web_service/soap/encodingstyle/aspDotNetHandler.rb +213 -0
- data/lib/action_web_service/soap/encodingstyle/handler.rb +100 -0
- data/lib/action_web_service/soap/encodingstyle/literalHandler.rb +226 -0
- data/lib/action_web_service/soap/encodingstyle/soapHandler.rb +582 -0
- data/lib/action_web_service/soap/generator.rb +268 -0
- data/lib/action_web_service/soap/header/handler.rb +57 -0
- data/lib/action_web_service/soap/header/handlerset.rb +70 -0
- data/lib/action_web_service/soap/header/simplehandler.rb +44 -0
- data/lib/action_web_service/soap/httpconfigloader.rb +119 -0
- data/lib/action_web_service/soap/mapping.rb +10 -0
- data/lib/action_web_service/soap/mapping/factory.rb +355 -0
- data/lib/action_web_service/soap/mapping/mapping.rb +381 -0
- data/lib/action_web_service/soap/mapping/registry.rb +541 -0
- data/lib/action_web_service/soap/mapping/rubytypeFactory.rb +475 -0
- data/lib/action_web_service/soap/mapping/typeMap.rb +50 -0
- data/lib/action_web_service/soap/mapping/wsdlencodedregistry.rb +280 -0
- data/lib/action_web_service/soap/mapping/wsdlliteralregistry.rb +418 -0
- data/lib/action_web_service/soap/marshal.rb +59 -0
- data/lib/action_web_service/soap/mimemessage.rb +240 -0
- data/lib/action_web_service/soap/netHttpClient.rb +190 -0
- data/lib/action_web_service/soap/parser.rb +251 -0
- data/lib/action_web_service/soap/processor.rb +66 -0
- data/lib/action_web_service/soap/property.rb +333 -0
- data/lib/action_web_service/soap/rpc/cgistub.rb +206 -0
- data/lib/action_web_service/soap/rpc/driver.rb +254 -0
- data/lib/action_web_service/soap/rpc/element.rb +325 -0
- data/lib/action_web_service/soap/rpc/httpserver.rb +129 -0
- data/lib/action_web_service/soap/rpc/proxy.rb +497 -0
- data/lib/action_web_service/soap/rpc/router.rb +594 -0
- data/lib/action_web_service/soap/rpc/rpc.rb +25 -0
- data/lib/action_web_service/soap/rpc/soaplet.rb +162 -0
- data/lib/action_web_service/soap/rpc/standaloneServer.rb +43 -0
- data/lib/action_web_service/soap/soap.rb +140 -0
- data/lib/action_web_service/soap/streamHandler.rb +229 -0
- data/lib/action_web_service/soap/wsdlDriver.rb +575 -0
- data/lib/action_web_service/struct.rb +64 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +28 -0
- data/lib/action_web_service/support/signature_types.rb +227 -0
- data/lib/action_web_service/test_invoke.rb +110 -0
- data/lib/action_web_service/version.rb +9 -0
- data/lib/action_web_service/wsdl/binding.rb +65 -0
- data/lib/action_web_service/wsdl/data.rb +64 -0
- data/lib/action_web_service/wsdl/definitions.rb +250 -0
- data/lib/action_web_service/wsdl/documentation.rb +32 -0
- data/lib/action_web_service/wsdl/import.rb +80 -0
- data/lib/action_web_service/wsdl/importer.rb +38 -0
- data/lib/action_web_service/wsdl/info.rb +39 -0
- data/lib/action_web_service/wsdl/message.rb +54 -0
- data/lib/action_web_service/wsdl/operation.rb +130 -0
- data/lib/action_web_service/wsdl/operationBinding.rb +108 -0
- data/lib/action_web_service/wsdl/param.rb +85 -0
- data/lib/action_web_service/wsdl/parser.rb +163 -0
- data/lib/action_web_service/wsdl/part.rb +52 -0
- data/lib/action_web_service/wsdl/port.rb +84 -0
- data/lib/action_web_service/wsdl/portType.rb +73 -0
- data/lib/action_web_service/wsdl/service.rb +61 -0
- data/lib/action_web_service/wsdl/soap/address.rb +40 -0
- data/lib/action_web_service/wsdl/soap/binding.rb +49 -0
- data/lib/action_web_service/wsdl/soap/body.rb +56 -0
- data/lib/action_web_service/wsdl/soap/cgiStubCreator.rb +76 -0
- data/lib/action_web_service/wsdl/soap/classDefCreator.rb +314 -0
- data/lib/action_web_service/wsdl/soap/classDefCreatorSupport.rb +126 -0
- data/lib/action_web_service/wsdl/soap/clientSkeltonCreator.rb +78 -0
- data/lib/action_web_service/wsdl/soap/complexType.rb +161 -0
- data/lib/action_web_service/wsdl/soap/data.rb +42 -0
- data/lib/action_web_service/wsdl/soap/definitions.rb +149 -0
- data/lib/action_web_service/wsdl/soap/driverCreator.rb +95 -0
- data/lib/action_web_service/wsdl/soap/element.rb +28 -0
- data/lib/action_web_service/wsdl/soap/fault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/header.rb +86 -0
- data/lib/action_web_service/wsdl/soap/headerfault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/mappingRegistryCreator.rb +92 -0
- data/lib/action_web_service/wsdl/soap/methodDefCreator.rb +228 -0
- data/lib/action_web_service/wsdl/soap/operation.rb +122 -0
- data/lib/action_web_service/wsdl/soap/servantSkeltonCreator.rb +67 -0
- data/lib/action_web_service/wsdl/soap/standaloneServerStubCreator.rb +85 -0
- data/lib/action_web_service/wsdl/soap/wsdl2ruby.rb +176 -0
- data/lib/action_web_service/wsdl/types.rb +43 -0
- data/lib/action_web_service/wsdl/wsdl.rb +23 -0
- data/lib/action_web_service/wsdl/xmlSchema/all.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/annotation.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/any.rb +56 -0
- data/lib/action_web_service/wsdl/xmlSchema/attribute.rb +127 -0
- data/lib/action_web_service/wsdl/xmlSchema/choice.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexContent.rb +92 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexType.rb +139 -0
- data/lib/action_web_service/wsdl/xmlSchema/content.rb +96 -0
- data/lib/action_web_service/wsdl/xmlSchema/data.rb +80 -0
- data/lib/action_web_service/wsdl/xmlSchema/element.rb +154 -0
- data/lib/action_web_service/wsdl/xmlSchema/enumeration.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/import.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/importer.rb +87 -0
- data/lib/action_web_service/wsdl/xmlSchema/include.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/length.rb +35 -0
- data/lib/action_web_service/wsdl/xmlSchema/parser.rb +166 -0
- data/lib/action_web_service/wsdl/xmlSchema/pattern.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/schema.rb +143 -0
- data/lib/action_web_service/wsdl/xmlSchema/sequence.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleContent.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleExtension.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleRestriction.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleType.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/unique.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/xsd2ruby.rb +107 -0
- data/lib/action_web_service/xsd/charset.rb +187 -0
- data/lib/action_web_service/xsd/codegen.rb +12 -0
- data/lib/action_web_service/xsd/codegen/classdef.rb +203 -0
- data/lib/action_web_service/xsd/codegen/commentdef.rb +34 -0
- data/lib/action_web_service/xsd/codegen/gensupport.rb +166 -0
- data/lib/action_web_service/xsd/codegen/methoddef.rb +63 -0
- data/lib/action_web_service/xsd/codegen/moduledef.rb +191 -0
- data/lib/action_web_service/xsd/datatypes.rb +1269 -0
- data/lib/action_web_service/xsd/datatypes1999.rb +20 -0
- data/lib/action_web_service/xsd/iconvcharset.rb +33 -0
- data/lib/action_web_service/xsd/mapping.rb +42 -0
- data/lib/action_web_service/xsd/namedelements.rb +95 -0
- data/lib/action_web_service/xsd/ns.rb +140 -0
- data/lib/action_web_service/xsd/qname.rb +78 -0
- data/lib/action_web_service/xsd/xmlparser.rb +61 -0
- data/lib/action_web_service/xsd/xmlparser/parser.rb +96 -0
- data/lib/action_web_service/xsd/xmlparser/rexmlparser.rb +54 -0
- data/lib/action_web_service/xsd/xmlparser/xmlparser.rb +50 -0
- data/lib/action_web_service/xsd/xmlparser/xmlscanner.rb +147 -0
- data/lib/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +183 -0
- data/test/abstract_dispatcher.rb +548 -0
- data/test/abstract_unit.rb +45 -0
- data/test/api_test.rb +103 -0
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/base_test.rb +42 -0
- data/test/casting_test.rb +95 -0
- data/test/client_soap_test.rb +156 -0
- data/test/client_xmlrpc_test.rb +153 -0
- data/test/container_test.rb +73 -0
- data/test/dispatcher_action_controller_soap_test.rb +139 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +185 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +146 -0
- data/test/struct_test.rb +52 -0
- data/test/test_invoke_test.rb +112 -0
- metadata +265 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# WSDL4R - XMLSchema unique element.
|
2
|
+
# Copyright (C) 2003 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 Unique < Info
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_element(element)
|
22
|
+
# Accepts any element.
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_attr(attr, value)
|
27
|
+
# Accepts any attribute.
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# XSD4R - XSD to ruby mapping library.
|
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/xsd/codegen/gensupport'
|
10
|
+
require 'action_web_service/wsdl/xmlSchema/importer'
|
11
|
+
require 'action_web_service/wsdl/soap/classDefCreator'
|
12
|
+
|
13
|
+
|
14
|
+
module WSDL
|
15
|
+
module XMLSchema
|
16
|
+
|
17
|
+
|
18
|
+
class XSD2Ruby
|
19
|
+
attr_accessor :location
|
20
|
+
attr_reader :opt
|
21
|
+
attr_accessor :logger
|
22
|
+
attr_accessor :basedir
|
23
|
+
|
24
|
+
def run
|
25
|
+
unless @location
|
26
|
+
raise RuntimeError, "XML Schema location not given"
|
27
|
+
end
|
28
|
+
@xsd = import(@location)
|
29
|
+
@name = create_classname(@xsd)
|
30
|
+
create_file
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@location = nil
|
37
|
+
@opt = {}
|
38
|
+
@logger = Logger.new(STDERR)
|
39
|
+
@basedir = nil
|
40
|
+
@xsd = nil
|
41
|
+
@name = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_file
|
45
|
+
create_classdef
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_classdef
|
49
|
+
@logger.info { "Creating class definition." }
|
50
|
+
@classdef_filename = @name + '.rb'
|
51
|
+
check_file(@classdef_filename) or return
|
52
|
+
write_file(@classdef_filename) do |f|
|
53
|
+
f << WSDL::SOAP::ClassDefCreator.new(@xsd).dump
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_file(filename)
|
58
|
+
if @basedir
|
59
|
+
filename = File.join(basedir, filename)
|
60
|
+
end
|
61
|
+
File.open(filename, "w") do |f|
|
62
|
+
yield f
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_file(filename)
|
67
|
+
if @basedir
|
68
|
+
filename = File.join(basedir, filename)
|
69
|
+
end
|
70
|
+
if FileTest.exist?(filename)
|
71
|
+
if @opt.key?('force')
|
72
|
+
@logger.warn {
|
73
|
+
"File '#{filename}' exists but overrides it."
|
74
|
+
}
|
75
|
+
true
|
76
|
+
else
|
77
|
+
@logger.warn {
|
78
|
+
"File '#{filename}' exists. #{$0} did not override it."
|
79
|
+
}
|
80
|
+
false
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@logger.info { "Creates file '#{filename}'." }
|
84
|
+
true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_classname(xsd)
|
89
|
+
name = nil
|
90
|
+
if xsd.targetnamespace
|
91
|
+
name = xsd.targetnamespace.scan(/[a-zA-Z0-9]+$/)[0]
|
92
|
+
end
|
93
|
+
if name.nil?
|
94
|
+
'default'
|
95
|
+
else
|
96
|
+
XSD::CodeGen::GenSupport.safevarname(name)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def import(location)
|
101
|
+
WSDL::XMLSchema::Importer.import(location)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# XSD4R - Charset handling library.
|
2
|
+
# Copyright (C) 2001, 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
|
+
module XSD
|
10
|
+
|
11
|
+
|
12
|
+
module Charset
|
13
|
+
@internal_encoding = $KCODE
|
14
|
+
|
15
|
+
class XSDError < StandardError; end
|
16
|
+
class CharsetError < XSDError; end
|
17
|
+
class UnknownCharsetError < CharsetError; end
|
18
|
+
class CharsetConversionError < CharsetError; end
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
###
|
23
|
+
## Maps
|
24
|
+
#
|
25
|
+
EncodingConvertMap = {}
|
26
|
+
def Charset.init
|
27
|
+
EncodingConvertMap[['UTF8', 'X_ISO8859_1']] =
|
28
|
+
Proc.new { |str| str.unpack('U*').pack('C*') }
|
29
|
+
EncodingConvertMap[['X_ISO8859_1', 'UTF8']] =
|
30
|
+
Proc.new { |str| str.unpack('C*').pack('U*') }
|
31
|
+
begin
|
32
|
+
require 'action_web_service/xsd/iconvcharset'
|
33
|
+
@internal_encoding = 'UTF8'
|
34
|
+
sjtag = (/(mswin|bccwin|mingw|cygwin|emx)/ =~ RUBY_PLATFORM) ? 'cp932' :
|
35
|
+
'shift_jis'
|
36
|
+
EncodingConvertMap[['UTF8', 'EUC' ]] =
|
37
|
+
Proc.new { |str| IconvCharset.safe_iconv("euc-jp", "utf-8", str) }
|
38
|
+
EncodingConvertMap[['EUC' , 'UTF8']] =
|
39
|
+
Proc.new { |str| IconvCharset.safe_iconv("utf-8", "euc-jp", str) }
|
40
|
+
EncodingConvertMap[['EUC' , 'SJIS']] =
|
41
|
+
Proc.new { |str| IconvCharset.safe_iconv(sjtag, "euc-jp", str) }
|
42
|
+
EncodingConvertMap[['UTF8', 'SJIS']] =
|
43
|
+
Proc.new { |str| IconvCharset.safe_iconv(sjtag, "utf-8", str) }
|
44
|
+
EncodingConvertMap[['SJIS', 'UTF8']] =
|
45
|
+
Proc.new { |str| IconvCharset.safe_iconv("utf-8", sjtag, str) }
|
46
|
+
EncodingConvertMap[['SJIS', 'EUC' ]] =
|
47
|
+
Proc.new { |str| IconvCharset.safe_iconv("euc-jp", sjtag, str) }
|
48
|
+
rescue LoadError
|
49
|
+
begin
|
50
|
+
require 'nkf'
|
51
|
+
EncodingConvertMap[['EUC' , 'SJIS']] =
|
52
|
+
Proc.new { |str| NKF.nkf('-sXm0', str) }
|
53
|
+
EncodingConvertMap[['SJIS', 'EUC' ]] =
|
54
|
+
Proc.new { |str| NKF.nkf('-eXm0', str) }
|
55
|
+
rescue LoadError
|
56
|
+
end
|
57
|
+
|
58
|
+
begin
|
59
|
+
require 'uconv'
|
60
|
+
@internal_encoding = 'UTF8'
|
61
|
+
EncodingConvertMap[['UTF8', 'EUC' ]] = Uconv.method(:u8toeuc)
|
62
|
+
EncodingConvertMap[['UTF8', 'SJIS']] = Uconv.method(:u8tosjis)
|
63
|
+
EncodingConvertMap[['EUC' , 'UTF8']] = Uconv.method(:euctou8)
|
64
|
+
EncodingConvertMap[['SJIS', 'UTF8']] = Uconv.method(:sjistou8)
|
65
|
+
rescue LoadError
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
self.init
|
70
|
+
|
71
|
+
CharsetMap = {
|
72
|
+
'NONE' => 'us-ascii',
|
73
|
+
'EUC' => 'euc-jp',
|
74
|
+
'SJIS' => 'shift_jis',
|
75
|
+
'UTF8' => 'utf-8',
|
76
|
+
'X_ISO_8859_1' => 'iso-8859-1',
|
77
|
+
'X_UNKNOWN' => nil,
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
###
|
82
|
+
## handlers
|
83
|
+
#
|
84
|
+
def Charset.encoding
|
85
|
+
@internal_encoding
|
86
|
+
end
|
87
|
+
|
88
|
+
def Charset.encoding=(encoding)
|
89
|
+
warn("xsd charset is set to #{encoding}") if $DEBUG
|
90
|
+
@internal_encoding = encoding
|
91
|
+
end
|
92
|
+
|
93
|
+
def Charset.xml_encoding_label
|
94
|
+
charset_label(@internal_encoding)
|
95
|
+
end
|
96
|
+
|
97
|
+
def Charset.encoding_to_xml(str, charset)
|
98
|
+
encoding_conv(str, @internal_encoding, charset_str(charset))
|
99
|
+
end
|
100
|
+
|
101
|
+
def Charset.encoding_from_xml(str, charset)
|
102
|
+
encoding_conv(str, charset_str(charset), @internal_encoding)
|
103
|
+
end
|
104
|
+
|
105
|
+
def Charset.encoding_conv(str, enc_from, enc_to)
|
106
|
+
if enc_from == enc_to or enc_from == 'NONE' or enc_to == 'NONE'
|
107
|
+
str
|
108
|
+
elsif converter = EncodingConvertMap[[enc_from, enc_to]]
|
109
|
+
converter.call(str)
|
110
|
+
else
|
111
|
+
raise CharsetConversionError.new(
|
112
|
+
"Converter not found: #{enc_from} -> #{enc_to}")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def Charset.charset_label(encoding)
|
117
|
+
CharsetMap[encoding.upcase]
|
118
|
+
end
|
119
|
+
|
120
|
+
def Charset.charset_str(label)
|
121
|
+
if CharsetMap.respond_to?(:key)
|
122
|
+
CharsetMap.key(label.downcase) || 'X_UNKNOWN'
|
123
|
+
else
|
124
|
+
CharsetMap.index(label.downcase) || 'X_UNKNOWN'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# us_ascii = '[\x00-\x7F]'
|
129
|
+
us_ascii = '[\x9\xa\xd\x20-\x7F]' # XML 1.0 restricted.
|
130
|
+
USASCIIRegexp = Regexp.new("\\A#{us_ascii}*\\z", nil, "NONE")
|
131
|
+
|
132
|
+
twobytes_euc = '(?:[\x8E\xA1-\xFE][\xA1-\xFE])'
|
133
|
+
threebytes_euc = '(?:\x8F[\xA1-\xFE][\xA1-\xFE])'
|
134
|
+
character_euc = "(?:#{us_ascii}|#{twobytes_euc}|#{threebytes_euc})"
|
135
|
+
EUCRegexp = Regexp.new("\\A#{character_euc}*\\z", nil, "NONE")
|
136
|
+
|
137
|
+
# onebyte_sjis = '[\x00-\x7F\xA1-\xDF]'
|
138
|
+
onebyte_sjis = '[\x9\xa\xd\x20-\x7F\xA1-\xDF]' # XML 1.0 restricted.
|
139
|
+
twobytes_sjis = '(?:[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC])'
|
140
|
+
character_sjis = "(?:#{onebyte_sjis}|#{twobytes_sjis})"
|
141
|
+
SJISRegexp = Regexp.new("\\A#{character_sjis}*\\z", nil, "NONE")
|
142
|
+
|
143
|
+
# 0xxxxxxx
|
144
|
+
# 110yyyyy 10xxxxxx
|
145
|
+
twobytes_utf8 = '(?:[\xC0-\xDF][\x80-\xBF])'
|
146
|
+
# 1110zzzz 10yyyyyy 10xxxxxx
|
147
|
+
threebytes_utf8 = '(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF])'
|
148
|
+
# 11110uuu 10uuuzzz 10yyyyyy 10xxxxxx
|
149
|
+
fourbytes_utf8 = '(?:[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])'
|
150
|
+
character_utf8 =
|
151
|
+
"(?:#{us_ascii}|#{twobytes_utf8}|#{threebytes_utf8}|#{fourbytes_utf8})"
|
152
|
+
UTF8Regexp = Regexp.new("\\A#{character_utf8}*\\z", nil, "NONE")
|
153
|
+
|
154
|
+
def Charset.is_us_ascii(str)
|
155
|
+
USASCIIRegexp =~ str
|
156
|
+
end
|
157
|
+
|
158
|
+
def Charset.is_utf8(str)
|
159
|
+
UTF8Regexp =~ str
|
160
|
+
end
|
161
|
+
|
162
|
+
def Charset.is_euc(str)
|
163
|
+
EUCRegexp =~ str
|
164
|
+
end
|
165
|
+
|
166
|
+
def Charset.is_sjis(str)
|
167
|
+
SJISRegexp =~ str
|
168
|
+
end
|
169
|
+
|
170
|
+
def Charset.is_ces(str, code = $KCODE)
|
171
|
+
case code
|
172
|
+
when 'NONE'
|
173
|
+
is_us_ascii(str)
|
174
|
+
when 'UTF8'
|
175
|
+
is_utf8(str)
|
176
|
+
when 'EUC'
|
177
|
+
is_euc(str)
|
178
|
+
when 'SJIS'
|
179
|
+
is_sjis(str)
|
180
|
+
else
|
181
|
+
raise UnknownCharsetError.new("Unknown charset: #{code}")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# XSD4R - Generating code library
|
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/xsd/codegen/gensupport'
|
10
|
+
require 'action_web_service/xsd/codegen/moduledef'
|
11
|
+
require 'action_web_service/xsd/codegen/classdef'
|
12
|
+
require 'action_web_service/xsd/codegen/methoddef'
|
@@ -0,0 +1,203 @@
|
|
1
|
+
# XSD4R - Generating class definition code
|
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/xsd/codegen/gensupport'
|
10
|
+
require 'action_web_service/xsd/codegen/moduledef'
|
11
|
+
require 'action_web_service/xsd/codegen/methoddef'
|
12
|
+
|
13
|
+
|
14
|
+
module XSD
|
15
|
+
module CodeGen
|
16
|
+
|
17
|
+
|
18
|
+
class ClassDef < ModuleDef
|
19
|
+
include GenSupport
|
20
|
+
|
21
|
+
def initialize(name, baseclass = nil)
|
22
|
+
super(name)
|
23
|
+
@baseclass = baseclass
|
24
|
+
@classvar = []
|
25
|
+
@attrdef = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def def_classvar(var, value)
|
29
|
+
var = var.sub(/\A@@/, "")
|
30
|
+
unless safevarname?(var)
|
31
|
+
raise ArgumentError.new("#{var} seems to be unsafe")
|
32
|
+
end
|
33
|
+
@classvar << [var, value]
|
34
|
+
end
|
35
|
+
|
36
|
+
def def_attr(attrname, writable = true, varname = nil)
|
37
|
+
unless safevarname?(varname || attrname)
|
38
|
+
raise ArgumentError.new("#{varname || attrname} seems to be unsafe")
|
39
|
+
end
|
40
|
+
@attrdef << [attrname, writable, varname]
|
41
|
+
end
|
42
|
+
|
43
|
+
def dump
|
44
|
+
buf = ""
|
45
|
+
unless @requirepath.empty?
|
46
|
+
buf << dump_requirepath
|
47
|
+
end
|
48
|
+
buf << dump_emptyline unless buf.empty?
|
49
|
+
package = @name.split(/::/)[0..-2]
|
50
|
+
buf << dump_package_def(package) unless package.empty?
|
51
|
+
buf << dump_comment if @comment
|
52
|
+
buf << dump_class_def
|
53
|
+
spacer = false
|
54
|
+
unless @classvar.empty?
|
55
|
+
spacer = true
|
56
|
+
buf << dump_classvar
|
57
|
+
end
|
58
|
+
unless @const.empty?
|
59
|
+
buf << dump_emptyline if spacer
|
60
|
+
spacer = true
|
61
|
+
buf << dump_const
|
62
|
+
end
|
63
|
+
unless @code.empty?
|
64
|
+
buf << dump_emptyline if spacer
|
65
|
+
spacer = true
|
66
|
+
buf << dump_code
|
67
|
+
end
|
68
|
+
unless @attrdef.empty?
|
69
|
+
buf << dump_emptyline if spacer
|
70
|
+
spacer = true
|
71
|
+
buf << dump_attributes
|
72
|
+
end
|
73
|
+
unless @methoddef.empty?
|
74
|
+
buf << dump_emptyline if spacer
|
75
|
+
spacer = true
|
76
|
+
buf << dump_methods
|
77
|
+
end
|
78
|
+
buf << dump_class_def_end
|
79
|
+
buf << dump_package_def_end(package) unless package.empty?
|
80
|
+
buf.gsub(/^\s+$/, '')
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def dump_class_def
|
86
|
+
name = @name.to_s.split(/::/)
|
87
|
+
if @baseclass
|
88
|
+
format("class #{name.last} < #{@baseclass}")
|
89
|
+
else
|
90
|
+
format("class #{name.last}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def dump_class_def_end
|
95
|
+
str = format("end")
|
96
|
+
end
|
97
|
+
|
98
|
+
def dump_classvar
|
99
|
+
dump_static(
|
100
|
+
@classvar.collect { |var, value|
|
101
|
+
%Q(@@#{var.sub(/^@@/, "")} = #{dump_value(value)})
|
102
|
+
}.join("\n")
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def dump_attributes
|
107
|
+
str = ""
|
108
|
+
@attrdef.each do |attrname, writable, varname|
|
109
|
+
varname ||= attrname
|
110
|
+
if attrname == varname
|
111
|
+
str << format(dump_accessor(attrname, writable), 2)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
@attrdef.each do |attrname, writable, varname|
|
115
|
+
varname ||= attrname
|
116
|
+
if attrname != varname
|
117
|
+
str << "\n" unless str.empty?
|
118
|
+
str << format(dump_attribute(attrname, writable, varname), 2)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
str
|
122
|
+
end
|
123
|
+
|
124
|
+
def dump_accessor(attrname, writable)
|
125
|
+
if writable
|
126
|
+
"attr_accessor :#{attrname}"
|
127
|
+
else
|
128
|
+
"attr_reader :#{attrname}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def dump_attribute(attrname, writable, varname)
|
133
|
+
str = nil
|
134
|
+
mr = MethodDef.new(attrname)
|
135
|
+
mr.definition = "@#{varname}"
|
136
|
+
str = mr.dump
|
137
|
+
if writable
|
138
|
+
mw = MethodDef.new(attrname + "=", 'value')
|
139
|
+
mw.definition = "@#{varname} = value"
|
140
|
+
str << "\n" + mw.dump
|
141
|
+
end
|
142
|
+
str
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
if __FILE__ == $0
|
152
|
+
require 'action_web_service/xsd/codegen/classdef'
|
153
|
+
include XSD::CodeGen
|
154
|
+
c = ClassDef.new("Foo::Bar::HobbitName", String)
|
155
|
+
c.def_require("foo/bar")
|
156
|
+
c.comment = <<-EOD
|
157
|
+
foo
|
158
|
+
bar
|
159
|
+
baz
|
160
|
+
EOD
|
161
|
+
c.def_const("FOO", 1)
|
162
|
+
c.def_classvar("@@foo", "var".dump)
|
163
|
+
c.def_classvar("baz", "1".dump)
|
164
|
+
c.def_attr("Foo", true, "foo")
|
165
|
+
c.def_attr("bar")
|
166
|
+
c.def_attr("baz", true)
|
167
|
+
c.def_attr("Foo2", true, "foo2")
|
168
|
+
c.def_attr("foo3", false, "foo3")
|
169
|
+
c.def_method("foo") do
|
170
|
+
<<-EOD
|
171
|
+
foo.bar = 1
|
172
|
+
\tbaz.each do |ele|
|
173
|
+
\t ele
|
174
|
+
end
|
175
|
+
EOD
|
176
|
+
end
|
177
|
+
c.def_method("baz", "qux") do
|
178
|
+
<<-EOD
|
179
|
+
[1, 2, 3].each do |i|
|
180
|
+
p i
|
181
|
+
end
|
182
|
+
EOD
|
183
|
+
end
|
184
|
+
|
185
|
+
m = MethodDef.new("qux", "quxx", "quxxx") do
|
186
|
+
<<-EOD
|
187
|
+
p quxx + quxxx
|
188
|
+
EOD
|
189
|
+
end
|
190
|
+
m.comment = "hello world\n123"
|
191
|
+
c.add_method(m)
|
192
|
+
c.def_code <<-EOD
|
193
|
+
Foo.new
|
194
|
+
Bar.z
|
195
|
+
EOD
|
196
|
+
c.def_code <<-EOD
|
197
|
+
Foo.new
|
198
|
+
Bar.z
|
199
|
+
EOD
|
200
|
+
c.def_privatemethod("foo", "baz", "*arg", "&block")
|
201
|
+
|
202
|
+
puts c.dump
|
203
|
+
end
|