1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nahi 2003-09-24 15:18:44 +00:00
parent 8c2fb77787
commit db9445103c
145 changed files with 20938 additions and 0 deletions

76
lib/wsdl/binding.rb Normal file
View file

@ -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

73
lib/wsdl/data.rb Normal file
View file

@ -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

233
lib/wsdl/definitions.rb Normal file
View file

@ -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

43
lib/wsdl/documentation.rb Normal file
View file

@ -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

81
lib/wsdl/import.rb Normal file
View file

@ -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

75
lib/wsdl/importer.rb Normal file
View file

@ -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

44
lib/wsdl/info.rb Normal file
View file

@ -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

65
lib/wsdl/message.rb Normal file
View file

@ -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

144
lib/wsdl/operation.rb Normal file
View file

@ -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

View file

@ -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

85
lib/wsdl/param.rb Normal file
View file

@ -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

170
lib/wsdl/parser.rb Normal file
View file

@ -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

63
lib/wsdl/part.rb Normal file
View file

@ -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

95
lib/wsdl/port.rb Normal file
View file

@ -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

83
lib/wsdl/portType.rb Normal file
View file

@ -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

72
lib/wsdl/service.rb Normal file
View file

@ -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

51
lib/wsdl/soap/address.rb Normal file
View file

@ -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

59
lib/wsdl/soap/binding.rb Normal file
View file

@ -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

63
lib/wsdl/soap/body.rb Normal file
View file

@ -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

View file

@ -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

52
lib/wsdl/soap/data.rb Normal file
View file

@ -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

View file

@ -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
<xs:complexType name="Fault" final="extension">
<xs:sequence>
<xs:element name="faultcode" type="xs:QName" />
<xs:element name="faultstring" type="xs:string" />
<xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
<xs:element name="detail" type="tns:detail" minOccurs="0" />
</xs:sequence>
</xs:complexType>
=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

63
lib/wsdl/soap/fault.rb Normal file
View file

@ -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

90
lib/wsdl/soap/header.rb Normal file
View file

@ -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

View file

@ -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

131
lib/wsdl/soap/operation.rb Normal file
View file

@ -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

54
lib/wsdl/types.rb Normal file
View file

@ -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

34
lib/wsdl/wsdl.rb Normal file
View file

@ -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

76
lib/wsdl/xmlSchema/all.rb Normal file
View file

@ -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

67
lib/wsdl/xmlSchema/any.rb Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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