diff options
Diffstat (limited to 'lib/wsdl/xmlSchema')
-rw-r--r-- | lib/wsdl/xmlSchema/all.rb | 76 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/any.rb | 67 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/attribute.rb | 85 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/choice.rb | 76 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/complexContent.rb | 90 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/complexType.rb | 130 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/content.rb | 107 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/data.rb | 75 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/element.rb | 115 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/import.rb | 55 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/parser.rb | 172 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/schema.rb | 105 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/sequence.rb | 76 | ||||
-rw-r--r-- | lib/wsdl/xmlSchema/unique.rb | 45 |
14 files changed, 1274 insertions, 0 deletions
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 |