~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/wsdl/soap/complexType.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# WSDL4R - SOAP complexType definition for WSDL.
 
2
# Copyright (C) 2002, 2003  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 
3
 
 
4
# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
 
5
# redistribute it and/or modify it under the same terms of Ruby's license;
 
6
# either the dual license version in 2003, or any later version.
 
7
 
 
8
 
 
9
require 'wsdl/xmlSchema/complexType'
 
10
require 'soap/mapping'
 
11
 
 
12
 
 
13
module WSDL
 
14
module XMLSchema
 
15
 
 
16
 
 
17
class ComplexType < Info
 
18
  def compoundtype
 
19
    @compoundtype ||= check_type
 
20
  end
 
21
 
 
22
  def check_type
 
23
    if content
 
24
      if attributes.empty? and
 
25
          content.elements.size == 1 and content.elements[0].maxoccurs != '1'
 
26
        if name == ::SOAP::Mapping::MapQName
 
27
          :TYPE_MAP
 
28
        else
 
29
          :TYPE_ARRAY
 
30
        end
 
31
      else
 
32
        :TYPE_STRUCT
 
33
      end
 
34
    elsif complexcontent
 
35
      if complexcontent.base == ::SOAP::ValueArrayName
 
36
        :TYPE_ARRAY
 
37
      else
 
38
        complexcontent.basetype.check_type
 
39
      end
 
40
    elsif simplecontent
 
41
      :TYPE_SIMPLE
 
42
    elsif !attributes.empty?
 
43
      :TYPE_STRUCT
 
44
    else # empty complexType definition (seen in partner.wsdl of salesforce)
 
45
      :TYPE_EMPTY
 
46
    end
 
47
  end
 
48
 
 
49
  def child_type(name = nil)
 
50
    case compoundtype
 
51
    when :TYPE_STRUCT
 
52
      if ele = find_element(name)
 
53
        ele.type
 
54
      elsif ele = find_element_by_name(name.name)
 
55
        ele.type
 
56
      end
 
57
    when :TYPE_ARRAY
 
58
      @contenttype ||= content_arytype
 
59
    when :TYPE_MAP
 
60
      item_ele = find_element_by_name("item") or
 
61
        raise RuntimeError.new("'item' element not found in Map definition.")
 
62
      content = item_ele.local_complextype or
 
63
        raise RuntimeError.new("No complexType definition for 'item'.")
 
64
      if ele = content.find_element(name)
 
65
        ele.type
 
66
      elsif ele = content.find_element_by_name(name.name)
 
67
        ele.type
 
68
      end
 
69
    else
 
70
      raise NotImplementedError.new("Unknown kind of complexType.")
 
71
    end
 
72
  end
 
73
 
 
74
  def child_defined_complextype(name)
 
75
    ele = nil
 
76
    case compoundtype
 
77
    when :TYPE_STRUCT, :TYPE_MAP
 
78
      unless ele = find_element(name)
 
79
        if name.namespace.nil?
 
80
          ele = find_element_by_name(name.name)
 
81
        end
 
82
      end
 
83
    when :TYPE_ARRAY
 
84
      if content.elements.size == 1
 
85
        ele = content.elements[0]
 
86
      else
 
87
        raise RuntimeError.new("Assert: must not reach.")
 
88
      end
 
89
    else
 
90
      raise RuntimeError.new("Assert: Not implemented.")
 
91
    end
 
92
    unless ele
 
93
      raise RuntimeError.new("Cannot find #{name} as a children of #{@name}.")
 
94
    end
 
95
    ele.local_complextype
 
96
  end
 
97
 
 
98
  def find_arytype
 
99
    unless compoundtype == :TYPE_ARRAY
 
100
      raise RuntimeError.new("Assert: not for array")
 
101
    end
 
102
    if complexcontent
 
103
      complexcontent.attributes.each do |attribute|
 
104
        if attribute.ref == ::SOAP::AttrArrayTypeName
 
105
          return attribute.arytype
 
106
        end
 
107
      end
 
108
      if check_array_content(complexcontent.content)
 
109
        return element_simpletype(complexcontent.content.elements[0])
 
110
      end
 
111
    elsif check_array_content(content)
 
112
      return element_simpletype(content.elements[0])
 
113
    end
 
114
    raise RuntimeError.new("Assert: Unknown array definition.")
 
115
  end
 
116
 
 
117
  def find_aryelement
 
118
    unless compoundtype == :TYPE_ARRAY
 
119
      raise RuntimeError.new("Assert: not for array")
 
120
    end
 
121
    if complexcontent
 
122
      if check_array_content(complexcontent.content)
 
123
        return complexcontent.content.elements[0]
 
124
      end
 
125
    elsif check_array_content(content)
 
126
      return content.elements[0]
 
127
    end
 
128
    nil # use default item name
 
129
  end
 
130
 
 
131
private
 
132
 
 
133
  def element_simpletype(element)
 
134
    if element.type
 
135
      element.type 
 
136
    elsif element.local_simpletype
 
137
      element.local_simpletype.base
 
138
    else
 
139
      nil
 
140
    end
 
141
  end
 
142
 
 
143
  def check_array_content(content)
 
144
    content and content.elements.size == 1 and
 
145
      content.elements[0].maxoccurs != '1'
 
146
  end
 
147
 
 
148
  def content_arytype
 
149
    if arytype = find_arytype
 
150
      ns = arytype.namespace
 
151
      name = arytype.name.sub(/\[(?:,)*\]$/, '')
 
152
      XSD::QName.new(ns, name)
 
153
    else
 
154
      nil
 
155
    end
 
156
  end
 
157
end
 
158
 
 
159
 
 
160
end
 
161
end