XMLSchemas/WsdlSoapBindingVisitor.pm untested

filter: Statementstmt 0.0% 0 / 136 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 179 CC 5 SCAR 14.3
CC
5
Cov
0%
visitSpecification
12.0
new
6.0
visitOperation
6.0
CRAP 4.2
1
2 #
3 # Interface Definition Language (OMG IDL CORBA v3.0)
4 #
5 # CORBA to WSDL/SOAP Interworking Specification, Version 1.1 February 2005
6 #
7
8 package CORBA::XMLSchemas::WsdlSoapBindingVisitor;
9
10 use strict;
11 use warnings;
12
13 our $VERSION = '2.62';
14
15 use CORBA::XMLSchemas::BaseVisitor;
16 use base qw(CORBA::XMLSchemas::BaseVisitor);
17
18 use File::Basename;
19 use POSIX qw(ctime);
20 use XML::DOM;
21
22 # needs $node->{xsd_name} $node->{xsd_qname} (XsdNameVisitor)
23
24 sub new {
25 my $proto = shift;
26 my $class = ref($proto) || $proto;
27 my $self = {};
28 bless $self, $class;
29 my ($parser) = @_;
30 $self->{beautify} = $parser->YYData->{opt_t};
31 $self->{_tns} = 'tns';
32 $self->{tns} = 'tns:';
33 $self->{_xsd} = 'xs';
34 $self->{xsd} = 'xs:';
35 $self->{_wsdl} = 'wsdl';
36 $self->{wsdl} = $parser->YYData->{opt_q} ? 'wsdl:' : q{};
37 $self->{_soap} = 'soap';
38 $self->{soap} = 'soap:';
39 $self->{_corba} = 'corba';
40 $self->{corba} = 'corba:';
41 $self->{srcname} = $parser->YYData->{srcname};
42 $self->{srcname_size} = $parser->YYData->{srcname_size};
43 $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
44 $self->{symbtab} = $parser->YYData->{symbtab};
45 $self->{base} = $parser->YYData->{opt_b} || q{};
46 my $filename = basename($self->{srcname}, '.idl') . 'binding.wsdl';
47 $self->open_stream($filename);
48 $self->{done_hash} = {};
49 $self->{num_key} = 'num_inc_soap';
50 return $self;
51 }
52
53 #
54 # 3.5 OMG IDL Specification
55 #
56
57 sub visitSpecification {
58 my $self = shift;
59 my ($node) = @_;
60 my $FH = $self->{out};
61
62 $self->{dom_doc} = new XML::DOM::Document();
63 $self->{dom_parent} = $self->{dom_doc};
64
65 my $definitions = $self->{dom_doc}->createElement($self->{wsdl} . 'definitions');
66 $definitions->setAttribute('targetNamespace', 'http://www.omg.org/IDL-Mapped/');
67 $definitions->setAttribute('xmlns:' . $self->{_tns}, 'http://www.omg.org/IDL-Mapped/');
68 if ($self->{wsdl}) {
69 $definitions->setAttribute('xmlns:' . $self->{_wsdl}, 'http://schemas.xmlsoap.org/wsdl/');
70 }
71 else {
72 $definitions->setAttribute('xmlns', 'http://schemas.xmlsoap.org/wsdl/');
73 }
74 $definitions->setAttribute('xmlns:' . $self->{_soap}, 'http://schemas.xmlsoap.org/wsdl/soap/');
75 $definitions->setAttribute('xmlns:' . $self->{_corba}, 'http://www.omg.org/IDL-WSDL/1.0/');
76 $self->{dom_parent}->appendChild($definitions);
77
78 my $import = $self->{dom_doc}->createElement($self->{wsdl} . 'import');
79 $import->setAttribute('namespace', 'http://www.omg.org/IDL-Mapped/');
80 my $filename = basename($self->{srcname}, '.idl') . '.wsdl';
81 $import->setAttribute('location', $self->{base} . $filename);
82 $definitions->appendChild($import);
83
84 foreach (@{$node->{list_decl}}) {
85 $self->_get_defn($_)->visit($self, $definitions);
86 }
87
88 if ($self->{beautify}) {
89 print $FH "<!-- This file was generated (by ",$0,"). DO NOT modify it -->\n";
90 print $FH "<!-- From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
91 print $FH "-->\n";
92 print $FH "\n";
93 print $FH $self->_beautify($self->{dom_doc}->toString());
94 print $FH "\n\n";
95 print $FH "<!-- end of file : ",$self->{filename}," -->\n";
96 }
97 else {
98 print $FH $self->{dom_doc}->toString();
99 }
100 close $FH;
101 $self->{dom_doc}->dispose();
102 }
103
104 #
105 # 3.8 Interface Declaration
106 #
107 # See 1.2.8 Interfaces
108 #
109
110 sub visitBaseInterface {
111 # empty
112 }
113
114 sub visitRegularInterface {
115 my $self = shift;
116 my ($node, $dom_parent) = @_;
117
118 # my $str = ' binding for ' . $node->{xsd_name} . q{ };
119 # my $comment = $self->{dom_doc}->createComment($str);
120 # $dom_parent->appendChild($comment);
121
122 my $binding = $self->{dom_doc}->createElement($self->{wsdl} . 'binding');
123 $binding->setAttribute('name', $node->{xsd_name} . 'Binding');
124 $binding->setAttribute('type', 'tns:' . $node->{xsd_name});
125 $dom_parent->appendChild($binding);
126
127 my $soap_binding = $self->{dom_doc}->createElement($self->{soap} . 'binding');
128 $soap_binding->setAttribute('style', 'rpc');
129 $soap_binding->setAttribute('transport', 'http://schemas.xmlsoap.org/soap/http');
130 $binding->appendChild($soap_binding);
131
132 $self->{itf} = $node->{xsd_name};
133 foreach (values %{$node->{hash_attribute_operation}}) {
134 $self->_get_defn($_)->visit($self, $binding);
135 }
136 delete $self->{itf};
137 }
138
139 #
140 # 3.9 Value Declaration
141 #
142
143 #
144 # 3.11 Type Declaration
145 #
146
147 sub visitTypeDeclarator {
148 # empty
149 }
150
151 sub visitStructType {
152 # empty
153 }
154
155 sub visitUnionType {
156 # empty
157 }
158
159 sub visitEnumType {
160 # empty
161 }
162
163 #
164 # 3.12 Exception Declaration
165 #
166
167 sub visitException {
168 # empty
169 }
170
171 #
172 # 3.13 Operation Declaration
173 #
174 # See 1.2.8.2 Interface as Binding Operations
175 #
176
177 sub visitOperation {
178 my $self = shift;
179 my ($node, $dom_parent) = @_;
180
181 my $operation = $self->{dom_doc}->createElement($self->{wsdl} . 'operation');
182 $operation->setAttribute('name', $node->{idf});
183 $dom_parent->appendChild($operation);
184
185 my $soap_operation = $self->{dom_doc}->createElement($self->{soap} . 'operation');
186 $soap_operation->setAttribute('soapAction', $self->{itf} . '#' . $node->{idf});
187 $operation->appendChild($soap_operation);
188
189 my $input = $self->{dom_doc}->createElement($self->{wsdl} . 'input');
190 $operation->appendChild($input);
191
192 my $soap_body = $self->{dom_doc}->createElement($self->{soap} . 'body');
193 $soap_body->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/');
194 $soap_body->setAttribute('use', 'literal');
195 $input->appendChild($soap_body);
196
197 my $output = $self->{dom_doc}->createElement($self->{wsdl} . 'output');
198 $operation->appendChild($output);
199
200 $soap_body = $self->{dom_doc}->createElement($self->{soap} . 'body');
201 $soap_body->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/');
202 $soap_body->setAttribute('use', 'literal');
203 $output->appendChild($soap_body);
204
205 foreach (@{$node->{list_raise}}) {
206 my $defn = $self->_get_defn($_);
207
208 my $fault = $self->{dom_doc}->createElement($self->{wsdl} . 'fault');
209 $fault->setAttribute('name', $defn->{xsd_name});
210 $operation->appendChild($fault);
211
212 my $soap_fault = $self->{dom_doc}->createElement($self->{soap} . 'fault');
213 $soap_fault->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/');
214 $soap_fault->setAttribute('name', $defn->{xsd_name});
215 $soap_fault->setAttribute('use', 'literal');
216 $fault->appendChild($soap_fault);
217 }
218
219 unless (exists $node->{modifier}) { # oneway
220 my $fault = $self->{dom_doc}->createElement($self->{wsdl} . 'fault');
221 $fault->setAttribute('name', 'CORBA.SystemException');
222 $operation->appendChild($fault);
223
224 my $soap_fault = $self->{dom_doc}->createElement($self->{soap} . 'fault');
225 $soap_fault->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/');
226 $soap_fault->setAttribute('name', 'CORBA.SystemException');
227 $soap_fault->setAttribute('use', 'literal');
228 $fault->appendChild($soap_fault);
229 }
230 }
231
232 1;
233