summaryrefslogtreecommitdiff
path: root/lib/wsdl/xmlSchema
diff options
context:
space:
mode:
Diffstat (limited to 'lib/wsdl/xmlSchema')
-rw-r--r--lib/wsdl/xmlSchema/attribute.rb60
-rw-r--r--lib/wsdl/xmlSchema/complexContent.rb5
-rw-r--r--lib/wsdl/xmlSchema/data.rb11
-rw-r--r--lib/wsdl/xmlSchema/element.rb72
-rw-r--r--lib/wsdl/xmlSchema/import.rb25
-rw-r--r--lib/wsdl/xmlSchema/parser.rb39
-rw-r--r--lib/wsdl/xmlSchema/schema.rb36
-rw-r--r--lib/wsdl/xmlSchema/simpleContent.rb56
-rw-r--r--lib/wsdl/xmlSchema/simpleRestriction.rb29
-rw-r--r--lib/wsdl/xmlSchema/simpleType.rb12
10 files changed, 266 insertions, 79 deletions
diff --git a/lib/wsdl/xmlSchema/attribute.rb b/lib/wsdl/xmlSchema/attribute.rb
index 6861fc171e..cfd4c68422 100644
--- a/lib/wsdl/xmlSchema/attribute.rb
+++ b/lib/wsdl/xmlSchema/attribute.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema attribute definition for WSDL.
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -14,34 +14,74 @@ 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
+ class << self
+ if RUBY_VERSION > "1.7.0"
+ def attr_reader_ref(symbol)
+ name = symbol.to_s
+ self.__send__(:define_method, name, proc {
+ 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
- @ref = nil
@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)
- nil
+ case element
+ when SimpleTypeName
+ @local_simpletype = SimpleType.new
+ @local_simpletype
+ end
end
def parse_attr(attr, value)
diff --git a/lib/wsdl/xmlSchema/complexContent.rb b/lib/wsdl/xmlSchema/complexContent.rb
index 66ad9e251d..eddb52f5ef 100644
--- a/lib/wsdl/xmlSchema/complexContent.rb
+++ b/lib/wsdl/xmlSchema/complexContent.rb
@@ -26,12 +26,17 @@ class ComplexContent < Info
@derivetype = nil
@content = nil
@attributes = XSD::NamedElements.new
+ @basetype = nil
end
def targetnamespace
parent.targetnamespace
end
+ def basetype
+ @basetype ||= root.collect_complextypes[@base]
+ end
+
def parse_element(element)
case element
when RestrictionName, ExtensionName
diff --git a/lib/wsdl/xmlSchema/data.rb b/lib/wsdl/xmlSchema/data.rb
index 10bc343adb..23ab1adf0b 100644
--- a/lib/wsdl/xmlSchema/data.rb
+++ b/lib/wsdl/xmlSchema/data.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema data definitions.
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -7,10 +7,13 @@
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'
@@ -22,12 +25,15 @@ 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')
@@ -37,6 +43,9 @@ 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')
diff --git a/lib/wsdl/xmlSchema/element.rb b/lib/wsdl/xmlSchema/element.rb
index cc9d4e9ed8..584afe9dc6 100644
--- a/lib/wsdl/xmlSchema/element.rb
+++ b/lib/wsdl/xmlSchema/element.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema element definition for WSDL.
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -14,23 +14,62 @@ 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)
+ class << self
+ if RUBY_VERSION > "1.7.0"
+ def attr_reader_ref(symbol)
+ name = symbol.to_s
+ self.__send__(:define_method, name, proc {
+ 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 :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 :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
@type = type
- @local_complextype = nil
+ @local_simpletype = @local_complextype = nil
@constraint = nil
@maxoccurs = '1'
@minoccurs = '1'
@nillable = nil
+ @ref = nil
+ @refelement = nil
+ end
+
+ def refelement
+ @refelement ||= root.collect_elements[@ref]
end
def targetnamespace
@@ -44,6 +83,9 @@ class Element < Info
def parse_element(element)
case element
+ when SimpleTypeName
+ @local_simpletype = SimpleType.new
+ @local_simpletype
when ComplexTypeName
@type = nil
@local_complextype = ComplexType.new
@@ -62,19 +104,19 @@ class Element < Info
@name = XSD::QName.new(targetnamespace, 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 }.")
+ 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 }.")
+ raise Parser::AttrConstraintError.new("cannot parse #{value} for #{attr}")
end
end
@minoccurs = value.source
diff --git a/lib/wsdl/xmlSchema/import.rb b/lib/wsdl/xmlSchema/import.rb
index e65641330d..d3487af934 100644
--- a/lib/wsdl/xmlSchema/import.rb
+++ b/lib/wsdl/xmlSchema/import.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema import definition.
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -7,6 +7,7 @@
require 'wsdl/info'
+require 'wsdl/xmlSchema/importer'
module WSDL
@@ -16,11 +17,13 @@ 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)
@@ -32,11 +35,29 @@ class Import < Info
when NamespaceAttrName
@namespace = value.source
when SchemaLocationAttrName
- @schemalocation = value.source
+ @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
diff --git a/lib/wsdl/xmlSchema/parser.rb b/lib/wsdl/xmlSchema/parser.rb
index a7f1c29fd4..057d9d9b70 100644
--- a/lib/wsdl/xmlSchema/parser.rb
+++ b/lib/wsdl/xmlSchema/parser.rb
@@ -1,5 +1,5 @@
# WSDL4R - WSDL XML Instance parser library.
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -51,6 +51,9 @@ public
@parser = XSD::XMLParser.create_parser(self, opt)
@parsestack = nil
@lastnode = nil
+ @ignored = {}
+ @location = opt[:location]
+ @originalroot = opt[:originalroot]
end
def parse(string_or_readable)
@@ -94,7 +97,7 @@ public
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 }'.")
+ 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
@@ -104,20 +107,31 @@ private
def decode_tag(ns, name, attrs, parent)
o = nil
- element = ns.parse(name)
+ elename = ns.parse(name)
if !parent
- if element == SchemaName
- o = Schema.parse_element(element)
+ if elename == SchemaName
+ o = Schema.parse_element(elename)
+ o.location = @location
else
- raise UnknownElementError.new("Unknown element #{ element }.")
+ raise UnknownElementError.new("unknown element: #{elename}")
end
+ o.root = @originalroot if @originalroot # o.root = o otherwise
else
- o = parent.parse_element(element)
+ 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
- STDERR.puts("Unknown element #{ element }.")
+ 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|
@@ -127,9 +141,12 @@ private
if attr_ele == IdAttrName
o.id = value_ele
else
- unless o.parse_attr(attr_ele, value_ele)
- STDERR.puts("Unknown attr #{ attr_ele }.")
- end
+ 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
diff --git a/lib/wsdl/xmlSchema/schema.rb b/lib/wsdl/xmlSchema/schema.rb
index ddd231bd97..43447f9fbf 100644
--- a/lib/wsdl/xmlSchema/schema.rb
+++ b/lib/wsdl/xmlSchema/schema.rb
@@ -24,6 +24,8 @@ class Schema < Info
attr_accessor :attributeformdefault
attr_accessor :elementformdefault
+ attr_reader :importedschema
+
def initialize
super
@targetnamespace = nil
@@ -33,6 +35,17 @@ class Schema < Info
@attributes = XSD::NamedElements.new
@imports = []
@elementformdefault = "qualified"
+ @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)
@@ -41,6 +54,10 @@ class Schema < Info
o = Import.new
@imports << o
o
+ when IncludeName
+ o = Include.new
+ @imports << o
+ o
when ComplexTypeName
o = ComplexType.new
@complextypes << o
@@ -55,6 +72,7 @@ class Schema < Info
o
when AttributeName
o = Attribute.new
+ @attributes << o
o
else
nil
@@ -74,21 +92,39 @@ class Schema < Info
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
diff --git a/lib/wsdl/xmlSchema/simpleContent.rb b/lib/wsdl/xmlSchema/simpleContent.rb
index 0d83678a01..e1f35c88b8 100644
--- a/lib/wsdl/xmlSchema/simpleContent.rb
+++ b/lib/wsdl/xmlSchema/simpleContent.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema simpleContent definition for WSDL.
-# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -15,17 +15,21 @@ module XMLSchema
class SimpleContent < Info
- attr_accessor :base
- attr_reader :derivetype
- attr_reader :content
- attr_reader :attributes
+ attr_reader :restriction
+ attr_reader :extension
+
+ def check_lexical_format(value)
+ check(value)
+ end
def initialize
super
- @base = nil
- @derivetype = nil
- @content = nil
- @attributes = XSD::NamedElements.new
+ @restriction = nil
+ @extension = nil
+ end
+
+ def base
+ content.base
end
def targetnamespace
@@ -34,28 +38,24 @@ class SimpleContent < Info
def parse_element(element)
case element
- when RestrictionName, ExtensionName
- @derivetype = element.name
- self
- when AttributeName
- if @derivetype.nil?
- raise Parser::ElementConstraintError.new("base attr not found.")
- end
- o = Attribute.new
- @attributes << o
- o
+ when RestrictionName
+ @restriction = SimpleRestriction.new
+ @restriction
+ when ExtensionName
+ @extension = SimpleExtension.new
+ @extension
end
end
- def parse_attr(attr, value)
- if @derivetype.nil?
- return nil
- end
- case attr
- when BaseAttrName
- @base = value
- else
- nil
+private
+
+ def content
+ @restriction || @extension
+ end
+
+ def check(value)
+ unless content.valid?(value)
+ raise XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'")
end
end
end
diff --git a/lib/wsdl/xmlSchema/simpleRestriction.rb b/lib/wsdl/xmlSchema/simpleRestriction.rb
index 6986e74423..e8bf3ebfa5 100644
--- a/lib/wsdl/xmlSchema/simpleRestriction.rb
+++ b/lib/wsdl/xmlSchema/simpleRestriction.rb
@@ -1,4 +1,4 @@
-# WSDL4R - XMLSchema simpleType definition for WSDL.
+# 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
@@ -17,21 +17,32 @@ 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)
- @enumeration.include?(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
@@ -41,6 +52,20 @@ class SimpleRestriction < Info
@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
diff --git a/lib/wsdl/xmlSchema/simpleType.rb b/lib/wsdl/xmlSchema/simpleType.rb
index d9f76f345c..e808c318c4 100644
--- a/lib/wsdl/xmlSchema/simpleType.rb
+++ b/lib/wsdl/xmlSchema/simpleType.rb
@@ -1,5 +1,5 @@
# WSDL4R - XMLSchema simpleType definition for WSDL.
-# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -16,15 +16,11 @@ module XMLSchema
class SimpleType < Info
attr_accessor :name
- attr_reader :derivetype
attr_reader :restriction
def check_lexical_format(value)
if @restriction
check_restriction(value)
- elsif @extension
- raise NotImplementedError
- # ToDo
else
raise ArgumentError.new("incomplete simpleType")
end
@@ -33,8 +29,6 @@ class SimpleType < Info
def base
if @restriction
@restriction.base
- elsif @extension
- @extension.base
else
raise ArgumentError.new("incomplete simpleType")
end
@@ -43,7 +37,6 @@ class SimpleType < Info
def initialize(name = nil)
super()
@name = name
- @derivetype = nil
@restriction = nil
end
@@ -55,7 +48,6 @@ class SimpleType < Info
case element
when RestrictionName
@restriction = SimpleRestriction.new
- @derivetype = element.name
@restriction
end
end
@@ -71,7 +63,7 @@ private
def check_restriction(value)
unless @restriction.valid?(value)
- raise ::XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'.")
+ raise XSD::ValueSpaceError.new("#{@name}: cannot accept '#{value}'")
end
end
end