| 1 |
# SOAP4R - Ruby type mapping schema definition utility. |
|---|
| 2 |
# Copyright (C) 2000-2007 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 'xsd/codegen/gensupport' |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
module SOAP |
|---|
| 13 |
module Mapping |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class SchemaElementDefinition |
|---|
| 17 |
attr_reader :varname, :mapped_class, :elename, :minoccurs, :maxoccurs |
|---|
| 18 |
|
|---|
| 19 |
def initialize(varname, mapped_class, elename, minoccurs, maxoccurs, |
|---|
| 20 |
as_any, as_array) |
|---|
| 21 |
@varname = varname |
|---|
| 22 |
@mapped_class = mapped_class |
|---|
| 23 |
@elename = elename |
|---|
| 24 |
@minoccurs = minoccurs |
|---|
| 25 |
@maxoccurs = maxoccurs |
|---|
| 26 |
@as_any = as_any |
|---|
| 27 |
@as_array = as_array |
|---|
| 28 |
end |
|---|
| 29 |
|
|---|
| 30 |
def as_any? |
|---|
| 31 |
@as_any |
|---|
| 32 |
end |
|---|
| 33 |
|
|---|
| 34 |
def as_array? |
|---|
| 35 |
@as_array |
|---|
| 36 |
end |
|---|
| 37 |
end |
|---|
| 38 |
|
|---|
| 39 |
module SchemaComplexTypeDefinition |
|---|
| 40 |
include Enumerable |
|---|
| 41 |
|
|---|
| 42 |
def initialize |
|---|
| 43 |
@content = [] |
|---|
| 44 |
@element_cache = {} |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
def is_concrete_definition |
|---|
| 48 |
true |
|---|
| 49 |
end |
|---|
| 50 |
|
|---|
| 51 |
def <<(ele) |
|---|
| 52 |
@content << ele |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
def each |
|---|
| 56 |
@content.each do |ele| |
|---|
| 57 |
yield ele |
|---|
| 58 |
end |
|---|
| 59 |
end |
|---|
| 60 |
|
|---|
| 61 |
def size |
|---|
| 62 |
@content.size |
|---|
| 63 |
end |
|---|
| 64 |
|
|---|
| 65 |
def as_any? |
|---|
| 66 |
false |
|---|
| 67 |
end |
|---|
| 68 |
|
|---|
| 69 |
def as_array? |
|---|
| 70 |
false |
|---|
| 71 |
end |
|---|
| 72 |
|
|---|
| 73 |
def find_element(qname) |
|---|
| 74 |
@element_cache[qname] ||= search_element(qname) |
|---|
| 75 |
end |
|---|
| 76 |
|
|---|
| 77 |
private |
|---|
| 78 |
|
|---|
| 79 |
def search_element(qname) |
|---|
| 80 |
each do |ele| |
|---|
| 81 |
if ele.respond_to?(:find_element) |
|---|
| 82 |
found = ele.find_element(qname) |
|---|
| 83 |
return found if found |
|---|
| 84 |
else |
|---|
| 85 |
# relaxed match |
|---|
| 86 |
if ele.elename == qname or |
|---|
| 87 |
(qname.namespace.nil? and ele.elename.name == qname.name) |
|---|
| 88 |
return ele |
|---|
| 89 |
end |
|---|
| 90 |
end |
|---|
| 91 |
end |
|---|
| 92 |
nil |
|---|
| 93 |
end |
|---|
| 94 |
end |
|---|
| 95 |
|
|---|
| 96 |
class SchemaEmptyDefinition |
|---|
| 97 |
include SchemaComplexTypeDefinition |
|---|
| 98 |
|
|---|
| 99 |
def initialize |
|---|
| 100 |
super() |
|---|
| 101 |
@content.freeze |
|---|
| 102 |
end |
|---|
| 103 |
end |
|---|
| 104 |
|
|---|
| 105 |
class SchemaSequenceDefinition |
|---|
| 106 |
include SchemaComplexTypeDefinition |
|---|
| 107 |
|
|---|
| 108 |
def initialize |
|---|
| 109 |
super() |
|---|
| 110 |
end |
|---|
| 111 |
|
|---|
| 112 |
def choice? |
|---|
| 113 |
false |
|---|
| 114 |
end |
|---|
| 115 |
|
|---|
| 116 |
# override |
|---|
| 117 |
def as_array? |
|---|
| 118 |
@as_array ||= false |
|---|
| 119 |
end |
|---|
| 120 |
|
|---|
| 121 |
def set_array |
|---|
| 122 |
@as_array = true |
|---|
| 123 |
end |
|---|
| 124 |
end |
|---|
| 125 |
|
|---|
| 126 |
class SchemaChoiceDefinition |
|---|
| 127 |
include SchemaComplexTypeDefinition |
|---|
| 128 |
|
|---|
| 129 |
def initialize |
|---|
| 130 |
super() |
|---|
| 131 |
end |
|---|
| 132 |
|
|---|
| 133 |
def choice? |
|---|
| 134 |
true |
|---|
| 135 |
end |
|---|
| 136 |
end |
|---|
| 137 |
|
|---|
| 138 |
class SchemaDefinition |
|---|
| 139 |
EMPTY = SchemaEmptyDefinition.new |
|---|
| 140 |
|
|---|
| 141 |
attr_reader :class_for |
|---|
| 142 |
attr_reader :elename, :type |
|---|
| 143 |
attr_reader :qualified |
|---|
| 144 |
attr_accessor :basetype |
|---|
| 145 |
attr_accessor :attributes |
|---|
| 146 |
attr_accessor :elements |
|---|
| 147 |
|
|---|
| 148 |
def initialize(class_for, elename, type, anonymous, qualified) |
|---|
| 149 |
@class_for = class_for |
|---|
| 150 |
@elename = elename |
|---|
| 151 |
@type = type |
|---|
| 152 |
@anonymous = anonymous |
|---|
| 153 |
@qualified = qualified |
|---|
| 154 |
@basetype = nil |
|---|
| 155 |
@elements = EMPTY |
|---|
| 156 |
@attributes = nil |
|---|
| 157 |
end |
|---|
| 158 |
|
|---|
| 159 |
def is_anonymous? |
|---|
| 160 |
@anonymous |
|---|
| 161 |
end |
|---|
| 162 |
|
|---|
| 163 |
def choice? |
|---|
| 164 |
@elements.choice? |
|---|
| 165 |
end |
|---|
| 166 |
end |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
end |
|---|
| 170 |
end |
|---|