PageRenderTime 92ms CodeModel.GetById 82ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/wsdl/xmlSchema/complexType.rb

http://github.com/agross/netopenspace
Ruby | 139 lines | 113 code | 19 blank | 7 comment | 15 complexity | f519c24fe309f570ef81a911bab3774a MD5 | raw file
  1# WSDL4R - XMLSchema 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
  9require 'wsdl/info'
 10require 'wsdl/xmlSchema/content'
 11require 'wsdl/xmlSchema/element'
 12require 'xsd/namedelements'
 13
 14
 15module WSDL
 16module XMLSchema
 17
 18
 19class ComplexType < Info
 20  attr_accessor :name
 21  attr_accessor :complexcontent
 22  attr_accessor :simplecontent
 23  attr_reader :content
 24  attr_accessor :final
 25  attr_accessor :mixed
 26  attr_reader :attributes
 27
 28  def initialize(name = nil)
 29    super()
 30    @name = name
 31    @complexcontent = nil
 32    @simplecontent = nil
 33    @content = nil
 34    @final = nil
 35    @mixed = false
 36    @attributes = XSD::NamedElements.new
 37  end
 38
 39  def targetnamespace
 40    # inner elements can be qualified
 41    # parent.is_a?(WSDL::XMLSchema::Element) ? nil : parent.targetnamespace
 42    parent.targetnamespace
 43  end
 44
 45  def elementformdefault
 46    parent.elementformdefault
 47  end
 48 
 49  AnyAsElement = Element.new(XSD::QName.new(nil, 'any'), XSD::AnyTypeName)
 50  def each_element
 51    if content
 52      content.elements.each do |element|
 53        if element.is_a?(Any)
 54          yield(AnyAsElement)
 55        else
 56          yield(element)
 57        end
 58      end
 59    end
 60  end
 61
 62  def find_element(name)
 63    if content
 64      content.elements.each do |element|
 65        if element.is_a?(Any)
 66          return AnyAsElement if name == AnyAsElement.name
 67        else
 68          return element if name == element.name
 69        end
 70      end
 71    end
 72    nil
 73  end
 74
 75  def find_element_by_name(name)
 76    if content
 77      content.elements.each do |element|
 78        if element.is_a?(Any)
 79          return AnyAsElement if name == AnyAsElement.name.name
 80        else
 81          return element if name == element.name.name
 82        end
 83      end
 84    end
 85    nil
 86  end
 87
 88  def sequence_elements=(elements)
 89    @content = Sequence.new
 90    elements.each do |element|
 91      @content << element
 92    end
 93  end
 94
 95  def all_elements=(elements)
 96    @content = All.new
 97    elements.each do |element|
 98      @content << element
 99    end
100  end
101
102  def parse_element(element)
103    case element
104    when AllName
105      @content = All.new
106    when SequenceName
107      @content = Sequence.new
108    when ChoiceName
109      @content = Choice.new
110    when ComplexContentName
111      @complexcontent = ComplexContent.new
112    when SimpleContentName
113      @simplecontent = SimpleContent.new
114    when AttributeName
115      o = Attribute.new
116      @attributes << o
117      o
118    else
119      nil
120    end
121  end
122
123  def parse_attr(attr, value)
124    case attr
125    when FinalAttrName
126      @final = value.source
127    when MixedAttrName
128      @mixed = (value.source == 'true')
129    when NameAttrName
130      @name = XSD::QName.new(targetnamespace, value.source)
131    else
132      nil
133    end
134  end
135end
136
137
138end
139end