From db9445103c082a306ba085f7677da02ea94b8841 Mon Sep 17 00:00:00 2001 From: nahi Date: Wed, 24 Sep 2003 15:18:44 +0000 Subject: * lib/soap/* (29 files): SOAP4R added. * lib/wsdl/* (42 files): WSDL4R added. * lib/xsd/* (12 files): XSD4R added. * test/soap/* (16 files): added. * test/wsdl/* (2 files): added. * test/xsd/* (3 files): added. * sample/soap/* (27 files): added. * sample/wsdl/* (13 files): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/wsdl/binding.rb | 76 ++++++++++++ lib/wsdl/data.rb | 73 +++++++++++ lib/wsdl/definitions.rb | 233 +++++++++++++++++++++++++++++++++++ lib/wsdl/documentation.rb | 43 +++++++ lib/wsdl/import.rb | 81 ++++++++++++ lib/wsdl/importer.rb | 75 +++++++++++ lib/wsdl/info.rb | 44 +++++++ lib/wsdl/message.rb | 65 ++++++++++ lib/wsdl/operation.rb | 144 ++++++++++++++++++++++ lib/wsdl/operationBinding.rb | 91 ++++++++++++++ lib/wsdl/param.rb | 85 +++++++++++++ lib/wsdl/parser.rb | 170 +++++++++++++++++++++++++ lib/wsdl/part.rb | 63 ++++++++++ lib/wsdl/port.rb | 95 ++++++++++++++ lib/wsdl/portType.rb | 83 +++++++++++++ lib/wsdl/service.rb | 72 +++++++++++ lib/wsdl/soap/address.rb | 51 ++++++++ lib/wsdl/soap/binding.rb | 59 +++++++++ lib/wsdl/soap/body.rb | 63 ++++++++++ lib/wsdl/soap/complexType.rb | 96 +++++++++++++++ lib/wsdl/soap/data.rb | 52 ++++++++ lib/wsdl/soap/definitions.rb | 130 +++++++++++++++++++ lib/wsdl/soap/fault.rb | 63 ++++++++++ lib/wsdl/soap/header.rb | 90 ++++++++++++++ lib/wsdl/soap/headerfault.rb | 67 ++++++++++ lib/wsdl/soap/operation.rb | 131 ++++++++++++++++++++ lib/wsdl/types.rb | 54 ++++++++ lib/wsdl/wsdl.rb | 34 +++++ lib/wsdl/xmlSchema/all.rb | 76 ++++++++++++ lib/wsdl/xmlSchema/any.rb | 67 ++++++++++ lib/wsdl/xmlSchema/attribute.rb | 85 +++++++++++++ lib/wsdl/xmlSchema/choice.rb | 76 ++++++++++++ lib/wsdl/xmlSchema/complexContent.rb | 90 ++++++++++++++ lib/wsdl/xmlSchema/complexType.rb | 130 +++++++++++++++++++ lib/wsdl/xmlSchema/content.rb | 107 ++++++++++++++++ lib/wsdl/xmlSchema/data.rb | 75 +++++++++++ lib/wsdl/xmlSchema/element.rb | 115 +++++++++++++++++ lib/wsdl/xmlSchema/import.rb | 55 +++++++++ lib/wsdl/xmlSchema/parser.rb | 172 ++++++++++++++++++++++++++ lib/wsdl/xmlSchema/schema.rb | 105 ++++++++++++++++ lib/wsdl/xmlSchema/sequence.rb | 76 ++++++++++++ lib/wsdl/xmlSchema/unique.rb | 45 +++++++ 42 files changed, 3657 insertions(+) create mode 100644 lib/wsdl/binding.rb create mode 100644 lib/wsdl/data.rb create mode 100644 lib/wsdl/definitions.rb create mode 100644 lib/wsdl/documentation.rb create mode 100644 lib/wsdl/import.rb create mode 100644 lib/wsdl/importer.rb create mode 100644 lib/wsdl/info.rb create mode 100644 lib/wsdl/message.rb create mode 100644 lib/wsdl/operation.rb create mode 100644 lib/wsdl/operationBinding.rb create mode 100644 lib/wsdl/param.rb create mode 100644 lib/wsdl/parser.rb create mode 100644 lib/wsdl/part.rb create mode 100644 lib/wsdl/port.rb create mode 100644 lib/wsdl/portType.rb create mode 100644 lib/wsdl/service.rb create mode 100644 lib/wsdl/soap/address.rb create mode 100644 lib/wsdl/soap/binding.rb create mode 100644 lib/wsdl/soap/body.rb create mode 100644 lib/wsdl/soap/complexType.rb create mode 100644 lib/wsdl/soap/data.rb create mode 100644 lib/wsdl/soap/definitions.rb create mode 100644 lib/wsdl/soap/fault.rb create mode 100644 lib/wsdl/soap/header.rb create mode 100644 lib/wsdl/soap/headerfault.rb create mode 100644 lib/wsdl/soap/operation.rb create mode 100644 lib/wsdl/types.rb create mode 100644 lib/wsdl/wsdl.rb create mode 100644 lib/wsdl/xmlSchema/all.rb create mode 100644 lib/wsdl/xmlSchema/any.rb create mode 100644 lib/wsdl/xmlSchema/attribute.rb create mode 100644 lib/wsdl/xmlSchema/choice.rb create mode 100644 lib/wsdl/xmlSchema/complexContent.rb create mode 100644 lib/wsdl/xmlSchema/complexType.rb create mode 100644 lib/wsdl/xmlSchema/content.rb create mode 100644 lib/wsdl/xmlSchema/data.rb create mode 100644 lib/wsdl/xmlSchema/element.rb create mode 100644 lib/wsdl/xmlSchema/import.rb create mode 100644 lib/wsdl/xmlSchema/parser.rb create mode 100644 lib/wsdl/xmlSchema/schema.rb create mode 100644 lib/wsdl/xmlSchema/sequence.rb create mode 100644 lib/wsdl/xmlSchema/unique.rb (limited to 'lib/wsdl') diff --git a/lib/wsdl/binding.rb b/lib/wsdl/binding.rb new file mode 100644 index 0000000000..349d6edcb6 --- /dev/null +++ b/lib/wsdl/binding.rb @@ -0,0 +1,76 @@ +=begin +WSDL4R - WSDL binding definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL + + +class Binding < Info + attr_reader :name # required + attr_reader :type # required + attr_reader :operations + attr_reader :soapbinding + + def initialize + super + @name = nil + @type = nil + @operations = XSD::NamedElements.new + @soapbinding = nil + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when OperationName + o = OperationBinding.new + @operations << o + o + when SOAPBindingName + o = WSDL::SOAP::Binding.new + @soapbinding = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + when TypeAttrName + @type = value + else + nil + end + end +end + + +end diff --git a/lib/wsdl/data.rb b/lib/wsdl/data.rb new file mode 100644 index 0000000000..4f3b845316 --- /dev/null +++ b/lib/wsdl/data.rb @@ -0,0 +1,73 @@ +=begin +WSDL4R - WSDL data definitions. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/documentation' +require 'wsdl/definitions' +require 'wsdl/types' +require 'wsdl/message' +require 'wsdl/part' +require 'wsdl/portType' +require 'wsdl/operation' +require 'wsdl/param' +require 'wsdl/binding' +require 'wsdl/operationBinding' +require 'wsdl/service' +require 'wsdl/port' +require 'wsdl/import' + + +module WSDL + + +BindingName = XSD::QName.new(Namespace, 'binding') +DefinitionsName = XSD::QName.new(Namespace, 'definitions') +DocumentationName = XSD::QName.new(Namespace, 'documentation') +FaultName = XSD::QName.new(Namespace, 'fault') +ImportName = XSD::QName.new(Namespace, 'import') +InputName = XSD::QName.new(Namespace, 'input') +MessageName = XSD::QName.new(Namespace, 'message') +OperationName = XSD::QName.new(Namespace, 'operation') +OutputName = XSD::QName.new(Namespace, 'output') +PartName = XSD::QName.new(Namespace, 'part') +PortName = XSD::QName.new(Namespace, 'port') +PortTypeName = XSD::QName.new(Namespace, 'portType') +ServiceName = XSD::QName.new(Namespace, 'service') +TypesName = XSD::QName.new(Namespace, 'types') + +SchemaName = XSD::QName.new(XSD::Namespace, 'schema') + +SOAPAddressName = XSD::QName.new(SOAPBindingNamespace, 'address') +SOAPBindingName = XSD::QName.new(SOAPBindingNamespace, 'binding') +SOAPHeaderName = XSD::QName.new(SOAPBindingNamespace, 'header') +SOAPBodyName = XSD::QName.new(SOAPBindingNamespace, 'body') +SOAPFaultName = XSD::QName.new(SOAPBindingNamespace, 'fault') +SOAPOperationName = XSD::QName.new(SOAPBindingNamespace, 'operation') + +BindingAttrName = XSD::QName.new(nil, 'binding') +ElementAttrName = XSD::QName.new(nil, 'element') +LocationAttrName = XSD::QName.new(nil, 'location') +MessageAttrName = XSD::QName.new(nil, 'message') +NameAttrName = XSD::QName.new(nil, 'name') +NamespaceAttrName = XSD::QName.new(nil, 'namespace') +ParameterOrderAttrName = XSD::QName.new(nil, 'parameterOrder') +TargetNamespaceAttrName = XSD::QName.new(nil, 'targetNamespace') +TypeAttrName = XSD::QName.new(nil, 'type') + + +end diff --git a/lib/wsdl/definitions.rb b/lib/wsdl/definitions.rb new file mode 100644 index 0000000000..7a0cff01e7 --- /dev/null +++ b/lib/wsdl/definitions.rb @@ -0,0 +1,233 @@ +=begin +WSDL4R - WSDL definitions. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL + + +class Definitions < Info + attr_reader :name + attr_reader :targetnamespace + attr_reader :imports + + # Overrides Info#root + def root + @root + end + + def root=(root) + @root = root + end + + def initialize + super + @name = nil + @targetnamespace = nil + @types = nil + @imports = [] + @messages = XSD::NamedElements.new + @porttypes = XSD::NamedElements.new + @bindings = XSD::NamedElements.new + @services = XSD::NamedElements.new + + @anontypes = XSD::NamedElements.new + @root = self + end + + def targetnamespace=(targetnamespace) + @targetnamespace = targetnamespace + if @name + @name = XSD::QName.new(@targetnamespace, @name.name) + end + end + + def collect_elements + result = XSD::NamedElements.new + if @types + @types.schemas.each do |schema| + result.concat(schema.elements) + end + end + @imports.each do |import| + result.concat(import.content.collect_elements) + end + result + end + + def collect_complextypes + result = @anontypes.dup + if @types + @types.schemas.each do |schema| + result.concat(schema.complextypes) + end + end + @imports.each do |import| + result.concat(import.content.collect_complextypes) + end + result + end + + def add_type(complextype) + @anontypes << complextype + end + + def messages + result = @messages.dup + @imports.each do |import| + result.concat(import.content.messages) if self.class === import.content + end + result + end + + def porttypes + result = @porttypes.dup + @imports.each do |import| + result.concat(import.content.porttypes) if self.class === import.content + end + result + end + + def bindings + result = @bindings.dup + @imports.each do |import| + result.concat(import.content.bindings) if self.class === import.content + end + result + end + + def services + result = @services.dup + @imports.each do |import| + result.concat(import.content.services) if self.class === import.content + end + result + end + + def message(name) + message = @messages[name] + return message if message + @imports.each do |import| + message = import.content.message(name) if self.class === import.content + return message if message + end + nil + end + + def porttype(name) + porttype = @porttypes[name] + return porttype if porttype + @imports.each do |import| + porttype = import.content.porttype(name) if self.class === import.content + return porttype if porttype + end + nil + end + + def binding(name) + binding = @bindings[name] + return binding if binding + @imports.each do |import| + binding = import.content.binding(name) if self.class === import.content + return binding if binding + end + nil + end + + def service(name) + service = @services[name] + return service if service + @imports.each do |import| + service = import.content.service(name) if self.class === import.content + return service if service + end + nil + end + + def porttype_binding(name) + binding = @bindings.find { |item| item.type == name } + return binding if binding + @imports.each do |import| + binding = import.content.porttype_binding(name) if self.class === import.content + return binding if binding + end + nil + end + + def parse_element(element) + case element + when ImportName + o = Import.new + @imports << o + o + when TypesName + o = Types.new + @types = o + o + when MessageName + o = Message.new + @messages << o + o + when PortTypeName + o = PortType.new + @porttypes << o + o + when BindingName + o = Binding.new + @bindings << o + o + when ServiceName + o = Service.new + @services << o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(@targetnamespace, value) + when TargetNamespaceAttrName + self.targetnamespace = value + else + nil + end + end + + def self.parse_element(element) + if element == DefinitionsName + Definitions.new + else + nil + end + end + +private + +end + + +end diff --git a/lib/wsdl/documentation.rb b/lib/wsdl/documentation.rb new file mode 100644 index 0000000000..00e78a99df --- /dev/null +++ b/lib/wsdl/documentation.rb @@ -0,0 +1,43 @@ +=begin +WSDL4R - WSDL SOAP documentation element. +Copyright (C) 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Documentation < 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 diff --git a/lib/wsdl/import.rb b/lib/wsdl/import.rb new file mode 100644 index 0000000000..a0fa26afaf --- /dev/null +++ b/lib/wsdl/import.rb @@ -0,0 +1,81 @@ +=begin +WSDL4R - WSDL import definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'wsdl/importer' + + +module WSDL + + +class Import < Info + attr_reader :namespace + attr_reader :location + attr_reader :content + + def initialize + super + @namespace = nil + @location = nil + @content = nil + @web_client = nil + end + + def parse_element(element) + case element + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NamespaceAttrName + @namespace = value + if @content + @content.targetnamespace = @namespace + end + @namespace + when LocationAttrName + @location = value + @content = import(@location) + if @content.is_a?(Definitions) + @content.root = root + if @namespace + @content.targetnamespace = @namespace + end + end + @location + else + nil + end + end + +private + + def import(location) + Importer.import(location) + end +end + + +end diff --git a/lib/wsdl/importer.rb b/lib/wsdl/importer.rb new file mode 100644 index 0000000000..794e7fc74d --- /dev/null +++ b/lib/wsdl/importer.rb @@ -0,0 +1,75 @@ +=begin +WSDL4R - WSDL importer library. +Copyright (C) 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Importer + def self.import(location) + new.import(location) + end + + def initialize + @web_client = nil + end + + def import(location) + content = nil + if FileTest.exist?(location) + content = File.open(location).read + else + proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] + content = web_client.new(proxy, "WSDL4R").get_content(location) + end + opt = {} # charset? + begin + WSDL::Parser.new(opt).parse(content) + rescue WSDL::Parser::ParseError => orgexcn + begin + require 'wsdl/xmlSchema/parser' + WSDL::XMLSchema::Parser.new(opt).parse(content) + rescue + raise orgexcn + end + end + end + +private + + 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 + STDERR.puts "Loading http-access2 failed. Net/http is used." if $DEBUG + require 'soap/netHttpClient' + ::SOAP::NetHttpClient + end + @web_client + end +end + + +end diff --git a/lib/wsdl/info.rb b/lib/wsdl/info.rb new file mode 100644 index 0000000000..886b9255ae --- /dev/null +++ b/lib/wsdl/info.rb @@ -0,0 +1,44 @@ +=begin +WSDL4R - WSDL information base. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +module WSDL + + +class Info + attr_accessor :parent + attr_accessor :id + + def initialize + @parent = nil + @id = nil + end + + def root + @parent.root + end + + def parse_element(element); end # abstract + + def parse_attr(attr, value); end # abstract + + def parse_epilogue; end # abstract +end + + +end diff --git a/lib/wsdl/message.rb b/lib/wsdl/message.rb new file mode 100644 index 0000000000..68f3bb89dd --- /dev/null +++ b/lib/wsdl/message.rb @@ -0,0 +1,65 @@ +=begin +WSDL4R - WSDL message definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Message < Info + attr_reader :name # required + attr_reader :parts + + def initialize + super + @name = nil + @parts = [] + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when PartName + o = Part.new + @parts << o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(parent.targetnamespace, value) + else + nil + end + end +end + + +end diff --git a/lib/wsdl/operation.rb b/lib/wsdl/operation.rb new file mode 100644 index 0000000000..ff3450d234 --- /dev/null +++ b/lib/wsdl/operation.rb @@ -0,0 +1,144 @@ +=begin +WSDL4R - WSDL operation definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Operation < Info + class NameInfo + attr_reader :op_name + attr_reader :optype_name + attr_reader :parts + def initialize(op_name, optype_name, parts) + @op_name = op_name + @optype_name = optype_name + @parts = parts + end + end + + attr_reader :name # required + attr_reader :parameter_order # optional + attr_reader :input + attr_reader :output + attr_reader :fault + attr_reader :type # required + + def initialize + super + @name = nil + @type = nil + @parameter_order = nil + @input = nil + @output = nil + @fault = nil + end + + def targetnamespace + parent.targetnamespace + end + + def input_info + op_name = @name + optype_name = XSD::QName.new(targetnamespace, input.name ? input.name.name : @name.name) + NameInfo.new(op_name, optype_name, inputparts) + end + + def output_info + op_name = @name + optype_name = XSD::QName.new(targetnamespace, output.name ? output.name.name : @name.name) + NameInfo.new(op_name, optype_name, outputparts) + end + + def inputparts + sort_parts(input.find_message.parts) + end + + def outputparts + sort_parts(output.find_message.parts) + end + + def faultparts + sort_parts(fault.find_message.parts) + end + + def outputname + XSD::QName.new(targetnamespace, + output.name ? output.name.name : @name.name + 'Response') + end + + def parse_element(element) + case element + when InputName + o = Param.new + @input = o + o + when OutputName + o = Param.new + @output = o + o + when FaultName + o = Param.new + @fault = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + when TypeAttrName + @type = value + when ParameterOrderAttrName + @parameter_order = value.split(/\s+/) + else + nil + end + end + +private + + def sort_parts(parts) + return parts.dup unless parameter_order + result = [] + parameter_order.each do |orderitem| + if (ele = parts.find { |part| part.name == orderitem }) + result << ele + end + end + if result.length == 0 + return parts.dup + end + if parts.length != result.length + raise RuntimeError.new("Incomplete prarmeterOrder list.") + end + result + end +end + + +end diff --git a/lib/wsdl/operationBinding.rb b/lib/wsdl/operationBinding.rb new file mode 100644 index 0000000000..0bd0d9b105 --- /dev/null +++ b/lib/wsdl/operationBinding.rb @@ -0,0 +1,91 @@ +=begin +WSDL4R - WSDL bound operation definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class OperationBinding < Info + attr_reader :name # required + attr_reader :input + attr_reader :output + attr_reader :fault + attr_reader :soapoperation + + def initialize + super + @name = nil + @input = nil + @output = nil + @fault = nil + @soapoperation = nil + end + + def targetnamespace + parent.targetnamespace + end + + def porttype + root.porttype(parent.type) + end + + def find_operation + porttype.operations[@name] + end + + def parse_element(element) + case element + when InputName + o = Param.new + @input = o + o + when OutputName + o = Param.new + @output = o + o + when FaultName + o = Param.new + @fault = o + o + when SOAPOperationName + o = WSDL::SOAP::Operation.new + @soapoperation = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + else + nil + end + end +end + + +end diff --git a/lib/wsdl/param.rb b/lib/wsdl/param.rb new file mode 100644 index 0000000000..10111677d2 --- /dev/null +++ b/lib/wsdl/param.rb @@ -0,0 +1,85 @@ +=begin +WSDL4R - WSDL param definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Param < Info + attr_reader :message # required + attr_reader :name # optional but required for fault. + attr_reader :soapbody + attr_reader :soapheader + attr_reader :soapfault + + def initialize + super + @message = nil + @name = nil + @soapbody = nil + @soapheader = [] + @soapfault = nil + end + + def targetnamespace + parent.targetnamespace + end + + def find_message + root.message(@message) + end + + def parse_element(element) + case element + when SOAPBodyName + o = WSDL::SOAP::Body.new + @soapbody = o + o + when SOAPHeaderName + o = WSDL::SOAP::Header.new + @soapheader << o + o + when SOAPFaultName + o = WSDL::SOAP::Fault.new + @soap_fault = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when MessageAttrName + @message = value + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + else + nil + end + end +end + + +end diff --git a/lib/wsdl/parser.rb b/lib/wsdl/parser.rb new file mode 100644 index 0000000000..e0a8945bb0 --- /dev/null +++ b/lib/wsdl/parser.rb @@ -0,0 +1,170 @@ +=begin +WSDL4R - WSDL XML Instance parser library. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'xsd/qname' +require 'xsd/ns' +require 'xsd/charset' +require 'xsd/datatypes' +require 'xsd/xmlparser' +require 'wsdl/wsdl' +require 'wsdl/data' +require 'wsdl/xmlSchema/data' +require 'wsdl/soap/data' + + +module WSDL + + +class Parser + include WSDL + + class ParseError < Error; end + class FormatDecodeError < ParseError; end + class UnknownElementError < FormatDecodeError; end + class UnknownAttributeError < FormatDecodeError; end + class UnexpectedElementError < FormatDecodeError; end + class ElementConstraintError < FormatDecodeError; end + class AttributeConstraintError < FormatDecodeError; end + +private + + class ParseFrame + attr_reader :ns + attr_reader :name + attr_accessor :node + + private + + def initialize(ns, name, node) + @ns = ns + @name = name + @node = node + end + end + +public + + def initialize(opt = {}) + @parser = XSD::XMLParser.create_parser(self, opt) + @parsestack = nil + @lastnode = nil + end + + def parse(string_or_readable) + @parsestack = [] + @lastnode = nil + @textbuf = '' + @parser.do_parse(string_or_readable) + @lastnode + end + + def charset + @parser.charset + end + + def start_element(name, attrs) + lastframe = @parsestack.last + ns = parent = nil + if lastframe + ns = lastframe.ns.clone_ns + parent = lastframe.node + else + ns = XSD::NS.new + parent = nil + end + attrs = XSD::XMLParser.filter_ns(ns, attrs) + node = decode_tag(ns, name, attrs, parent) + @parsestack << ParseFrame.new(ns, name, node) + end + + def characters(text) + lastframe = @parsestack.last + if lastframe + # Need not to be cloned because character does not have attr. + ns = lastframe.ns + decode_text(ns, text) + else + p text if $DEBUG + end + end + + def end_element(name) + lastframe = @parsestack.pop + unless name == lastframe.name + raise UnexpectedElementError.new("Closing element name '#{ name }' does not match with opening element '#{ lastframe.name }'.") + end + decode_tag_end(lastframe.ns, lastframe.node) + @lastnode = lastframe.node + end + +private + + def decode_tag(ns, name, attrs, parent) + o = nil + element = ns.parse(name) + if !parent + if element == DefinitionsName + o = Definitions.parse_element(element) + else + raise UnknownElementError.new("Unknown element #{ element }.") + end + else + o = parent.parse_element(element) + unless o + STDERR.puts("Unknown element #{ element }.") + o = Documentation.new # which accepts any element. + end + o.parent = parent + end + attrs.each do |key, value| + attr = unless /:/ =~ key + XSD::QName.new(nil, key) + else + ns.parse(key) + end + value_ele = if /:/ !~ value + value + elsif /^http:\/\// =~ value # ToDo: ugly. + value + else + begin + ns.parse(value) + rescue + value + end + end + unless o.parse_attr(attr, value_ele) + STDERR.puts("Unknown attr #{ attr }.") + # raise UnknownAttributeError.new("Unknown attr #{ attr }.") + end + end + o + end + + def decode_tag_end(ns, node) + node.parse_epilogue + end + + def decode_text(ns, text) + @textbuf << text + end +end + + +end diff --git a/lib/wsdl/part.rb b/lib/wsdl/part.rb new file mode 100644 index 0000000000..2aeb457c4e --- /dev/null +++ b/lib/wsdl/part.rb @@ -0,0 +1,63 @@ +=begin +WSDL4R - WSDL part definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Part < Info + attr_reader :name # required + attr_reader :element # optional + attr_reader :type # optional + + def initialize + super + @name = nil + @element = nil + @type = nil + end + + def parse_element(element) + case element + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = value + when ElementAttrName + @element = value + when TypeAttrName + @type = value + else + nil + end + end +end + + +end diff --git a/lib/wsdl/port.rb b/lib/wsdl/port.rb new file mode 100644 index 0000000000..b389f6ca02 --- /dev/null +++ b/lib/wsdl/port.rb @@ -0,0 +1,95 @@ +=begin +WSDL4R - WSDL port definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Port < Info + attr_reader :name # required + attr_reader :binding # required + attr_reader :soap_address + + def initialize + super + @name = nil + @binding = nil + @soap_address = nil + end + + def targetnamespace + parent.targetnamespace + end + + def porttype + root.porttype(find_binding.type) + end + + def find_binding + root.binding(@binding) + end + + def inputoperation_map + result = {} + find_binding.operations.each do |op_bind| + op_info = op_bind.soapoperation.input_info + result[op_info.op_name] = op_info + end + result + end + + def outputoperation_map + result = {} + find_binding.operations.each do |op_bind| + op_info = op_bind.soapoperation.output_info + result[op_info.op_name] = op_info + end + result + end + + def parse_element(element) + case element + when SOAPAddressName + o = WSDL::SOAP::Address.new + @soap_address = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + when BindingAttrName + @binding = value + else + nil + end + end +end + + +end diff --git a/lib/wsdl/portType.rb b/lib/wsdl/portType.rb new file mode 100644 index 0000000000..b3a99b3bc0 --- /dev/null +++ b/lib/wsdl/portType.rb @@ -0,0 +1,83 @@ +=begin +WSDL4R - WSDL portType definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL + + +class PortType < Info + attr_reader :name # required + attr_reader :operations + + def targetnamespace + parent.targetnamespace + end + + def initialize + super + @name = nil + @operations = XSD::NamedElements.new + end + + def find_binding + root.bindings.find { |item| item.type == @name } + end + + def locations + bind_name = find_binding.name + result = [] + root.services.each do |service| + service.ports.each do |port| + if port.binding == bind_name + result << port.soap_address.location if port.soap_address + end + end + end + result + end + + def parse_element(element) + case element + when OperationName + o = Operation.new + @operations << o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + else + nil + end + end +end + + +end diff --git a/lib/wsdl/service.rb b/lib/wsdl/service.rb new file mode 100644 index 0000000000..efaeaa727a --- /dev/null +++ b/lib/wsdl/service.rb @@ -0,0 +1,72 @@ +=begin +WSDL4R - WSDL service definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL + + +class Service < Info + attr_reader :name # required + attr_reader :ports + attr_reader :soap_address + + def initialize + super + @name = nil + @ports = XSD::NamedElements.new + @soap_address = nil + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when PortName + o = Port.new + @ports << o + o + when SOAPAddressName + o = WSDL::SOAP::Address.new + @soap_address = o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + else + nil + end + end +end + + +end diff --git a/lib/wsdl/soap/address.rb b/lib/wsdl/soap/address.rb new file mode 100644 index 0000000000..759918c95b --- /dev/null +++ b/lib/wsdl/soap/address.rb @@ -0,0 +1,51 @@ +=begin +WSDL4R - WSDL SOAP address definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Address < Info + attr_reader :location + + def initialize + super + @location = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when LocationAttrName + @location = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/binding.rb b/lib/wsdl/soap/binding.rb new file mode 100644 index 0000000000..e9ba3a48d1 --- /dev/null +++ b/lib/wsdl/soap/binding.rb @@ -0,0 +1,59 @@ +=begin +WSDL4R - WSDL SOAP binding definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Binding < Info + attr_reader :style + attr_reader :transport + + def initialize + super + @style = nil + @transport = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when StyleAttrName + if ["document", "rpc"].include?(value) + @style = value.intern + else + raise AttributeConstraintError.new("Unexpected value #{ value }.") + end + when TransportAttrName + @transport = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/body.rb b/lib/wsdl/soap/body.rb new file mode 100644 index 0000000000..f209622410 --- /dev/null +++ b/lib/wsdl/soap/body.rb @@ -0,0 +1,63 @@ +=begin +WSDL4R - WSDL SOAP body definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Body < Info + attr_reader :parts + attr_reader :use # required + attr_reader :encodingstyle + attr_reader :namespace + + def initialize + super + @parts = nil + @use = nil + @encodingstyle = nil + @namespace = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when PartsAttrName + @parts = value + when UseAttrName + @use = value + when EncodingStyleAttrName + @encodingstyle = value + when NamespaceAttrName + @namespace = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/complexType.rb b/lib/wsdl/soap/complexType.rb new file mode 100644 index 0000000000..f47ddee449 --- /dev/null +++ b/lib/wsdl/soap/complexType.rb @@ -0,0 +1,96 @@ +=begin +WSDL4R - SOAP complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/xmlSchema/complexType' + + +module WSDL +module XMLSchema + + +class ComplexType < Info + def compoundtype + @compoundtype ||= check_type + end + + def check_type + if content + :TYPE_STRUCT + elsif complexcontent and complexcontent.base == ::SOAP::ValueArrayName + :TYPE_ARRAY + else + raise NotImplementedError.new("Unknown kind of complexType.") + end + end + + def child_type(name = nil) + case compoundtype + when :TYPE_STRUCT + if ele = find_element(name) + ele.type + elsif ele = find_element_by_name(name.name) + ele.type + else + nil + end + when :TYPE_ARRAY + @contenttype ||= content_arytype + end + end + + def child_defined_complextype(name) + unless compoundtype == :TYPE_STRUCT + raise RuntimeError.new("Assert: not for struct") + end + unless ele = find_element(name) + if name.namespace.nil? + ele = find_element_by_name(name.name) + end + end + unless ele + raise RuntimeError.new("Cannot find #{name} as a children of #{@name}.") + end + ele.local_complextype + end + + def find_arytype + complexcontent.attributes.each do |attribute| + if attribute.ref == ::SOAP::AttrArrayTypeName + return attribute.arytype + end + end + nil + end + +private + + def content_arytype + unless compoundtype == :TYPE_ARRAY + raise RuntimeError.new("Assert: not for array") + end + arytype = find_arytype + ns = arytype.namespace + name = arytype.name.sub(/\[(?:,)*\]$/, '') + XSD::QName.new(ns, name) + end +end + + +end +end diff --git a/lib/wsdl/soap/data.rb b/lib/wsdl/soap/data.rb new file mode 100644 index 0000000000..301ae9951d --- /dev/null +++ b/lib/wsdl/soap/data.rb @@ -0,0 +1,52 @@ +=begin +WSDL4R - WSDL SOAP binding data definitions. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'xsd/qname' +require 'wsdl/soap/definitions' +require 'wsdl/soap/binding' +require 'wsdl/soap/operation' +require 'wsdl/soap/body' +require 'wsdl/soap/header' +require 'wsdl/soap/headerfault' +require 'wsdl/soap/fault' +require 'wsdl/soap/address' +require 'wsdl/soap/complexType' + + +module WSDL +module SOAP + + +HeaderFaultName = XSD::QName.new(SOAPBindingNamespace, 'headerfault') + +LocationAttrName = XSD::QName.new(nil, 'location') +StyleAttrName = XSD::QName.new(nil, 'style') +TransportAttrName = XSD::QName.new(nil, 'transport') +UseAttrName = XSD::QName.new(nil, 'use') +PartsAttrName = XSD::QName.new(nil, 'parts') +PartAttrName = XSD::QName.new(nil, 'part') +NameAttrName = XSD::QName.new(nil, 'name') +MessageAttrName = XSD::QName.new(nil, 'message') +EncodingStyleAttrName = XSD::QName.new(nil, 'encodingStyle') +NamespaceAttrName = XSD::QName.new(nil, 'namespace') +SOAPActionAttrName = XSD::QName.new(nil, 'soapAction') + + +end +end diff --git a/lib/wsdl/soap/definitions.rb b/lib/wsdl/soap/definitions.rb new file mode 100644 index 0000000000..08df0dcc68 --- /dev/null +++ b/lib/wsdl/soap/definitions.rb @@ -0,0 +1,130 @@ +=begin +WSDL4R - WSDL additional definitions for SOAP. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' +require 'soap/mapping' + + +module WSDL + + +class Definitions < Info + def soap_rpc_complextypes(binding) + types = rpc_operation_complextypes(binding) + types << array_complextype + types << fault_complextype + types << exception_complextype + types + end + +private + + def rpc_operation_complextypes(binding) + types = XSD::NamedElements.new + binding.operations.each do |op_bind| + if op_bind_rpc?(op_bind) + operation = op_bind.find_operation + if op_bind.input + type = XMLSchema::ComplexType.new(operation_input_name(operation)) + message = messages[operation.input.message] + type.sequence_elements = elements_from_message(message) + types << type + end + if op_bind.output + type = XMLSchema::ComplexType.new(operation_output_name(operation)) + message = messages[operation.output.message] + type.sequence_elements = elements_from_message(message) + types << type + end + end + end + types + end + + def operation_input_name(operation) + operation.input.name || operation.name + end + + def operation_output_name(operation) + operation.output.name || + XSD::QName.new(operation.name.namespace, operation.name.name + "Response") + end + + def op_bind_rpc?(op_bind) + op_bind.soapoperation and op_bind.soapoperation.operation_style == :rpc + end + + def elements_from_message(message) + message.parts.collect { |part| + qname = XSD::QName.new(nil, part.name) + XMLSchema::Element.new(qname, part.type) + } + end + + def array_complextype + type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName) + type.complexcontent = XMLSchema::ComplexContent.new + type.complexcontent.base = ::SOAP::ValueArrayName + attr = XMLSchema::Attribute.new + attr.ref = ::SOAP::AttrArrayTypeName + anytype = XSD::AnyTypeName.dup + anytype.name += '[]' + attr.arytype = anytype + type.complexcontent.attributes << attr + type + end + +=begin + + + + + + + + +=end + def fault_complextype + type = XMLSchema::ComplexType.new(::SOAP::EleFaultName) + faultcode = XMLSchema::Element.new(::SOAP::EleFaultCodeName, XSD::XSDQName::Type) + faultstring = XMLSchema::Element.new(::SOAP::EleFaultStringName, XSD::XSDString::Type) + faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type) + faultactor.minoccurs = 0 + detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName) + detail.minoccurs = 0 + type.all_elements = [faultcode, faultstring, faultactor, detail] + type.final = 'extension' + type + end + + def exception_complextype + type = XMLSchema::ComplexType.new(XSD::QName.new( + ::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException')) + excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'exceptionTypeName'), XSD::XSDString::Type) + cause = XMLSchema::Element.new(XSD::QName.new(nil, 'cause'), XSD::AnyTypeName) + backtrace = XMLSchema::Element.new(XSD::QName.new(nil, 'backtrace'), ::SOAP::ValueArrayName) + message = XMLSchema::Element.new(XSD::QName.new(nil, 'message'), XSD::XSDString::Type) + type.all_elements = [excn_name, cause, backtrace, message] + type + end +end + + +end diff --git a/lib/wsdl/soap/fault.rb b/lib/wsdl/soap/fault.rb new file mode 100644 index 0000000000..eb57cb0233 --- /dev/null +++ b/lib/wsdl/soap/fault.rb @@ -0,0 +1,63 @@ +=begin +WSDL4R - WSDL SOAP body definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Fault < Info + attr_reader :name # required + attr_reader :use # required + attr_reader :encodingstyle + attr_reader :namespace + + def initialize + super + @name = nil + @use = nil + @encodingstyle = nil + @namespace = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = value + when UseAttrName + @use = value + when EncodingStyleAttrName + @encodingstyle = value + when NamespaceAttrName + @namespace = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/header.rb b/lib/wsdl/soap/header.rb new file mode 100644 index 0000000000..f779ba5c08 --- /dev/null +++ b/lib/wsdl/soap/header.rb @@ -0,0 +1,90 @@ +=begin +WSDL4R - WSDL SOAP body definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Header < Info + attr_reader :headerfault + + attr_reader :message # required + attr_reader :part # required + attr_reader :use # required + attr_reader :encodingstyle + attr_reader :namespace + + def initialize + super + @message = nil + @part = nil + @use = nil + @encodingstyle = nil + @namespace = nil + @headerfault = nil + end + + def find_message + root.message(@message) + end + + def find_part + find_message.parts.each do |part| + if part.name == @part + return part + end + end + nil + end + + def parse_element(element) + case element + when HeaderFaultName + o = WSDL::SOAP::HeaderFault.new + @headerfault = o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when MessageAttrName + @message = value + when PartAttrName + @part = value + when UseAttrName + @use = value + when EncodingStyleAttrName + @encodingstyle = value + when NamespaceAttrName + @namespace = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/headerfault.rb b/lib/wsdl/soap/headerfault.rb new file mode 100644 index 0000000000..c0d58e2230 --- /dev/null +++ b/lib/wsdl/soap/headerfault.rb @@ -0,0 +1,67 @@ +=begin +WSDL4R - WSDL SOAP body definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class HeaderFault < Info + attr_reader :message # required + attr_reader :part # required + attr_reader :use # required + attr_reader :encodingstyle + attr_reader :namespace + + def initialize + super + @message = nil + @part = nil + @use = nil + @encodingstyle = nil + @namespace = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when MessageAttrName + @message = value + when PartAttrName + @part = value + when UseAttrName + @use = value + when EncodingStyleAttrName + @encodingstyle = value + when NamespaceAttrName + @namespace = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/soap/operation.rb b/lib/wsdl/soap/operation.rb new file mode 100644 index 0000000000..2e88522f5c --- /dev/null +++ b/lib/wsdl/soap/operation.rb @@ -0,0 +1,131 @@ +=begin +WSDL4R - WSDL SOAP operation definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module SOAP + + +class Operation < Info + class OperationInfo + attr_reader :style + attr_reader :op_name + attr_reader :optype_name + attr_reader :headerparts + attr_reader :bodyparts + attr_reader :faultpart + attr_reader :soapaction + + def initialize(style, op_name, optype_name, headerparts, bodyparts, faultpart, soapaction) + @style = style + @op_name = op_name + @optype_name = optype_name + @headerparts = headerparts + @bodyparts = bodyparts + @faultpart = faultpart + @soapaction = soapaction + end + end + + attr_reader :soapaction + attr_reader :style + + def initialize + super + @soapaction = nil + @style = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when StyleAttrName + if ["document", "rpc"].include?(value) + @style = value.intern + else + raise AttributeConstraintError.new("Unexpected value #{ value }.") + end + when SOAPActionAttrName + @soapaction = value + else + nil + end + end + + def input_info + name_info = parent.find_operation.input_info + param_info(name_info, parent.input) + end + + def output_info + name_info = parent.find_operation.output_info + param_info(name_info, parent.output) + end + + def operation_style + return @style if @style + if parent_binding.soapbinding + return parent_binding.soapbinding.style + end + nil + end + +private + + def parent_binding + parent.parent + end + + def param_info(name_info, param) + op_name = name_info.op_name + optype_name = name_info.optype_name + + soapheader = param.soapheader + headerparts = soapheader.collect { |item| item.find_part } + + soapbody = param.soapbody + if soapbody.encodingstyle and + soapbody.encodingstyle != ::SOAP::EncodingNamespace + raise NotImplementedError.new( + "EncodingStyle '#{ soapbody.encodingstyle }' not supported.") + end + if soapbody.namespace + op_name = op_name.dup + op_name.namespace = soapbody.namespace + end + if soapbody.parts + raise NotImplementedError.new("soap:body parts") + else + bodyparts = name_info.parts + end + + faultpart = nil + soapaction = parent.soapoperation.soapaction + OperationInfo.new(operation_style, op_name, optype_name, headerparts, bodyparts, faultpart, soapaction) + end +end + + +end +end diff --git a/lib/wsdl/types.rb b/lib/wsdl/types.rb new file mode 100644 index 0000000000..420ab8d387 --- /dev/null +++ b/lib/wsdl/types.rb @@ -0,0 +1,54 @@ +=begin +WSDL4R - WSDL types definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL + + +class Types < Info + attr_reader :schemas + + def initialize + super + @schemas = [] + end + + def parse_element(element) + case element + when SchemaName + o = XMLSchema::Schema.new + @schemas << o + o + when DocumentationName + o = Documentation.new + o + else + nil + end + end + + def parse_attr(attr, value) + nil + end +end + + +end diff --git a/lib/wsdl/wsdl.rb b/lib/wsdl/wsdl.rb new file mode 100644 index 0000000000..23fd764065 --- /dev/null +++ b/lib/wsdl/wsdl.rb @@ -0,0 +1,34 @@ +=begin +WSDL4R - Base definitions. +Copyright (C) 2000, 2001, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'xsd/qname' + + +module WSDL + + +Version = '0.0.2' + +Namespace = 'http://schemas.xmlsoap.org/wsdl/' +SOAPBindingNamespace ='http://schemas.xmlsoap.org/wsdl/soap/' + +class Error < StandardError; end + + +end diff --git a/lib/wsdl/xmlSchema/all.rb b/lib/wsdl/xmlSchema/all.rb new file mode 100644 index 0000000000..7db0fbc939 --- /dev/null +++ b/lib/wsdl/xmlSchema/all.rb @@ -0,0 +1,76 @@ +=begin +WSDL4R - XMLSchema complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class All < Info + attr_reader :minoccurs + attr_reader :maxoccurs + attr_reader :elements + + def initialize + super() + @minoccurs = 1 + @maxoccurs = 1 + @elements = [] + end + + def targetnamespace + parent.targetnamespace + end + + def <<(element) + @elements << element + end + + def parse_element(element) + case element + when AnyName + o = Any.new + @elements << o + o + when ElementName + o = Element.new + @elements << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when MaxOccursAttrName + @maxoccurs = value + when MinOccursAttrName + @minoccurs = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/any.rb b/lib/wsdl/xmlSchema/any.rb new file mode 100644 index 0000000000..46904c4107 --- /dev/null +++ b/lib/wsdl/xmlSchema/any.rb @@ -0,0 +1,67 @@ +=begin +WSDL4R - XMLSchema any definition for WSDL. +Copyright (C) 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Any < Info + attr_accessor :maxoccurs + attr_accessor :minoccurs + attr_accessor :namespace + attr_accessor :process_contents + + def initialize + super() + @maxoccurs = 1 + @minoccurs = 1 + @namespace = '##any' + @process_contents = 'strict' + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when MaxOccursAttrName + @maxoccurs = value + when MinOccursAttrName + @minoccurs = value + when NamespaceAttrName + @namespace = value + when ProcessContentsAttrName + @process_contents = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/attribute.rb b/lib/wsdl/xmlSchema/attribute.rb new file mode 100644 index 0000000000..08cc9e931b --- /dev/null +++ b/lib/wsdl/xmlSchema/attribute.rb @@ -0,0 +1,85 @@ +=begin +WSDL4R - XMLSchema attribute definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Attribute < Info + attr_accessor :ref + attr_accessor :use + attr_accessor :form + attr_accessor :name + attr_accessor :type + attr_accessor :default + attr_accessor :fixed + + attr_accessor :arytype + + def initialize + super + @ref = nil + @use = nil + @form = nil + @name = nil + @type = nil + @default = nil + @fixed = nil + + @arytype = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when RefAttrName + @ref = value + when UseAttrName + @use = value + when FormAttrName + @form = value + when NameAttrName + @name = value + when TypeAttrName + @type = value + when DefaultAttrName + @default = value + when FixedAttrName + @fixed = value + when ArrayTypeAttrName + @arytype = if value.is_a?(XSD::QName) + value + else + XSD::QName.new(XSD::Namespace, value) + end + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/choice.rb b/lib/wsdl/xmlSchema/choice.rb new file mode 100644 index 0000000000..f31e93b3f1 --- /dev/null +++ b/lib/wsdl/xmlSchema/choice.rb @@ -0,0 +1,76 @@ +=begin +WSDL4R - XMLSchema complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Choice < Info + attr_reader :minoccurs + attr_reader :maxoccurs + attr_reader :elements + + def initialize + super() + @minoccurs = 1 + @maxoccurs = 1 + @elements = [] + end + + def targetnamespace + parent.targetnamespace + end + + def <<(element) + @elements << element + end + + def parse_element(element) + case element + when AnyName + o = Any.new + @elements << o + o + when ElementName + o = Element.new + @elements << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when MaxOccursAttrName + @maxoccurs = value + when MinOccursAttrName + @minoccurs = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/complexContent.rb b/lib/wsdl/xmlSchema/complexContent.rb new file mode 100644 index 0000000000..79c231ac2d --- /dev/null +++ b/lib/wsdl/xmlSchema/complexContent.rb @@ -0,0 +1,90 @@ +=begin +WSDL4R - XMLSchema complexContent definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class ComplexContent < Info + attr_accessor :base + attr_reader :derivetype + attr_reader :content + attr_reader :attributes + + def initialize + super + @base = nil + @derivetype = nil + @content = nil + @attributes = XSD::NamedElements.new + end + + def parse_element(element) + case element + when RestrictionName, ExtensionName + @derivetype = element.name + self + when AllName + if @derivetype.nil? + raise Parser::ElementConstraintError.new("base attr not found.") + end + @content = All.new + @content + when SequenceName + if @derivetype.nil? + raise Parser::ElementConstraintError.new("base attr not found.") + end + @content = Sequence.new + @content + when ChoiceName + if @derivetype.nil? + raise Parser::ElementConstraintError.new("base attr not found.") + end + @content = Choice.new + @content + when AttributeName + if @derivetype.nil? + raise Parser::ElementConstraintError.new("base attr not found.") + end + o = Attribute.new + @attributes << o + o + end + end + + def parse_attr(attr, value) + if @derivetype.nil? + return nil + end + case attr + when BaseAttrName + @base = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/complexType.rb b/lib/wsdl/xmlSchema/complexType.rb new file mode 100644 index 0000000000..c34be3e57b --- /dev/null +++ b/lib/wsdl/xmlSchema/complexType.rb @@ -0,0 +1,130 @@ +=begin +WSDL4R - XMLSchema complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'wsdl/xmlSchema/content' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class ComplexType < Info + attr_accessor :name + attr_accessor :complexcontent + attr_accessor :content + attr_accessor :final + attr_accessor :mixed + attr_reader :attributes + + def initialize(name = nil) + super() + @name = name + @complexcontent = nil + @content = nil + @final = nil + @mixed = false + @attributes = XSD::NamedElements.new + end + + def targetnamespace + parent.targetnamespace + end + + def each_element + if @content + @content.elements.each do |element| + yield(element.name, element) + end + end + end + + def find_element(name) + if @content + @content.elements.each do |element| + return element if name == element.name + end + end + nil + end + + def find_element_by_name(name) + if @content + @content.elements.each do |element| + return element if name == element.name.name + end + end + nil + end + + def sequence_elements=(elements) + @content = Sequence.new + elements.each do |element| + @content << element + end + end + + def all_elements=(elements) + @content = All.new + elements.each do |element| + @content << element + end + end + + def parse_element(element) + case element + when AllName + @content = All.new + @content + when SequenceName + @content = Sequence.new + @content + when ChoiceName + @content = Choice.new + @content + when ComplexContentName + @complexcontent = ComplexContent.new + @complexcontent + when AttributeName + o = Attribute.new + @attributes << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when FinalAttrName + @final = value + when MixedAttrName + @mixed = (value == 'true') + when NameAttrName + @name = XSD::QName.new(targetnamespace, value) + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/content.rb b/lib/wsdl/xmlSchema/content.rb new file mode 100644 index 0000000000..a1bd302701 --- /dev/null +++ b/lib/wsdl/xmlSchema/content.rb @@ -0,0 +1,107 @@ +=begin +WSDL4R - XMLSchema complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Content < Info + attr_accessor :final + attr_accessor :mixed + attr_accessor :type + attr_reader :contents + attr_reader :elements + + def initialize + super() + @final = nil + @mixed = false + @type = nil + @contents = [] + @elements = [] + end + + def targetnamespace + parent.targetnamespace + end + + def <<(content) + @contents << content + update_elements + end + + def each + @contents.each do |content| + yield content + end + end + + def parse_element(element) + case element + when AllName, SequenceName, ChoiceName + o = Content.new + o.type = element.name + @contents << o + o + when AnyName + o = Any.new + @contents << o + o + when ElementName + o = Element.new + @contents << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when FinalAttrName + @final = value + when MixedAttrName + @mixed = (value == 'true') + else + nil + end + end + + def parse_epilogue + update_elements + end + +private + + def update_elements + @elements = [] + @contents.each do |content| + if content.is_a?(Element) + @elements << [content.name, content] + end + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/data.rb b/lib/wsdl/xmlSchema/data.rb new file mode 100644 index 0000000000..9c9820abbd --- /dev/null +++ b/lib/wsdl/xmlSchema/data.rb @@ -0,0 +1,75 @@ +=begin +WSDL4R - XMLSchema data definitions. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/xmlSchema/schema' +require 'wsdl/xmlSchema/import' +require 'wsdl/xmlSchema/complexType' +require 'wsdl/xmlSchema/complexContent' +require 'wsdl/xmlSchema/any' +require 'wsdl/xmlSchema/element' +require 'wsdl/xmlSchema/all' +require 'wsdl/xmlSchema/choice' +require 'wsdl/xmlSchema/sequence' +require 'wsdl/xmlSchema/attribute' +require 'wsdl/xmlSchema/unique' + + +module WSDL +module XMLSchema + + +AllName = XSD::QName.new(XSD::Namespace, 'all') +AnyName = XSD::QName.new(XSD::Namespace, 'any') +ArrayTypeAttrName = XSD::QName.new(Namespace, 'arrayType') +AttributeName = XSD::QName.new(XSD::Namespace, 'attribute') +ChoiceName = XSD::QName.new(XSD::Namespace, 'choice') +ComplexContentName = XSD::QName.new(XSD::Namespace, 'complexContent') +ComplexTypeName = XSD::QName.new(XSD::Namespace, 'complexType') +ElementName = XSD::QName.new(XSD::Namespace, 'element') +ExtensionName = XSD::QName.new(XSD::Namespace, 'extension') +ImportName = XSD::QName.new(XSD::Namespace, 'import') +RestrictionName = XSD::QName.new(XSD::Namespace, 'restriction') +SequenceName = XSD::QName.new(XSD::Namespace, 'sequence') +SchemaName = XSD::QName.new(XSD::Namespace, 'schema') +SimpleTypeName = XSD::QName.new(XSD::Namespace, 'simpleType') +UniqueName = XSD::QName.new(XSD::Namespace, 'unique') + +AttributeFormDefaultAttrName = XSD::QName.new(nil, 'attributeFormDefault') +BaseAttrName = XSD::QName.new(nil, 'base') +DefaultAttrName = XSD::QName.new(nil, 'default') +ElementFormDefaultAttrName = XSD::QName.new(nil, 'elementFormDefault') +FinalAttrName = XSD::QName.new(nil, 'final') +FixedAttrName = XSD::QName.new(nil, 'fixed') +FormAttrName = XSD::QName.new(nil, 'form') +IdAttrName = XSD::QName.new(nil, 'id') +MaxOccursAttrName = XSD::QName.new(nil, 'maxOccurs') +MinOccursAttrName = XSD::QName.new(nil, 'minOccurs') +MixedAttrName = XSD::QName.new(nil, 'mixed') +NameAttrName = XSD::QName.new(nil, 'name') +NamespaceAttrName = XSD::QName.new(nil, 'namespace') +NillableAttrName = XSD::QName.new(nil, 'nillable') +RefAttrName = XSD::QName.new(nil, 'ref') +SchemaLocationAttrName = XSD::QName.new(nil, 'schemaLocation') +TargetNamespaceAttrName = XSD::QName.new(nil, 'targetNamespace') +TypeAttrName = XSD::QName.new(nil, 'type') +UseAttrName = XSD::QName.new(nil, 'use') + + +end +end diff --git a/lib/wsdl/xmlSchema/element.rb b/lib/wsdl/xmlSchema/element.rb new file mode 100644 index 0000000000..d6d17c08cf --- /dev/null +++ b/lib/wsdl/xmlSchema/element.rb @@ -0,0 +1,115 @@ +=begin +WSDL4R - XMLSchema element definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Element < Info + attr_accessor :name # required + attr_accessor :type + attr_accessor :local_complextype + attr_accessor :constraint + attr_accessor :maxoccurs + attr_accessor :minoccurs + attr_accessor :nillable + + def initialize(name = nil, type = XSD::AnyTypeName) + super() + @name = name + @type = type + @local_complextype = nil + @constraint = nil + @maxoccurs = 1 + @minoccurs = 1 + @nillable = nil + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when ComplexTypeName + @type = nil + @local_complextype = ComplexType.new + @local_complextype + when UniqueName + @constraint = Unique.new + @constraint + else + nil + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + #@name = XSD::QName.new(nil, value) + @name = XSD::QName.new(targetnamespace, value) + when TypeAttrName + @type = if value.is_a?(XSD::QName) + value + else + XSD::QName.new(XSD::Namespace, value) + end + when MaxOccursAttrName + case parent + when All + if value != '1' + raise Parser::AttrConstraintError.new( + "Cannot parse #{ value } for #{ attr }.") + end + @maxoccurs = value + when Sequence + @maxoccurs = value + else + raise NotImplementedError.new + end + @maxoccurs + when MinOccursAttrName + case parent + when All + if ['0', '1'].include?(value) + @minoccurs = value + else + raise Parser::AttrConstraintError.new( + "Cannot parse #{ value } for #{ attr }.") + end + when Sequence + @minoccurs = value + else + raise NotImplementedError.new + end + @minoccurs + when NillableAttrName + @nillable = (value == 'true') + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/import.rb b/lib/wsdl/xmlSchema/import.rb new file mode 100644 index 0000000000..2267125a70 --- /dev/null +++ b/lib/wsdl/xmlSchema/import.rb @@ -0,0 +1,55 @@ +=begin +WSDL4R - XMLSchema import definition. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Import < Info + attr_reader :namespace + attr_reader :schemalocation + + def initialize + super + @namespace = nil + @schemalocation = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when NamespaceAttrName + @namespace = value + when SchemaLocationAttrName + @schemalocation = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/parser.rb b/lib/wsdl/xmlSchema/parser.rb new file mode 100644 index 0000000000..6e893cdc7e --- /dev/null +++ b/lib/wsdl/xmlSchema/parser.rb @@ -0,0 +1,172 @@ +=begin +WSDL4R - WSDL XML Instance parser library. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'xsd/qname' +require 'xsd/ns' +require 'xsd/charset' +require 'xsd/datatypes' +require 'xsd/xmlparser' +require 'wsdl/xmlSchema/data' + + +module WSDL +module XMLSchema + + +class Parser + include XSD + + class ParseError < Error; end + class FormatDecodeError < Error; end + class UnknownElementError < FormatDecodeError; end + class UnknownAttributeError < FormatDecodeError; end + class UnexpectedElementError < FormatDecodeError; end + class ElementConstraintError < FormatDecodeError; end + class AttributeConstraintError < FormatDecodeError; end + +private + + class ParseFrame + attr_reader :ns + attr_reader :name + attr_accessor :node + + private + + def initialize(ns, name, node) + @ns = ns + @name = name + @node = node + end + end + +public + + def initialize(opt = {}) + @parser = XSD::XMLParser.create_parser(self, opt) + @parsestack = nil + @lastnode = nil + end + + def parse(string_or_readable) + @parsestack = [] + @lastnode = nil + @textbuf = '' + @parser.do_parse(string_or_readable) + @lastnode + end + + def charset + @parser.charset + end + + def start_element(name, attrs) + lastframe = @parsestack.last + ns = parent = nil + if lastframe + ns = lastframe.ns.clone_ns + parent = lastframe.node + else + ns = XSD::NS.new + parent = nil + end + attrs = XSD::XMLParser.filter_ns(ns, attrs) + node = decode_tag(ns, name, attrs, parent) + @parsestack << ParseFrame.new(ns, name, node) + end + + def characters(text) + lastframe = @parsestack.last + if lastframe + # Need not to be cloned because character does not have attr. + ns = lastframe.ns + decode_text(ns, text) + else + p text if $DEBUG + end + end + + def end_element(name) + lastframe = @parsestack.pop + unless name == lastframe.name + raise UnexpectedElementError.new("Closing element name '#{ name }' does not match with opening element '#{ lastframe.name }'.") + end + decode_tag_end(lastframe.ns, lastframe.node) + @lastnode = lastframe.node + end + +private + + def decode_tag(ns, name, attrs, parent) + o = nil + element = ns.parse(name) + if !parent + if element == SchemaName + o = Schema.parse_element(element) + else + raise UnknownElementError.new("Unknown element #{ element }.") + end + else + o = parent.parse_element(element) + unless o + raise UnknownElementError.new("Unknown element #{ element }.") + end + o.parent = parent + end + attrs.each do |key, value| + attr = unless /:/ =~ key + XSD::QName.new(nil, key) + else + ns.parse(key) + end + value_ele = if /:/ !~ value + value + elsif /^http:\/\// =~ value # ToDo: ugly. + value + else + begin + ns.parse(value) + rescue + value + end + end + if attr == IdAttrName + o.id = value_ele + else + unless o.parse_attr(attr, value_ele) + STDERR.puts("Unknown attr #{ attr }.") + # raise UnknownAttributeError.new("Unknown attr #{ attr }.") + end + end + end + o + end + + def decode_tag_end(ns, node) + node.parse_epilogue + end + + def decode_text(ns, text) + @textbuf << text + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/schema.rb b/lib/wsdl/xmlSchema/schema.rb new file mode 100644 index 0000000000..3a9aa6842e --- /dev/null +++ b/lib/wsdl/xmlSchema/schema.rb @@ -0,0 +1,105 @@ +=begin +WSDL4R - XMLSchema schema definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class Schema < Info + attr_reader :targetnamespace # required + attr_reader :complextypes + attr_reader :elements + attr_reader :attributes + attr_reader :imports + attr_accessor :attributeformdefault + attr_accessor :elementformdefault + + def initialize + super + @targetnamespace = nil + @complextypes = XSD::NamedElements.new + @elements = XSD::NamedElements.new + @attributes = XSD::NamedElements.new + @imports = [] + @elementformdefault = nil + end + + def parse_element(element) + case element + when ImportName + o = Import.new + @imports << o + o + when ComplexTypeName + o = ComplexType.new + @complextypes << o + o + when ElementName + o = Element.new + @elements << o + o + when AttributeName + o = Attribute.new + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when TargetNamespaceAttrName + @targetnamespace = value + when AttributeFormDefaultAttrName + @attributeformdefault = value + when ElementFormDefaultAttrName + @elementformdefault = value + else + nil + end + end + + def collect_elements + result = XSD::NamedElements.new + result.concat(@elements) + result + end + + def collect_complextypes + result = XSD::NamedElements.new + result.concat(@complextypes) + result + end + + def self.parse_element(element) + if element == SchemaName + Schema.new + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/sequence.rb b/lib/wsdl/xmlSchema/sequence.rb new file mode 100644 index 0000000000..fb5ca1aef6 --- /dev/null +++ b/lib/wsdl/xmlSchema/sequence.rb @@ -0,0 +1,76 @@ +=begin +WSDL4R - XMLSchema complexType definition for WSDL. +Copyright (C) 2002, 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Sequence < Info + attr_reader :minoccurs + attr_reader :maxoccurs + attr_reader :elements + + def initialize + super() + @minoccurs = 1 + @maxoccurs = 1 + @elements = [] + end + + def targetnamespace + parent.targetnamespace + end + + def <<(element) + @elements << element + end + + def parse_element(element) + case element + when AnyName + o = Any.new + @elements << o + o + when ElementName + o = Element.new + @elements << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when MaxOccursAttrName + @maxoccurs = value + when MinOccursAttrName + @minoccurs = value + else + nil + end + end +end + + +end +end diff --git a/lib/wsdl/xmlSchema/unique.rb b/lib/wsdl/xmlSchema/unique.rb new file mode 100644 index 0000000000..1d2573f6b0 --- /dev/null +++ b/lib/wsdl/xmlSchema/unique.rb @@ -0,0 +1,45 @@ +=begin +WSDL4R - XMLSchema unique element. +Copyright (C) 2003 NAKAMURA, Hiroshi. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PRATICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 675 Mass +Ave, Cambridge, MA 02139, USA. +=end + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Unique < 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 -- cgit v1.2.3