| 1 | # | ||
| 2 | # Interface Definition Language (OMG IDL CORBA v3.0) | ||
| 3 | # | ||
| 4 | # CORBA to WSDL/SOAP Interworking Specification, Version 1.1 February 2005 | ||
| 5 | # | ||
| 6 | |||
| 7 | package CORBA::XMLSchemas::WsdlVisitor; | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | our $VERSION = '2.60'; | ||
| 13 | |||
| 14 | use CORBA::XMLSchemas::BaseVisitor; | ||
| 15 | use base qw(CORBA::XMLSchemas::BaseVisitor); | ||
| 16 | |||
| 17 | use File::Basename; | ||
| 18 | use POSIX qw(ctime); | ||
| 19 | use XML::DOM; | ||
| 20 | use CORBA::XMLSchemas::XsdImportVisitor; | ||
| 21 | use CORBA::XMLSchemas::RelaxngImportVisitor; | ||
| 22 | |||
| 23 | # needs $node->{xsd_name} $node->{xsd_qname} (XsdNameVisitor) | ||
| 24 | |||
| 25 | sub new { | ||
| 26 | my $proto = shift; | ||
| 27 | my $class = ref($proto) || $proto; | ||
| 28 | my $self = {}; | ||
| 29 | bless $self, $class; | ||
| 30 | my ($parser, $ext_schema) = @_; | ||
| 31 | $self->{beautify} = $parser->YYData->{opt_t}; | ||
| 32 | $self->{ext_schema} = 'xsd:'; | ||
| 33 | $self->{ext_schema} = $ext_schema . ':' if (defined $ext_schema); | ||
| 34 | $self->{_tns} = 'tns'; | ||
| 35 | $self->{tns} = 'tns:'; | ||
| 36 | $self->{_xsd} = 'xs'; | ||
| 37 | $self->{xsd} = 'xs:'; | ||
| 38 | $self->{_wsdl} = 'wsdl'; | ||
| 39 | $self->{wsdl} = $parser->YYData->{opt_q} ? 'wsdl:' : q{}; | ||
| 40 | $self->{_corba} = 'corba'; | ||
| 41 | $self->{corba} = 'corba:'; | ||
| 42 | $self->{srcname} = $parser->YYData->{srcname}; | ||
| 43 | $self->{srcname_size} = $parser->YYData->{srcname_size}; | ||
| 44 | $self->{srcname_mtime} = $parser->YYData->{srcname_mtime}; | ||
| 45 | $self->{symbtab} = $parser->YYData->{symbtab}; | ||
| 46 | $self->{base} = $parser->YYData->{opt_b} || q{}; | ||
| 47 | $self->{root} = $parser->YYData->{root}; | ||
| 48 | my $filename = basename($self->{srcname}, '.idl') . '.wsdl'; | ||
| 49 | $self->open_stream($filename); | ||
| 50 | $self->{done_hash} = {}; | ||
| 51 | $self->{num_key} = 'num_inc_wsdl'; | ||
| 52 | if ($self->{ext_schema} eq 'rng:') { | ||
| 53 | $self->{schema_visitor} = new CORBA::XMLSchemas::RelaxngImportVisitor($parser); | ||
| 54 | } | ||
| 55 | else { | ||
| 56 | $self->{schema_visitor} = new CORBA::XMLSchemas::XsdImportVisitor($parser); | ||
| 57 | } | ||
| 58 | $self->{ports} = []; | ||
| 59 | return $self; | ||
| 60 | } | ||
| 61 | |||
| 62 | # | ||
| 63 | # 3.5 OMG IDL Specification | ||
| 64 | # | ||
| 65 | |||
| 66 | sub visitSpecification { | ||
| 67 | my $self = shift; | ||
| 68 | my ($node) = @_; | ||
| 69 | my $FH = $self->{out}; | ||
| 70 | |||
| 71 | $self->{dom_doc} = new XML::DOM::Document(); | ||
| 72 | $self->{dom_parent} = $self->{dom_doc}; | ||
| 73 | |||
| 74 | my $definitions = $self->{dom_doc}->createElement($self->{wsdl} . 'definitions'); | ||
| 75 | $definitions->setAttribute('targetNamespace', 'http://www.omg.org/IDL-Mapped/'); | ||
| 76 | $definitions->setAttribute('xmlns:' . $self->{_tns}, 'http://www.omg.org/IDL-Mapped/'); | ||
| 77 | $definitions->setAttribute('xmlns:' . $self->{_xsd}, 'http://www.w3.org/2001/XMLSchema'); | ||
| 78 | if ($self->{wsdl}) { | ||
| 79 | $definitions->setAttribute('xmlns:' . $self->{_wsdl}, 'http://schemas.xmlsoap.org/wsdl/'); | ||
| 80 | } | ||
| 81 | else { | ||
| 82 | $definitions->setAttribute('xmlns', 'http://schemas.xmlsoap.org/wsdl/'); | ||
| 83 | } | ||
| 84 | $definitions->setAttribute('xmlns:' . $self->{_corba}, 'http://www.omg.org/IDL-WSDL/1.0/'); | ||
| 85 | $self->{dom_parent}->appendChild($definitions); | ||
| 86 | |||
| 87 | my $import = $self->{dom_doc}->createElement($self->{wsdl} . 'import'); | ||
| 88 | $import->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/'); | ||
| 89 | $import->setAttribute('location', $self->{base} . 'corba.wsdl'); | ||
| 90 | $definitions->appendChild($import); | ||
| 91 | |||
| 92 | my $types = $self->{dom_doc}->createElement($self->{wsdl} . 'types'); | ||
| 93 | $definitions->appendChild($types); | ||
| 94 | |||
| 95 | $node->visit($self->{schema_visitor}, $self->{dom_doc}, $types); | ||
| 96 | |||
| 97 | foreach (@{$node->{list_decl}}) { | ||
| 98 | $self->_get_defn($_)->visit($self, $definitions); | ||
| 99 | } | ||
| 100 | foreach (@{$self->{ports}}) { | ||
| 101 | $definitions->appendChild($_); | ||
| 102 | } | ||
| 103 | |||
| 104 | if ($self->{beautify}) { | ||
| 105 | print $FH "<!-- This file was generated (by ", $0, "). DO NOT modify it -->\n"; | ||
| 106 | print $FH "<!-- From file : ", $self->{srcname}, ", ", $self->{srcname_size}, " octets, ", POSIX::ctime($self->{srcname_mtime}); | ||
| 107 | print $FH "-->\n"; | ||
| 108 | print $FH "\n"; | ||
| 109 | print $FH $self->_beautify($self->{dom_doc}->toString()); | ||
| 110 | print $FH "\n\n"; | ||
| 111 | print $FH "<!-- end of file : ", $self->{filename}, " -->\n"; | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | print $FH $self->{dom_doc}->toString(); | ||
| 115 | } | ||
| 116 | close $FH; | ||
| 117 | $self->{dom_doc}->dispose(); | ||
| 118 | } | ||
| 119 | |||
| 120 | # | ||
| 121 | # 3.8 Interface Declaration | ||
| 122 | # | ||
| 123 | # See 1.2.8 Interfaces | ||
| 124 | # | ||
| 125 | |||
| 126 | sub visitRegularInterface { | ||
| 127 | my $self = shift; | ||
| 128 | my ($node, $dom_parent) = @_; | ||
| 129 | |||
| 130 | my $str = ' interface: ' . $node->{xsd_name} . q{ }; | ||
| 131 | my $comment = $self->{dom_doc}->createComment($str); | ||
| 132 | $dom_parent->appendChild($comment); | ||
| 133 | |||
| 134 | foreach (@{$node->{list_decl}}) { | ||
| 135 | $self->_get_defn($_)->visit($self, $dom_parent); | ||
| 136 | } | ||
| 137 | |||
| 138 | if (scalar keys %{$node->{hash_attribute_operation}}) { | ||
| 139 | my $str = ' port for ' . $node->{xsd_name} . q{ }; | ||
| 140 | my $comment = $self->{dom_doc}->createComment($str); | ||
| 141 | push @{$self->{ports}}, $comment; | ||
| 142 | |||
| 143 | my $portType = $self->{dom_doc}->createElement($self->{wsdl} . 'portType'); | ||
| 144 | $portType->setAttribute('name', $node->{xsd_name}); | ||
| 145 | push @{$self->{ports}}, $portType; | ||
| 146 | |||
| 147 | foreach (values %{$node->{hash_attribute_operation}}) { | ||
| 148 | my $defn = $self->_get_defn($_); | ||
| 149 | if ($defn->isa('Operation')) { | ||
| 150 | $self->_operation($defn, $portType); | ||
| 151 | } | ||
| 152 | else { | ||
| 153 | $self->_operation($defn->{_get}, $portType); | ||
| 154 | $self->_operation($defn->{_set}, $portType) | ||
| 155 | if (exists $defn->{_set}); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | sub _operation { | ||
| 162 | my $self = shift; | ||
| 163 | my ($node, $dom_parent) = @_; | ||
| 164 | |||
| 165 | my $operation = $self->{dom_doc}->createElement($self->{wsdl} . 'operation'); | ||
| 166 | $operation->setAttribute('name', $node->{idf}); | ||
| 167 | $dom_parent->appendChild($operation); | ||
| 168 | |||
| 169 | my $input = $self->{dom_doc}->createElement($self->{wsdl} . 'input'); | ||
| 170 | $input->setAttribute('message', $self->{tns} . $node->{xsd_name}); | ||
| 171 | $operation->appendChild($input); | ||
| 172 | |||
| 173 | my $output = $self->{dom_doc}->createElement($self->{wsdl} . 'output'); | ||
| 174 | $output->setAttribute('message', $self->{tns} . $node->{xsd_name} . 'Response'); | ||
| 175 | $operation->appendChild($output); | ||
| 176 | |||
| 177 | foreach (@{$node->{list_raise}}) { | ||
| 178 | my $defn = $self->_get_defn($_); | ||
| 179 | |||
| 180 | my $fault = $self->{dom_doc}->createElement($self->{wsdl} . 'fault'); | ||
| 181 | $fault->setAttribute('name', $defn->{xsd_name}); | ||
| 182 | $fault->setAttribute('message', $self->{tns} . '_exception.' . $defn->{xsd_name}); | ||
| 183 | $operation->appendChild($fault); | ||
| 184 | } | ||
| 185 | |||
| 186 | unless (exists $node->{modifier}) { # oneway | ||
| 187 | my $fault = $self->{dom_doc}->createElement($self->{wsdl} . 'fault'); | ||
| 188 | $fault->setAttribute('name', 'CORBA.SystemException'); | ||
| 189 | $fault->setAttribute('message', $self->{corba} . 'CORBA.SystemExceptionMessage'); | ||
| 190 | $operation->appendChild($fault); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | sub visitAbstractInterface { | ||
| 195 | my $self = shift; | ||
| 196 | my ($node, $dom_parent) = @_; | ||
| 197 | |||
| 198 | my $str = ' abstract interface: ' . $node->{xsd_name} . q{ }; | ||
| 199 | my $comment = $self->{dom_doc}->createComment($str); | ||
| 200 | $dom_parent->appendChild($comment); | ||
| 201 | |||
| 202 | foreach (@{$node->{list_decl}}) { | ||
| 203 | $self->_get_defn($_)->visit($self, $dom_parent); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | # | ||
| 208 | # 3.9 Value Declaration | ||
| 209 | # | ||
| 210 | |||
| 211 | sub visitValue { | ||
| 212 | # empty | ||
| 213 | } | ||
| 214 | |||
| 215 | # | ||
| 216 | # 3.11 Type Declaration | ||
| 217 | # | ||
| 218 | |||
| 219 | sub visitTypeDeclarator { | ||
| 220 | # empty | ||
| 221 | } | ||
| 222 | |||
| 223 | sub visitStructType { | ||
| 224 | # empty | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | sub visitUnionType { | ||
| 229 | # empty | ||
| 230 | } | ||
| 231 | |||
| 232 | sub visitEnumType { | ||
| 233 | # empty | ||
| 234 | } | ||
| 235 | |||
| 236 | # | ||
| 237 | # 3.12 Exception Declaration | ||
| 238 | # | ||
| 239 | |||
| 240 | sub visitException { | ||
| 241 | # empty | ||
| 242 | } | ||
| 243 | |||
| 244 | # | ||
| 245 | # 3.13 Operation Declaration | ||
| 246 | # | ||
| 247 | # See 1.2.8.2 Interface as Binding Operations | ||
| 248 | # | ||
| 249 | |||
| 250 | sub visitOperation { | ||
| 251 | my $self = shift; | ||
| 252 | my ($node, $dom_parent) = @_; | ||
| 253 | |||
| 254 | my $message = $self->{dom_doc}->createElement($self->{wsdl} . 'message'); | ||
| 255 | $message->setAttribute('name', $node->{xsd_name}); | ||
| 256 | $dom_parent->appendChild($message); | ||
| 257 | |||
| 258 | foreach (@{$node->{list_param}}) { # parameter | ||
| 259 | if ( $_->{attr} eq 'in' | ||
| 260 | or $_->{attr} eq 'inout' ) { | ||
| 261 | $_->visit($self, $message); # parameter | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | my $type = $self->_get_defn($node->{type}); | ||
| 266 | $message = $self->{dom_doc}->createElement($self->{wsdl} . 'message'); | ||
| 267 | $message->setAttribute('name', $node->{xsd_name} . 'Response'); | ||
| 268 | $dom_parent->appendChild($message); | ||
| 269 | |||
| 270 | unless ($type->isa('VoidType')) { | ||
| 271 | my $part = $self->{dom_doc}->createElement($self->{wsdl} . 'part'); | ||
| 272 | $part->setAttribute('name', '_return'); | ||
| 273 | $part->setAttribute('type', $type->{xsd_qname}); | ||
| 274 | $message->appendChild($part); | ||
| 275 | } | ||
| 276 | |||
| 277 | foreach (@{$node->{list_param}}) { # parameter | ||
| 278 | if ( $_->{attr} eq 'inout' | ||
| 279 | or $_->{attr} eq 'out' ) { | ||
| 280 | $_->visit($self, $message); # parameter | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | foreach (@{$node->{list_raise}}) { | ||
| 285 | my $defn = $self->_get_defn($_); | ||
| 286 | |||
| 287 | my $message = $self->{dom_doc}->createElement($self->{wsdl} . 'message'); | ||
| 288 | $message->setAttribute('name', '_exception.' . $defn->{xsd_name}); | ||
| 289 | $dom_parent->appendChild($message); | ||
| 290 | |||
| 291 | my $part = $self->{dom_doc}->createElement($self->{wsdl} . 'part'); | ||
| 292 | $part->setAttribute('name', 'exception'); | ||
| 293 | $part->setAttribute('type', $defn->{xsd_qname}); | ||
| 294 | $message->appendChild($part); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | sub visitParameter { | ||
| 299 | my $self = shift; | ||
| 300 | my ($node, $dom_parent) = @_; | ||
| 301 | my $type = $self->_get_defn($node->{type}); | ||
| 302 | |||
| 303 | my $part = $self->{dom_doc}->createElement($self->{wsdl} . 'part'); | ||
| 304 | $part->setAttribute('name', $node->{xsd_name}); | ||
| 305 | $part->setAttribute('type', $type->{xsd_qname}); | ||
| 306 | $dom_parent->appendChild($part); | ||
| 307 | } | ||
| 308 | |||
| 309 | 1; | ||
| 310 |