soap-lc 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,136 @@
1
+ module SOAP
2
+ class XSD
3
+ class ComplexType < Hash
4
+ def initialize( type )
5
+ type.attributes.each { |name, value|
6
+ self[name.to_sym] = value
7
+ }
8
+
9
+ type.find_all{ |e| e.class == REXML::Element }.each { |content|
10
+ case content.name
11
+ when "simpleContent"
12
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
13
+ self[:type] = :simpleContent
14
+ ###############################################################################
15
+ warn "xsd:simpleContent in xsd:complexType (global definition) is not yet supported!"
16
+ ###############################################################################
17
+ when "complexContent"
18
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
19
+ self[:type] = :complexContent
20
+ ###############################################################################
21
+ warn "xsd:complexContent in xsd:complexType (global definition) is not yet supported!"
22
+ ###############################################################################
23
+ when "group"
24
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
25
+ self[:type] = :group
26
+ ###############################################################################
27
+ warn "xsd:group in xsd:complexType (global definition) is not yet supported!"
28
+ ###############################################################################
29
+ when "all"
30
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
31
+ self[:type] = :all
32
+ ###############################################################################
33
+ warn "xsd:all in xsd:complexType (global definition) is not yet supported!"
34
+ ###############################################################################
35
+ when "choise"
36
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
37
+ self[:type] = :choise
38
+ ###############################################################################
39
+ warn "xsd:choise in xsd:complexType (global definition) is not yet supported!"
40
+ ###############################################################################
41
+ when "sequence"
42
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
43
+ self[:type] = :sequence
44
+ self[:sequence] = SOAP::XSD::Sequence.new( content )
45
+ when "attribute"
46
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if (not(self[:attributes_type].nil?) and self[:attributes_type] != :attribute) or [:simpleContent, :complexContent].include?(self[:type])
47
+ self[:attributes_type] = :attribute
48
+ ###############################################################################
49
+ warn "xsd:attribute in xsd:complexType (global definition) is not yet supported!"
50
+ ###############################################################################
51
+ when "attributeGroup"
52
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if (not(self[:attributes_type].nil?) and self[:attributes_type] != :attributeGroup) or [:simpleContent, :complexContent].include?(self[:type])
53
+ self[:attributes_type] = :attributeGroup
54
+ ###############################################################################
55
+ warn "xsd:attributeGroup in xsd:complexType (global definition) is not yet supported!"
56
+ ###############################################################################
57
+ when "anyAttribute"
58
+ raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if not(self[:any_attributes].nil?) or [:simpleContent, :complexContent].include?(self[:type])
59
+ self[:any_attributes] = :anyAttribute
60
+ ###############################################################################
61
+ warn "xsd:anyAttribute in xsd:complexType (global definition) is not yet supported!"
62
+ ###############################################################################
63
+ when "annotation"
64
+ ###############################################################################
65
+ warn "xsd:annotation in xsd:complexType (global definition) (global definition) is not yet supported!"
66
+ ###############################################################################
67
+ else
68
+ raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:complexType `#{type.attributes['name']}'"
69
+ end
70
+ }
71
+ end
72
+
73
+ def display( types, args )
74
+ r = ""
75
+
76
+ case self[:type]
77
+ when :simpleContent
78
+ ###############################################################################
79
+ warn "xsd:simpleContent in xsd:complexType (global definition) is not yet supported!"
80
+ ###############################################################################
81
+ when :complexContent
82
+ ###############################################################################
83
+ warn "xsd:complexContent in xsd:complexType (global definition) is not yet supported!"
84
+ ###############################################################################
85
+ when :group
86
+ ###############################################################################
87
+ warn "xsd:group in xsd:complexType (global definition) is not yet supported!"
88
+ ###############################################################################
89
+ when :all
90
+ ###############################################################################
91
+ warn "xsd:all in xsd:complexType (global definition) is not yet supported!"
92
+ ###############################################################################
93
+ when :choise
94
+ ###############################################################################
95
+ warn "xsd:choise in xsd:complexType (global definition) is not yet supported!"
96
+ ###############################################################################
97
+ when :sequence
98
+ r << self[:sequence].display( types, args )
99
+ #else
100
+ # raise SOAP::LCWSDLError, "Malformated complexType `#{self[:name]}'"
101
+ end
102
+
103
+ return r
104
+ end
105
+
106
+ def responseToHash( xml, types )
107
+ r = {}
108
+ case self[:type]
109
+ when :simpleContent
110
+ ###############################################################################
111
+ warn "xsd:simpleContent in xsd:complexType (global definition) is not yet supported!"
112
+ ###############################################################################
113
+ when :complexContent
114
+ ###############################################################################
115
+ warn "xsd:complexContent in xsd:complexType (global definition) is not yet supported!"
116
+ ###############################################################################
117
+ when :group
118
+ ###############################################################################
119
+ warn "xsd:group in xsd:complexType (global definition) is not yet supported!"
120
+ ###############################################################################
121
+ when :all
122
+ ###############################################################################
123
+ warn "xsd:all in xsd:complexType (global definition) is not yet supported!"
124
+ ###############################################################################
125
+ when :choise
126
+ ###############################################################################
127
+ warn "xsd:choise in xsd:complexType (global definition) is not yet supported!"
128
+ ###############################################################################
129
+ when :sequence
130
+ r = self[:sequence].responseToHash( xml, types )
131
+ end
132
+ return r
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,107 @@
1
+ module SOAP
2
+ class XSD
3
+ class Convert
4
+
5
+ def self.to_ruby( t, v )
6
+ new().c( t.gsub( /.*:/, "xsd_" ), v )
7
+ end
8
+
9
+ def c( t, v )
10
+ self.method( t ).call( v )
11
+ end
12
+
13
+ def xsd_int( x )
14
+ x.to_i
15
+ end
16
+ alias_method :xsd_long, :xsd_int
17
+ alias_method :xsd_integer, :xsd_int
18
+
19
+ def xsd_float( x )
20
+ x.to_f
21
+ end
22
+ alias_method :xsd_double, :xsd_float
23
+ alias_method :xsd_decimal, :xsd_float
24
+
25
+ def xsd_string( x )
26
+ x
27
+ end
28
+ alias_method :xsd_normalizedString, :xsd_string
29
+
30
+ def xsd_boolean( x )
31
+ (x == "true")
32
+ end
33
+
34
+ def xsd_duration( x )
35
+ end
36
+ def xsd_dateTime( x )
37
+ end
38
+ def xsd_time( x )
39
+ end
40
+ def xsd_date( x )
41
+ end
42
+ def xsd_gYearMonth( x )
43
+ end
44
+ def xsd_gYear( x )
45
+ end
46
+ def xsd_gMonthDay( x )
47
+ end
48
+ def xsd_gDay( x )
49
+ end
50
+ def xsd_gMonth( x )
51
+ end
52
+ def xsd_base64Binary( x )
53
+ end
54
+ def xsd_hexBinary( x )
55
+ end
56
+ def xsd_anyURI( x )
57
+ end
58
+ def xsd_QName( x )
59
+ end
60
+ def xsd_NOTATION( x )
61
+ end
62
+ def xsd_token( x )
63
+ end
64
+ def xsd_language( x )
65
+ end
66
+ def xsd_Name( x )
67
+ end
68
+ def xsd_NMTOKEN( x )
69
+ end
70
+ def xsd_NCName( x )
71
+ end
72
+ def xsd_NMTOKENS( x )
73
+ end
74
+ def xsd_ID( x )
75
+ end
76
+ def xsd_IDREF( x )
77
+ end
78
+ def xsd_ENTITY( x )
79
+ end
80
+ def xsd_IDREFS( x )
81
+ end
82
+ def xsd_ENTITIES( x )
83
+ end
84
+ def xsd_nonPositiveInteger( x )
85
+ end
86
+ def xsd_nonNegativeInteger( x )
87
+ end
88
+ def xsd_negativeInteger( x )
89
+ end
90
+ def xsd_unsignedLong( x )
91
+ end
92
+ def xsd_positiveInteger( x )
93
+ end
94
+ def xsd_short( x )
95
+ end
96
+ def xsd_unsignedInt( x )
97
+ end
98
+ def xsd_byte( x )
99
+ end
100
+ def xsd_unsignedShort( x )
101
+ end
102
+ def xsd_unsignedByte( x )
103
+ end
104
+ end
105
+ end
106
+ end
107
+
@@ -0,0 +1,167 @@
1
+ module SOAP
2
+ class XSD
3
+ class Element < Hash
4
+ def initialize( type )
5
+ type.attributes.each { |name, value|
6
+ self[name.to_sym] = value
7
+ }
8
+
9
+ type.find_all{ |e| e.class == REXML::Element }.each { |content|
10
+ case content.name
11
+ when "simpleType"
12
+ raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil?
13
+ self[:type] = :simpleType
14
+ ###############################################################################
15
+ warn "xsd:simpleType in xsd:element is not yet supported!"
16
+ ###############################################################################
17
+ when "complexType"
18
+ raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil?
19
+ self[:type] = :complexType
20
+ self[:complexType] = SOAP::XSD::ComplexType.new( content )
21
+ when "unique"
22
+ raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
23
+ self[:key] = :unique
24
+ ###############################################################################
25
+ warn "xsd:unique in xsd:element is not yet supported!"
26
+ ###############################################################################
27
+ when "key"
28
+ raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
29
+ self[:key] = :key
30
+ ###############################################################################
31
+ warn "xsd:unique in xsd:element is not yet supported!"
32
+ ###############################################################################
33
+ when "keyref"
34
+ raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
35
+ self[:key] = :keyref
36
+ ###############################################################################
37
+ warn "xsd:unique in xsd:element is not yet supported!"
38
+ ###############################################################################
39
+ when "annotation"
40
+ ###############################################################################
41
+ warn "xsd:annotation in xsd:complexType (global definition) (global definition) is not yet supported!"
42
+ ###############################################################################
43
+ else
44
+ raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:element `#{type.attributes['name']}'"
45
+ end
46
+ }
47
+ end
48
+
49
+ def display( types, args )
50
+ r = ""
51
+
52
+ min, max = getOccures( args )
53
+ if SOAP::XSD::ANY_SIMPLE_TYPE.include?( self[:type].nns )
54
+ r << SOAP::XSD.displayBuiltinType( self[:name], args, min, max )
55
+ else
56
+ case types[self[:type].nns][:type]
57
+ when :simpleType
58
+ if args.keys.include?( self[:name].to_sym )
59
+ args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array
60
+ if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max
61
+ raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'"
62
+ end
63
+ args[self[:name].to_sym].each { |v|
64
+ r << "<#{self[:name]}>"
65
+ r << "#{v}" ############ CHECK !!!
66
+ r << "</#{self[:name]}>\n"
67
+ }
68
+ elsif min > 0
69
+ raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0
70
+ end
71
+ when :complexType
72
+ if args.keys.include?( self[:name].to_sym )
73
+ if args.keys.include?( self[:name].to_sym )
74
+ args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array
75
+ if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max
76
+ raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'"
77
+ end
78
+ args[self[:name].to_sym].each { |v|
79
+ r << "<#{self[:name]}>"
80
+ r << types[self[:type].nns][:value].display( types, v )
81
+ r << "</#{self[:name]}>\n"
82
+ }
83
+ elsif min > 0
84
+ raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0
85
+ end
86
+ else
87
+ r << "<#{self[:name]}>\n"
88
+ r << types[self[:type].nns][:value].display( types, args )
89
+ r << "</#{self[:name]}>\n"
90
+ end
91
+ else
92
+ raise SOAL::LCWSDLError, "Malformated element `#{self[:name]}'"
93
+ end
94
+ end
95
+
96
+ return r
97
+ end
98
+
99
+ def getOccures( args )
100
+ element_min = self[:minOccurs].to_i || 1
101
+ element_max = self[:maxOccurs] || "1"
102
+ if element_max == "unbounded"
103
+ if args.keys.include?(self[:name].to_sym)
104
+ if args[self[:name].to_sym].class == Array
105
+ element_max = args[self[:name].to_sym].size
106
+ else
107
+ element_max = 1
108
+ end
109
+ else
110
+ element_max = 1
111
+ end
112
+ else
113
+ element_max = element_max.to_i
114
+ end
115
+
116
+ return( [element_min, element_max] )
117
+ end
118
+
119
+ def responseToHash( xml, types )
120
+ r = {}
121
+
122
+ if SOAP::XSD::ANY_SIMPLE_TYPE.include?( self[:type].to_s.nns )
123
+ xml.each { |e|
124
+ if e.name == self[:name]
125
+ r[self[:name]] = SOAP::XSD::Convert.to_ruby( self[:type].to_s, e.text )
126
+ end
127
+ }
128
+ else
129
+ case self[:type]
130
+ when :simpleType
131
+ # **************************** TODO ************************************
132
+ when :complexType
133
+ # **************************** TO VERIFY ************************************
134
+ r = self[:complexType].responseToHash( xml, types )
135
+ else
136
+ xml.each { |e|
137
+ if e.name == self[:name]
138
+ case types[self[:type].to_s.nns][:type]
139
+ when :simpleType
140
+ if r.keys.include?(self[:name])
141
+ unless r[self[:name]].class == Array
142
+ r[self[:name]] = [r[self[:name]]]
143
+ end
144
+ r[self[:name]] << types[self[:type].to_s.nns][:value].responseToHash( e.text, types )
145
+ else
146
+ r[self[:name]] = types[self[:type].to_s.nns][:value].responseToHash( e.text, types )
147
+ end
148
+ else
149
+ if r.keys.include?(self[:name])
150
+ unless r[self[:name]].class == Array
151
+ r[self[:name]] = [r[self[:name]]]
152
+ end
153
+ r[self[:name]] << types[self[:type].to_s.nns][:value].responseToHash( e, types )
154
+ else
155
+ r[self[:name]] = types[self[:type].to_s.nns][:value].responseToHash( e, types )
156
+ end
157
+ end
158
+ end
159
+ }
160
+ end
161
+ end
162
+
163
+ return r
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,6 @@
1
+ module SOAP
2
+ class XSD
3
+ class Enumeration < Array
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,76 @@
1
+ module SOAP
2
+ class XSD
3
+ class Restriction < Hash
4
+ def initialize( content )
5
+ content.attributes.each { |name, value|
6
+ self[name.to_sym] = value
7
+ }
8
+ content.find_all{ |e| e.class == REXML::Element }.each { |restrictions|
9
+ case restrictions.name
10
+ when "annotation"
11
+ ###############################################################################
12
+ warn "xsd:annotation in xsd:restriction is not yet supported!"
13
+ ###############################################################################
14
+ when "fractionDigits"
15
+ ###############################################################################
16
+ warn "xsd:fractionDigits in xsd:restriction is not yet supported!"
17
+ ###############################################################################
18
+ when "enumeration"
19
+ self[:enumeration] = SOAP::XSD::Enumeration.new unless self.has_key?( :enumeration )
20
+ self[:enumeration] << restrictions.attributes['value']
21
+ when "length"
22
+ ###############################################################################
23
+ warn "xsd:length in xsd:restriction is not yet supported!"
24
+ ###############################################################################
25
+ when "maxExclusive"
26
+ ###############################################################################
27
+ warn "xsd:maxExclusive in xsd:restriction is not yet supported!"
28
+ ###############################################################################
29
+ when "maxInclusive"
30
+ ###############################################################################
31
+ warn "xsd:maxInclusive in xsd:restriction is not yet supported!"
32
+ ###############################################################################
33
+ when "maxLength"
34
+ ###############################################################################
35
+ warn "xsd:maxLength in xsd:restriction is not yet supported!"
36
+ ###############################################################################
37
+ when "minExclusive"
38
+ ###############################################################################
39
+ warn "xsd:minExclusive in xsd:restriction is not yet supported!"
40
+ ###############################################################################
41
+ when "minInclusive"
42
+ ###############################################################################
43
+ warn "xsd:minInclusive in xsd:restriction is not yet supported!"
44
+ ###############################################################################
45
+ when "minLength"
46
+ ###############################################################################
47
+ warn "xsd:minLength in xsd:restriction is not yet supported!"
48
+ ###############################################################################
49
+ when "pattern"
50
+ ###############################################################################
51
+ warn "xsd:pattern in xsd:restriction is not yet supported!"
52
+ ###############################################################################
53
+ when "simpleType"
54
+ ###############################################################################
55
+ warn "xsd:simpleType in xsd:restriction is not yet supported!"
56
+ ###############################################################################
57
+ when "totalDigits"
58
+ ###############################################################################
59
+ warn "xsd:totalDigits in xsd:restriction is not yet supported!"
60
+ ###############################################################################
61
+ when "whiteSpace"
62
+ ###############################################################################
63
+ warn "xsd:whiteSpace in xsd:restriction is not yet supported!"
64
+ ###############################################################################
65
+ else
66
+ warn "Ignoring `#{restrictions.name}' in xsd:restriction for xsd:simpleType `#{type.attributes['name']}'"
67
+ end
68
+ }
69
+ end
70
+
71
+ def responseToHash( xml, types )
72
+ SOAP::XSD::Convert.to_ruby( self[:base].to_s, xml )
73
+ end
74
+ end
75
+ end
76
+ end