diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:53:51 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:53:51 +0000 |
commit | 1e760c0be3ed35874204114e7454509f740c0fe2 (patch) | |
tree | a75eb2b1eea073830902d1fa49c568c4525c8b57 /ruby_1_8_6/lib/wsdl/xmlSchema | |
parent | a2055d63b41a6678dc7aeb17d0bece314e700c5a (diff) |
add tag v1_8_6_71v1_8_5_71
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_71@13189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_6/lib/wsdl/xmlSchema')
25 files changed, 2013 insertions, 0 deletions
diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/all.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/all.rb new file mode 100644 index 0000000000..bb9566feac --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/all.rb @@ -0,0 +1,69 @@ +# WSDL4R - XMLSchema complexType definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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 elementformdefault + parent.elementformdefault + 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.source + when MinOccursAttrName + @minoccurs = value.source + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/annotation.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/annotation.rb new file mode 100644 index 0000000000..633bd196f1 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/annotation.rb @@ -0,0 +1,34 @@ +# WSDL4R - WSDL SOAP documentation element. +# Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Annotation < Info + def initialize + super + end + + def parse_element(element) + # Accepts any element. + self + end + + def parse_attr(attr, value) + # Accepts any attribute. + true + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/any.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/any.rb new file mode 100644 index 0000000000..72d25e8dde --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/any.rb @@ -0,0 +1,56 @@ +# WSDL4R - XMLSchema any definition for WSDL. +# Copyright (C) 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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.source + when MinOccursAttrName + @minoccurs = value.source + when NamespaceAttrName + @namespace = value.source + when ProcessContentsAttrName + @process_contents = value.source + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/attribute.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/attribute.rb new file mode 100644 index 0000000000..f9048661a2 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/attribute.rb @@ -0,0 +1,127 @@ +# WSDL4R - XMLSchema attribute definition for WSDL. +# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Attribute < Info + class << self + if RUBY_VERSION > "1.7.0" + def attr_reader_ref(symbol) + name = symbol.to_s + define_method(name) { + instance_variable_get("@#{name}") || + (refelement ? refelement.__send__(name) : nil) + } + end + else + def attr_reader_ref(symbol) + name = symbol.to_s + module_eval <<-EOS + def #{name} + @#{name} || (refelement ? refelement.#{name} : nil) + end + EOS + end + end + end + + attr_writer :use + attr_writer :form + attr_writer :name + attr_writer :type + attr_writer :local_simpletype + attr_writer :default + attr_writer :fixed + + attr_reader_ref :use + attr_reader_ref :form + attr_reader_ref :name + attr_reader_ref :type + attr_reader_ref :local_simpletype + attr_reader_ref :default + attr_reader_ref :fixed + + attr_accessor :ref + attr_accessor :arytype + + def initialize + super + @use = nil + @form = nil + @name = nil + @type = nil + @local_simpletype = nil + @default = nil + @fixed = nil + @ref = nil + @refelement = nil + @arytype = nil + end + + def refelement + @refelement ||= root.collect_attributes[@ref] + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when SimpleTypeName + @local_simpletype = SimpleType.new + @local_simpletype + end + end + + def parse_attr(attr, value) + case attr + when RefAttrName + @ref = value + when UseAttrName + @use = value.source + when FormAttrName + @form = value.source + when NameAttrName + if directelement? + @name = XSD::QName.new(targetnamespace, value.source) + else + @name = XSD::QName.new(nil, value.source) + end + when TypeAttrName + @type = value + when DefaultAttrName + @default = value.source + when FixedAttrName + @fixed = value.source + when ArrayTypeAttrName + @arytype = if value.namespace.nil? + XSD::QName.new(XSD::Namespace, value.source) + else + value + end + else + nil + end + end + +private + + def directelement? + parent.is_a?(Schema) + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/choice.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/choice.rb new file mode 100644 index 0000000000..f6d27fa38c --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/choice.rb @@ -0,0 +1,69 @@ +# WSDL4R - XMLSchema complexType definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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 elementformdefault + parent.elementformdefault + 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.source + when MinOccursAttrName + @minoccurs = value.source + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/complexContent.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/complexContent.rb new file mode 100644 index 0000000000..f7fb6c16b4 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/complexContent.rb @@ -0,0 +1,92 @@ +# WSDL4R - XMLSchema complexContent definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class 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 + @basetype = nil + end + + def targetnamespace + parent.targetnamespace + end + + def elementformdefault + parent.elementformdefault + end + + def basetype + @basetype ||= root.collect_complextypes[@base] + 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/ruby_1_8_6/lib/wsdl/xmlSchema/complexType.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/complexType.rb new file mode 100644 index 0000000000..dc9ec954fc --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/complexType.rb @@ -0,0 +1,139 @@ +# WSDL4R - XMLSchema complexType definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'wsdl/xmlSchema/content' +require 'wsdl/xmlSchema/element' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class ComplexType < Info + attr_accessor :name + attr_accessor :complexcontent + attr_accessor :simplecontent + attr_reader :content + attr_accessor :final + attr_accessor :mixed + attr_reader :attributes + + def initialize(name = nil) + super() + @name = name + @complexcontent = nil + @simplecontent = nil + @content = nil + @final = nil + @mixed = false + @attributes = XSD::NamedElements.new + end + + def targetnamespace + # inner elements can be qualified + # parent.is_a?(WSDL::XMLSchema::Element) ? nil : parent.targetnamespace + parent.targetnamespace + end + + def elementformdefault + parent.elementformdefault + end + + AnyAsElement = Element.new(XSD::QName.new(nil, 'any'), XSD::AnyTypeName) + def each_element + if content + content.elements.each do |element| + if element.is_a?(Any) + yield(AnyAsElement) + else + yield(element) + end + end + end + end + + def find_element(name) + if content + content.elements.each do |element| + if element.is_a?(Any) + return AnyAsElement if name == AnyAsElement.name + else + return element if name == element.name + end + end + end + nil + end + + def find_element_by_name(name) + if content + content.elements.each do |element| + if element.is_a?(Any) + return AnyAsElement if name == AnyAsElement.name.name + else + return element if name == element.name.name + end + 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 + when SequenceName + @content = Sequence.new + when ChoiceName + @content = Choice.new + when ComplexContentName + @complexcontent = ComplexContent.new + when SimpleContentName + @simplecontent = SimpleContent.new + when AttributeName + o = Attribute.new + @attributes << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when FinalAttrName + @final = value.source + when MixedAttrName + @mixed = (value.source == 'true') + when NameAttrName + @name = XSD::QName.new(targetnamespace, value.source) + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/content.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/content.rb new file mode 100644 index 0000000000..2f1dfb4b6c --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/content.rb @@ -0,0 +1,96 @@ +# WSDL4R - XMLSchema complexType definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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.source + when MixedAttrName + @mixed = (value.source == '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/ruby_1_8_6/lib/wsdl/xmlSchema/data.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/data.rb new file mode 100644 index 0000000000..23ab1adf0b --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/data.rb @@ -0,0 +1,80 @@ +# WSDL4R - XMLSchema data definitions. +# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'xsd/datatypes' +require 'wsdl/xmlSchema/annotation' +require 'wsdl/xmlSchema/schema' +require 'wsdl/xmlSchema/import' +require 'wsdl/xmlSchema/include' +require 'wsdl/xmlSchema/simpleType' +require 'wsdl/xmlSchema/simpleRestriction' +require 'wsdl/xmlSchema/simpleExtension' +require 'wsdl/xmlSchema/complexType' +require 'wsdl/xmlSchema/complexContent' +require 'wsdl/xmlSchema/simpleContent' +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' +require 'wsdl/xmlSchema/enumeration' +require 'wsdl/xmlSchema/length' +require 'wsdl/xmlSchema/pattern' + +module WSDL +module XMLSchema + + +AllName = XSD::QName.new(XSD::Namespace, 'all') +AnnotationName = XSD::QName.new(XSD::Namespace, 'annotation') +AnyName = XSD::QName.new(XSD::Namespace, 'any') +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') +EnumerationName = XSD::QName.new(XSD::Namespace, 'enumeration') +ExtensionName = XSD::QName.new(XSD::Namespace, 'extension') +ImportName = XSD::QName.new(XSD::Namespace, 'import') +IncludeName = XSD::QName.new(XSD::Namespace, 'include') +LengthName = XSD::QName.new(XSD::Namespace, 'length') +PatternName = XSD::QName.new(XSD::Namespace, 'pattern') +RestrictionName = XSD::QName.new(XSD::Namespace, 'restriction') +SequenceName = XSD::QName.new(XSD::Namespace, 'sequence') +SchemaName = XSD::QName.new(XSD::Namespace, 'schema') +SimpleContentName = XSD::QName.new(XSD::Namespace, 'simpleContent') +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') +ProcessContentsAttrName = XSD::QName.new(nil, 'processContents') +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') +ValueAttrName = XSD::QName.new(nil, 'value') + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/element.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/element.rb new file mode 100644 index 0000000000..fffb6485d0 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/element.rb @@ -0,0 +1,154 @@ +# WSDL4R - XMLSchema element definition for WSDL. +# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Element < Info + class << self + if RUBY_VERSION > "1.7.0" + def attr_reader_ref(symbol) + name = symbol.to_s + define_method(name) { + instance_variable_get("@#{name}") || + (refelement ? refelement.__send__(name) : nil) + } + end + else + def attr_reader_ref(symbol) + name = symbol.to_s + module_eval <<-EOS + def #{name} + @#{name} || (refelement ? refelement.#{name} : nil) + end + EOS + end + end + end + + attr_writer :name # required + attr_writer :form + attr_writer :type + attr_writer :local_simpletype + attr_writer :local_complextype + attr_writer :constraint + attr_writer :maxoccurs + attr_writer :minoccurs + attr_writer :nillable + + attr_reader_ref :name + attr_reader_ref :form + attr_reader_ref :type + attr_reader_ref :local_simpletype + attr_reader_ref :local_complextype + attr_reader_ref :constraint + attr_reader_ref :maxoccurs + attr_reader_ref :minoccurs + attr_reader_ref :nillable + + attr_accessor :ref + + def initialize(name = nil, type = nil) + super() + @name = name + @form = nil + @type = type + @local_simpletype = @local_complextype = nil + @constraint = nil + @maxoccurs = '1' + @minoccurs = '1' + @nillable = nil + @ref = nil + @refelement = nil + end + + def refelement + @refelement ||= (@ref ? root.collect_elements[@ref] : nil) + end + + def targetnamespace + parent.targetnamespace + end + + def elementformdefault + parent.elementformdefault + end + + def elementform + self.form.nil? ? parent.elementformdefault : self.form + end + + def parse_element(element) + case element + when SimpleTypeName + @local_simpletype = SimpleType.new + @local_simpletype + 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 + # namespace may be nil + if directelement? or elementform == 'qualified' + @name = XSD::QName.new(targetnamespace, value.source) + else + @name = XSD::QName.new(nil, value.source) + end + when FormAttrName + @form = value.source + when TypeAttrName + @type = value + when RefAttrName + @ref = value + when MaxOccursAttrName + if parent.is_a?(All) + if value.source != '1' + raise Parser::AttrConstraintError.new( + "cannot parse #{value} for #{attr}") + end + end + @maxoccurs = value.source + when MinOccursAttrName + if parent.is_a?(All) + unless ['0', '1'].include?(value.source) + raise Parser::AttrConstraintError.new( + "cannot parse #{value} for #{attr}") + end + end + @minoccurs = value.source + when NillableAttrName + @nillable = (value.source == 'true') + else + nil + end + end + +private + + def directelement? + parent.is_a?(Schema) + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/enumeration.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/enumeration.rb new file mode 100644 index 0000000000..5a16476032 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/enumeration.rb @@ -0,0 +1,36 @@ +# WSDL4R - XMLSchema enumeration definition for WSDL. +# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Enumeration < Info + def initialize + super + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when ValueAttrName + parent.enumeration << value.source + value.source + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/import.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/import.rb new file mode 100644 index 0000000000..d3487af934 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/import.rb @@ -0,0 +1,65 @@ +# WSDL4R - XMLSchema import definition. +# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'wsdl/xmlSchema/importer' + + +module WSDL +module XMLSchema + + +class Import < Info + attr_reader :namespace + attr_reader :schemalocation + attr_reader :content + + def initialize + super + @namespace = nil + @schemalocation = nil + @content = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when NamespaceAttrName + @namespace = value.source + when SchemaLocationAttrName + @schemalocation = URI.parse(value.source) + if @schemalocation.relative? and !parent.location.nil? and + !parent.location.relative? + @schemalocation = parent.location + @schemalocation + end + if root.importedschema.key?(@schemalocation) + @content = root.importedschema[@schemalocation] + else + root.importedschema[@schemalocation] = nil # placeholder + @content = import(@schemalocation) + root.importedschema[@schemalocation] = @content + end + @schemalocation + else + nil + end + end + +private + + def import(location) + Importer.import(location, root) + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/importer.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/importer.rb new file mode 100644 index 0000000000..f57bfd972a --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/importer.rb @@ -0,0 +1,87 @@ +# WSDL4R - XSD importer library. +# Copyright (C) 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'soap/httpconfigloader' +require 'wsdl/xmlSchema/parser' + + +module WSDL +module XMLSchema + + +class Importer + def self.import(location, originalroot = nil) + new.import(location, originalroot) + end + + def initialize + @web_client = nil + end + + def import(location, originalroot = nil) + unless location.is_a?(URI) + location = URI.parse(location) + end + content = parse(fetch(location), location, originalroot) + content.location = location + content + end + +private + + def parse(content, location, originalroot) + opt = { + :location => location, + :originalroot => originalroot + } + WSDL::XMLSchema::Parser.new(opt).parse(content) + end + + def fetch(location) + warn("importing: #{location}") if $DEBUG + content = nil + if location.scheme == 'file' or + (location.relative? and FileTest.exist?(location.path)) + content = File.open(location.path).read + elsif location.scheme and location.scheme.size == 1 and + FileTest.exist?(location.to_s) + # ToDo: remove this ugly workaround for a path with drive letter + # (D://foo/bar) + content = File.open(location.to_s).read + else + client = web_client.new(nil, "WSDL4R") + client.proxy = ::SOAP::Env::HTTP_PROXY + client.no_proxy = ::SOAP::Env::NO_PROXY + if opt = ::SOAP::Property.loadproperty(::SOAP::PropertyName) + ::SOAP::HTTPConfigLoader.set_options(client, + opt["client.protocol.http"]) + end + content = client.get_content(location) + end + content + end + + def web_client + @web_client ||= begin + require 'http-access2' + if HTTPAccess2::VERSION < "2.0" + raise LoadError.new("http-access/2.0 or later is required.") + end + HTTPAccess2::Client + rescue LoadError + warn("Loading http-access2 failed. Net/http is used.") if $DEBUG + require 'soap/netHttpClient' + ::SOAP::NetHttpClient + end + @web_client + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/include.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/include.rb new file mode 100644 index 0000000000..af1ef942bb --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/include.rb @@ -0,0 +1,54 @@ +# WSDL4R - XMLSchema include definition. +# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'wsdl/xmlSchema/importer' + + +module WSDL +module XMLSchema + + +class Include < Info + attr_reader :schemalocation + attr_reader :content + + def initialize + super + @schemalocation = nil + @content = nil + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when SchemaLocationAttrName + @schemalocation = URI.parse(value.source) + if @schemalocation.relative? + @schemalocation = parent.location + @schemalocation + end + @content = import(@schemalocation) + @schemalocation + else + nil + end + end + +private + + def import(location) + Importer.import(location) + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/length.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/length.rb new file mode 100644 index 0000000000..7f61602da9 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/length.rb @@ -0,0 +1,35 @@ +# WSDL4R - XMLSchema length definition for WSDL. +# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Length < Info + def initialize + super + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when ValueAttrName + value.source + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/parser.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/parser.rb new file mode 100644 index 0000000000..057d9d9b70 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/parser.rb @@ -0,0 +1,166 @@ +# WSDL4R - WSDL XML Instance parser library. +# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require '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 < 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 + @ignored = {} + @location = opt[:location] + @originalroot = opt[:originalroot] + 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 + elename = ns.parse(name) + if !parent + if elename == SchemaName + o = Schema.parse_element(elename) + o.location = @location + else + raise UnknownElementError.new("unknown element: #{elename}") + end + o.root = @originalroot if @originalroot # o.root = o otherwise + else + if elename == AnnotationName + # only the first annotation element is allowed for each element. + o = Annotation.new + else + o = parent.parse_element(elename) + end + unless o + unless @ignored.key?(elename) + warn("ignored element: #{elename} of #{parent.class}") + @ignored[elename] = elename + end + o = Documentation.new # which accepts any element. + end + # node could be a pseudo element. pseudo element has its own parent. + o.root = parent.root + o.parent = parent if o.parent.nil? + end + attrs.each do |key, value| + attr_ele = ns.parse(key, true) + value_ele = ns.parse(value, true) + value_ele.source = value # for recovery; value may not be a QName + if attr_ele == IdAttrName + o.id = value_ele + else + unless o.parse_attr(attr_ele, value_ele) + unless @ignored.key?(attr_ele) + warn("ignored attr: #{attr_ele}") + @ignored[attr_ele] = attr_ele + end + 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/ruby_1_8_6/lib/wsdl/xmlSchema/pattern.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/pattern.rb new file mode 100644 index 0000000000..f826be4578 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/pattern.rb @@ -0,0 +1,36 @@ +# WSDL4R - XMLSchema pattern definition for WSDL. +# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class Pattern < Info + def initialize + super + end + + def parse_element(element) + nil + end + + def parse_attr(attr, value) + case attr + when ValueAttrName + parent.pattern = /\A#{value.source}\z/n + value.source + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/schema.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/schema.rb new file mode 100644 index 0000000000..ec97d07aa5 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/schema.rb @@ -0,0 +1,143 @@ +# WSDL4R - XMLSchema schema definition for WSDL. +# Copyright (C) 2002, 2003-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class Schema < Info + attr_reader :targetnamespace # required + attr_reader :complextypes + attr_reader :simpletypes + attr_reader :elements + attr_reader :attributes + attr_reader :imports + attr_accessor :attributeformdefault + attr_accessor :elementformdefault + + attr_reader :importedschema + + def initialize + super + @targetnamespace = nil + @complextypes = XSD::NamedElements.new + @simpletypes = XSD::NamedElements.new + @elements = XSD::NamedElements.new + @attributes = XSD::NamedElements.new + @imports = [] + @attributeformdefault = "unqualified" + @elementformdefault = "unqualified" + @importedschema = {} + @location = nil + @root = self + end + + def location + @location || (root.nil? ? nil : root.location) + end + + def location=(location) + @location = location + end + + def parse_element(element) + case element + when ImportName + o = Import.new + @imports << o + o + when IncludeName + o = Include.new + @imports << o + o + when ComplexTypeName + o = ComplexType.new + @complextypes << o + o + when SimpleTypeName + o = SimpleType.new + @simpletypes << o + o + when ElementName + o = Element.new + @elements << o + o + when AttributeName + o = Attribute.new + @attributes << o + o + else + nil + end + end + + def parse_attr(attr, value) + case attr + when TargetNamespaceAttrName + @targetnamespace = value.source + when AttributeFormDefaultAttrName + @attributeformdefault = value.source + when ElementFormDefaultAttrName + @elementformdefault = value.source + else + nil + end + end + + def collect_attributes + result = XSD::NamedElements.new + result.concat(@attributes) + @imports.each do |import| + result.concat(import.content.collect_attributes) if import.content + end + result + end + + def collect_elements + result = XSD::NamedElements.new + result.concat(@elements) + @imports.each do |import| + result.concat(import.content.collect_elements) if import.content + end + result + end + + def collect_complextypes + result = XSD::NamedElements.new + result.concat(@complextypes) + @imports.each do |import| + result.concat(import.content.collect_complextypes) if import.content + end + result + end + + def collect_simpletypes + result = XSD::NamedElements.new + result.concat(@simpletypes) + @imports.each do |import| + result.concat(import.content.collect_simpletypes) if import.content + end + result + end + + def self.parse_element(element) + if element == SchemaName + Schema.new + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/sequence.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/sequence.rb new file mode 100644 index 0000000000..823fa3b7f9 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/sequence.rb @@ -0,0 +1,69 @@ +# WSDL4R - XMLSchema complexType definition for WSDL. +# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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 elementformdefault + parent.elementformdefault + 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.source + when MinOccursAttrName + @minoccurs = value.source + else + nil + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/simpleContent.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleContent.rb new file mode 100644 index 0000000000..e1f35c88b8 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleContent.rb @@ -0,0 +1,65 @@ +# WSDL4R - XMLSchema simpleContent definition for WSDL. +# Copyright (C) 2004, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class SimpleContent < Info + attr_reader :restriction + attr_reader :extension + + def check_lexical_format(value) + check(value) + end + + def initialize + super + @restriction = nil + @extension = nil + end + + def base + content.base + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when RestrictionName + @restriction = SimpleRestriction.new + @restriction + when ExtensionName + @extension = SimpleExtension.new + @extension + end + end + +private + + def content + @restriction || @extension + end + + def check(value) + unless content.valid?(value) + raise XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'") + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/simpleExtension.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleExtension.rb new file mode 100644 index 0000000000..3c53a7328c --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleExtension.rb @@ -0,0 +1,54 @@ +# WSDL4R - XMLSchema simpleType extension definition for WSDL. +# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class SimpleExtension < Info + attr_reader :base + attr_reader :attributes + + def initialize + super + @base = nil + @attributes = XSD::NamedElements.new + end + + def targetnamespace + parent.targetnamespace + end + + def valid?(value) + true + end + + def parse_element(element) + case element + when AttributeName + o = Attribute.new + @attributes << o + o + end + end + + def parse_attr(attr, value) + case attr + when BaseAttrName + @base = value + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/simpleRestriction.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleRestriction.rb new file mode 100644 index 0000000000..e8bf3ebfa5 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleRestriction.rb @@ -0,0 +1,73 @@ +# WSDL4R - XMLSchema simpleContent restriction definition for WSDL. +# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class SimpleRestriction < Info + attr_reader :base + attr_reader :enumeration + attr_accessor :length + attr_accessor :pattern + + def initialize + super + @base = nil + @enumeration = [] # NamedElements? + @length = nil + @pattern = nil + end + + def valid?(value) + return false unless check_restriction(value) + return false unless check_length(value) + return false unless check_pattern(value) + true + end + + def parse_element(element) + case element + when EnumerationName + Enumeration.new # just a parsing handler + when LengthName + Length.new # just a parsing handler + when PatternName + Pattern.new # just a parsing handler + end + end + + def parse_attr(attr, value) + case attr + when BaseAttrName + @base = value + end + end + +private + + def check_restriction(value) + @enumeration.empty? or @enumeration.include?(value) + end + + def check_length(value) + @length.nil? or value.size == @length + end + + def check_pattern(value) + @pattern.nil? or @pattern =~ value + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/simpleType.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleType.rb new file mode 100644 index 0000000000..e808c318c4 --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/simpleType.rb @@ -0,0 +1,73 @@ +# WSDL4R - XMLSchema simpleType definition for WSDL. +# Copyright (C) 2004, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' +require 'xsd/namedelements' + + +module WSDL +module XMLSchema + + +class SimpleType < Info + attr_accessor :name + attr_reader :restriction + + def check_lexical_format(value) + if @restriction + check_restriction(value) + else + raise ArgumentError.new("incomplete simpleType") + end + end + + def base + if @restriction + @restriction.base + else + raise ArgumentError.new("incomplete simpleType") + end + end + + def initialize(name = nil) + super() + @name = name + @restriction = nil + end + + def targetnamespace + parent.targetnamespace + end + + def parse_element(element) + case element + when RestrictionName + @restriction = SimpleRestriction.new + @restriction + end + end + + def parse_attr(attr, value) + case attr + when NameAttrName + @name = XSD::QName.new(targetnamespace, value.source) + end + end + +private + + def check_restriction(value) + unless @restriction.valid?(value) + raise XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'") + end + end +end + + +end +end diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/unique.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/unique.rb new file mode 100644 index 0000000000..837ff22b4a --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/unique.rb @@ -0,0 +1,34 @@ +# WSDL4R - XMLSchema unique element. +# Copyright (C) 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'wsdl/info' + + +module WSDL +module XMLSchema + + +class 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 diff --git a/ruby_1_8_6/lib/wsdl/xmlSchema/xsd2ruby.rb b/ruby_1_8_6/lib/wsdl/xmlSchema/xsd2ruby.rb new file mode 100644 index 0000000000..afe5fc5ada --- /dev/null +++ b/ruby_1_8_6/lib/wsdl/xmlSchema/xsd2ruby.rb @@ -0,0 +1,107 @@ +# XSD4R - XSD to ruby mapping library. +# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. + +# This program is copyrighted free software by NAKAMURA, Hiroshi. You can +# redistribute it and/or modify it under the same terms of Ruby's license; +# either the dual license version in 2003, or any later version. + + +require 'xsd/codegen/gensupport' +require 'wsdl/xmlSchema/importer' +require 'wsdl/soap/classDefCreator' + + +module WSDL +module XMLSchema + + +class XSD2Ruby + attr_accessor :location + attr_reader :opt + attr_accessor :logger + attr_accessor :basedir + + def run + unless @location + raise RuntimeError, "XML Schema location not given" + end + @xsd = import(@location) + @name = create_classname(@xsd) + create_file + end + +private + + def initialize + @location = nil + @opt = {} + @logger = Logger.new(STDERR) + @basedir = nil + @xsd = nil + @name = nil + end + + def create_file + create_classdef + end + + def create_classdef + @logger.info { "Creating class definition." } + @classdef_filename = @name + '.rb' + check_file(@classdef_filename) or return + write_file(@classdef_filename) do |f| + f << WSDL::SOAP::ClassDefCreator.new(@xsd).dump + end + end + + def write_file(filename) + if @basedir + filename = File.join(basedir, filename) + end + File.open(filename, "w") do |f| + yield f + end + end + + def check_file(filename) + if @basedir + filename = File.join(basedir, filename) + end + if FileTest.exist?(filename) + if @opt.key?('force') + @logger.warn { + "File '#{filename}' exists but overrides it." + } + true + else + @logger.warn { + "File '#{filename}' exists. #{$0} did not override it." + } + false + end + else + @logger.info { "Creates file '#{filename}'." } + true + end + end + + def create_classname(xsd) + name = nil + if xsd.targetnamespace + name = xsd.targetnamespace.scan(/[a-zA-Z0-9]+$/)[0] + end + if name.nil? + 'default' + else + XSD::CodeGen::GenSupport.safevarname(name) + end + end + + def import(location) + WSDL::XMLSchema::Importer.import(location) + end +end + + +end +end |