summaryrefslogtreecommitdiff
path: root/lib/wsdl
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-22 13:20:28 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-22 13:20:28 +0000
commit15b7d439885f4aa97e0f508ef485cadab4b23577 (patch)
tree82c8688f0c59072692095d904460e9d33d42c747 /lib/wsdl
parent7c95e34533ddc68692e2f811de159a81b94af3d4 (diff)
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/wsdl')
-rw-r--r--lib/wsdl/soap/wsdl2ruby.rb176
-rw-r--r--lib/wsdl/xmlSchema/annotation.rb34
-rw-r--r--lib/wsdl/xmlSchema/importer.rb81
-rw-r--r--lib/wsdl/xmlSchema/include.rb54
-rw-r--r--lib/wsdl/xmlSchema/length.rb35
-rw-r--r--lib/wsdl/xmlSchema/pattern.rb36
-rw-r--r--lib/wsdl/xmlSchema/simpleExtension.rb54
-rw-r--r--lib/wsdl/xmlSchema/xsd2ruby.rb107
8 files changed, 577 insertions, 0 deletions
diff --git a/lib/wsdl/soap/wsdl2ruby.rb b/lib/wsdl/soap/wsdl2ruby.rb
new file mode 100644
index 0000000000..16b05fb032
--- /dev/null
+++ b/lib/wsdl/soap/wsdl2ruby.rb
@@ -0,0 +1,176 @@
+# WSDL4R - WSDL to ruby mapping library.
+# Copyright (C) 2002-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'logger'
+require 'xsd/qname'
+require 'wsdl/importer'
+require 'wsdl/soap/classDefCreator'
+require 'wsdl/soap/servantSkeltonCreator'
+require 'wsdl/soap/driverCreator'
+require 'wsdl/soap/clientSkeltonCreator'
+require 'wsdl/soap/standaloneServerStubCreator'
+require 'wsdl/soap/cgiStubCreator'
+
+
+module WSDL
+module SOAP
+
+
+class WSDL2Ruby
+ attr_accessor :location
+ attr_reader :opt
+ attr_accessor :logger
+ attr_accessor :basedir
+
+ def run
+ unless @location
+ raise RuntimeError, "WSDL location not given"
+ end
+ @wsdl = import(@location)
+ @name = @wsdl.name ? @wsdl.name.name : 'default'
+ create_file
+ end
+
+private
+
+ def initialize
+ @location = nil
+ @opt = {}
+ @logger = Logger.new(STDERR)
+ @basedir = nil
+ @wsdl = nil
+ @name = nil
+ end
+
+ def create_file
+ create_classdef if @opt.key?('classdef')
+ create_servant_skelton(@opt['servant_skelton']) if @opt.key?('servant_skelton')
+ create_cgi_stub(@opt['cgi_stub']) if @opt.key?('cgi_stub')
+ create_standalone_server_stub(@opt['standalone_server_stub']) if @opt.key?('standalone_server_stub')
+ create_driver(@opt['driver']) if @opt.key?('driver')
+ create_client_skelton(@opt['client_skelton']) if @opt.key?('client_skelton')
+ end
+
+ def create_classdef
+ @logger.info { "Creating class definition." }
+ @classdef_filename = @name + '.rb'
+ check_file(@classdef_filename) or return
+ write_file(@classdef_filename) do |f|
+ f << WSDL::SOAP::ClassDefCreator.new(@wsdl).dump
+ end
+ end
+
+ def create_client_skelton(servicename)
+ @logger.info { "Creating client skelton." }
+ servicename ||= @wsdl.services[0].name.name
+ @client_skelton_filename = servicename + 'Client.rb'
+ check_file(@client_skelton_filename) or return
+ write_file(@client_skelton_filename) do |f|
+ f << shbang << "\n"
+ f << "require '#{@driver_filename}'\n\n" if @driver_filename
+ f << WSDL::SOAP::ClientSkeltonCreator.new(@wsdl).dump(
+ create_name(servicename))
+ end
+ end
+
+ def create_servant_skelton(porttypename)
+ @logger.info { "Creating servant skelton." }
+ @servant_skelton_filename = (porttypename || @name + 'Servant') + '.rb'
+ check_file(@servant_skelton_filename) or return
+ write_file(@servant_skelton_filename) do |f|
+ f << "require '#{@classdef_filename}'\n\n" if @classdef_filename
+ f << WSDL::SOAP::ServantSkeltonCreator.new(@wsdl).dump(
+ create_name(porttypename))
+ end
+ end
+
+ def create_cgi_stub(servicename)
+ @logger.info { "Creating CGI stub." }
+ servicename ||= @wsdl.services[0].name.name
+ @cgi_stubFilename = servicename + '.cgi'
+ check_file(@cgi_stubFilename) or return
+ write_file(@cgi_stubFilename) do |f|
+ f << shbang << "\n"
+ if @servant_skelton_filename
+ f << "require '#{@servant_skelton_filename}'\n\n"
+ end
+ f << WSDL::SOAP::CGIStubCreator.new(@wsdl).dump(create_name(servicename))
+ end
+ end
+
+ def create_standalone_server_stub(servicename)
+ @logger.info { "Creating standalone stub." }
+ servicename ||= @wsdl.services[0].name.name
+ @standalone_server_stub_filename = servicename + '.rb'
+ check_file(@standalone_server_stub_filename) or return
+ write_file(@standalone_server_stub_filename) do |f|
+ f << shbang << "\n"
+ f << "require '#{@servant_skelton_filename}'\n\n" if @servant_skelton_filename
+ f << WSDL::SOAP::StandaloneServerStubCreator.new(@wsdl).dump(
+ create_name(servicename))
+ end
+ end
+
+ def create_driver(porttypename)
+ @logger.info { "Creating driver." }
+ @driver_filename = (porttypename || @name) + 'Driver.rb'
+ check_file(@driver_filename) or return
+ write_file(@driver_filename) do |f|
+ f << "require '#{@classdef_filename}'\n\n" if @classdef_filename
+ f << WSDL::SOAP::DriverCreator.new(@wsdl).dump(
+ create_name(porttypename))
+ end
+ end
+
+ def write_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ File.open(filename, "w") do |f|
+ yield f
+ end
+ end
+
+ def check_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ if FileTest.exist?(filename)
+ if @opt.key?('force')
+ @logger.warn {
+ "File '#{filename}' exists but overrides it."
+ }
+ true
+ else
+ @logger.warn {
+ "File '#{filename}' exists. #{$0} did not override it."
+ }
+ false
+ end
+ else
+ @logger.info { "Creates file '#{filename}'." }
+ true
+ end
+ end
+
+ def shbang
+ "#!/usr/bin/env ruby"
+ end
+
+ def create_name(name)
+ name ? XSD::QName.new(@wsdl.targetnamespace, name) : nil
+ end
+
+ def import(location)
+ WSDL::Importer.import(location)
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/annotation.rb b/lib/wsdl/xmlSchema/annotation.rb
new file mode 100644
index 0000000000..633bd196f1
--- /dev/null
+++ b/lib/wsdl/xmlSchema/annotation.rb
@@ -0,0 +1,34 @@
+# WSDL4R - WSDL SOAP documentation element.
+# Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module XMLSchema
+
+
+class Annotation < Info
+ def initialize
+ super
+ end
+
+ def parse_element(element)
+ # Accepts any element.
+ self
+ end
+
+ def parse_attr(attr, value)
+ # Accepts any attribute.
+ true
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/importer.rb b/lib/wsdl/xmlSchema/importer.rb
new file mode 100644
index 0000000000..8829d5240c
--- /dev/null
+++ b/lib/wsdl/xmlSchema/importer.rb
@@ -0,0 +1,81 @@
+# WSDL4R - XSD importer library.
+# Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'soap/httpconfigloader'
+require 'wsdl/xmlSchema/parser'
+
+
+module WSDL
+module XMLSchema
+
+
+class Importer
+ def self.import(location, originalroot = nil)
+ new.import(location, originalroot)
+ end
+
+ def initialize
+ @web_client = nil
+ end
+
+ def import(location, originalroot = nil)
+ unless location.is_a?(URI)
+ location = URI.parse(location)
+ end
+ content = parse(fetch(location), location, originalroot)
+ content.location = location
+ content
+ end
+
+private
+
+ def parse(content, location, originalroot)
+ opt = {
+ :location => location,
+ :originalroot => originalroot
+ }
+ WSDL::XMLSchema::Parser.new(opt).parse(content)
+ end
+
+ def fetch(location)
+ warn("importing: #{location}") if $DEBUG
+ content = nil
+ if location.scheme == 'file' or
+ (location.relative? and FileTest.exist?(location.path))
+ content = File.open(location.path).read
+ else
+ client = web_client.new(nil, "WSDL4R")
+ client.proxy = ::SOAP::Env::HTTP_PROXY
+ client.no_proxy = ::SOAP::Env::NO_PROXY
+ if opt = ::SOAP::Property.loadproperty(::SOAP::PropertyName)
+ ::SOAP::HTTPConfigLoader.set_options(client, opt["client.protocol.http"])
+ end
+ content = client.get_content(location)
+ end
+ content
+ end
+
+ def web_client
+ @web_client ||= begin
+ require 'http-access2'
+ if HTTPAccess2::VERSION < "2.0"
+ raise LoadError.new("http-access/2.0 or later is required.")
+ end
+ HTTPAccess2::Client
+ rescue LoadError
+ warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
+ require 'soap/netHttpClient'
+ ::SOAP::NetHttpClient
+ end
+ @web_client
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/include.rb b/lib/wsdl/xmlSchema/include.rb
new file mode 100644
index 0000000000..af1ef942bb
--- /dev/null
+++ b/lib/wsdl/xmlSchema/include.rb
@@ -0,0 +1,54 @@
+# WSDL4R - XMLSchema include definition.
+# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/xmlSchema/importer'
+
+
+module WSDL
+module XMLSchema
+
+
+class Include < Info
+ attr_reader :schemalocation
+ attr_reader :content
+
+ def initialize
+ super
+ @schemalocation = nil
+ @content = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when SchemaLocationAttrName
+ @schemalocation = URI.parse(value.source)
+ if @schemalocation.relative?
+ @schemalocation = parent.location + @schemalocation
+ end
+ @content = import(@schemalocation)
+ @schemalocation
+ else
+ nil
+ end
+ end
+
+private
+
+ def import(location)
+ Importer.import(location)
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/length.rb b/lib/wsdl/xmlSchema/length.rb
new file mode 100644
index 0000000000..7f61602da9
--- /dev/null
+++ b/lib/wsdl/xmlSchema/length.rb
@@ -0,0 +1,35 @@
+# WSDL4R - XMLSchema length definition for WSDL.
+# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module XMLSchema
+
+
+class Length < Info
+ def initialize
+ super
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when ValueAttrName
+ value.source
+ end
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/pattern.rb b/lib/wsdl/xmlSchema/pattern.rb
new file mode 100644
index 0000000000..f826be4578
--- /dev/null
+++ b/lib/wsdl/xmlSchema/pattern.rb
@@ -0,0 +1,36 @@
+# WSDL4R - XMLSchema pattern definition for WSDL.
+# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module XMLSchema
+
+
+class Pattern < Info
+ def initialize
+ super
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when ValueAttrName
+ parent.pattern = /\A#{value.source}\z/n
+ value.source
+ end
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/simpleExtension.rb b/lib/wsdl/xmlSchema/simpleExtension.rb
new file mode 100644
index 0000000000..3c53a7328c
--- /dev/null
+++ b/lib/wsdl/xmlSchema/simpleExtension.rb
@@ -0,0 +1,54 @@
+# WSDL4R - XMLSchema simpleType extension definition for WSDL.
+# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'xsd/namedelements'
+
+
+module WSDL
+module XMLSchema
+
+
+class SimpleExtension < Info
+ attr_reader :base
+ attr_reader :attributes
+
+ def initialize
+ super
+ @base = nil
+ @attributes = XSD::NamedElements.new
+ end
+
+ def targetnamespace
+ parent.targetnamespace
+ end
+
+ def valid?(value)
+ true
+ end
+
+ def parse_element(element)
+ case element
+ when AttributeName
+ o = Attribute.new
+ @attributes << o
+ o
+ end
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when BaseAttrName
+ @base = value
+ end
+ end
+end
+
+
+end
+end
diff --git a/lib/wsdl/xmlSchema/xsd2ruby.rb b/lib/wsdl/xmlSchema/xsd2ruby.rb
new file mode 100644
index 0000000000..afe5fc5ada
--- /dev/null
+++ b/lib/wsdl/xmlSchema/xsd2ruby.rb
@@ -0,0 +1,107 @@
+# XSD4R - XSD to ruby mapping library.
+# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'xsd/codegen/gensupport'
+require 'wsdl/xmlSchema/importer'
+require 'wsdl/soap/classDefCreator'
+
+
+module WSDL
+module XMLSchema
+
+
+class XSD2Ruby
+ attr_accessor :location
+ attr_reader :opt
+ attr_accessor :logger
+ attr_accessor :basedir
+
+ def run
+ unless @location
+ raise RuntimeError, "XML Schema location not given"
+ end
+ @xsd = import(@location)
+ @name = create_classname(@xsd)
+ create_file
+ end
+
+private
+
+ def initialize
+ @location = nil
+ @opt = {}
+ @logger = Logger.new(STDERR)
+ @basedir = nil
+ @xsd = nil
+ @name = nil
+ end
+
+ def create_file
+ create_classdef
+ end
+
+ def create_classdef
+ @logger.info { "Creating class definition." }
+ @classdef_filename = @name + '.rb'
+ check_file(@classdef_filename) or return
+ write_file(@classdef_filename) do |f|
+ f << WSDL::SOAP::ClassDefCreator.new(@xsd).dump
+ end
+ end
+
+ def write_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ File.open(filename, "w") do |f|
+ yield f
+ end
+ end
+
+ def check_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ if FileTest.exist?(filename)
+ if @opt.key?('force')
+ @logger.warn {
+ "File '#{filename}' exists but overrides it."
+ }
+ true
+ else
+ @logger.warn {
+ "File '#{filename}' exists. #{$0} did not override it."
+ }
+ false
+ end
+ else
+ @logger.info { "Creates file '#{filename}'." }
+ true
+ end
+ end
+
+ def create_classname(xsd)
+ name = nil
+ if xsd.targetnamespace
+ name = xsd.targetnamespace.scan(/[a-zA-Z0-9]+$/)[0]
+ end
+ if name.nil?
+ 'default'
+ else
+ XSD::CodeGen::GenSupport.safevarname(name)
+ end
+ end
+
+ def import(location)
+ WSDL::XMLSchema::Importer.import(location)
+ end
+end
+
+
+end
+end