XMLSchemas/XsdVisitor.pm untested

filter: Statementstmt 0.0% 0 / 553 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 80 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 0.0% 0 / 32 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 876 CC 70 SCAR 38.4
CC
70
Cov
0%
visitTypeDeclarator
156.0
visitOperation
72.0
visitRegularValue
56.0
CRAP 46.4
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::XsdVisitor;
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
21 # needs $node->{xsd_name} $node->{xsd_qname} (XsdNameVisitor)
22
23 sub new {
24 my $proto = shift;
25 my $class = ref($proto) || $proto;
26 my $self = {};
27 bless $self, $class;
28 my ($parser, $standalone) = @_;
29 $self->{standalone} = $standalone;
30 $self->{beautify} = $parser->YYData->{opt_t};
31 $self->{_xsd} = 'xs';
32 $self->{xsd} = $parser->YYData->{opt_q} ? 'xs:' : q{};
33 $self->{_tns} = 'tns';
34 $self->{tns} = 'tns:';
35 $self->{_corba} = 'corba';
36 $self->{corba} = 'corba:';
37 $self->{srcname} = $parser->YYData->{srcname};
38 $self->{srcname_size} = $parser->YYData->{srcname_size};
39 $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
40 $self->{symbtab} = $parser->YYData->{symbtab};
41 $self->{base} = $parser->YYData->{opt_b} || q{};
42 $self->{root} = $parser->YYData->{root};
43 my $filename = basename($self->{srcname}, '.idl') . '.xsd';
44 $self->open_stream($filename);
45 $self->{done_hash} = {};
46 $self->{num_key} = 'num_inc_xsd';
47 $self->{need_corba} = undef;
48 return $self;
49 }
50
51 sub _standalone {
52 my $self = shift;
53 my ($node, $dom_parent) = @_;
54
55 if ($self->{standalone}) {
56 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
57 $element->setAttribute("name", $node->{xsd_name});
58 $element->setAttribute("type", $node->{xsd_qname});
59 $dom_parent->appendChild($element);
60 }
61 }
62
63 #
64 # 3.5 OMG IDL Specification
65 #
66
67 sub visitSpecification {
68 my $self = shift;
69 my ($node) = @_;
70 my $FH = $self->{out};
71
72 $self->{dom_doc} = new XML::DOM::Document();
73 $self->{dom_parent} = $self->{dom_doc};
74
75 my $schema = $self->{dom_doc}->createElement($self->{xsd} . 'schema');
76 $schema->setAttribute('targetNamespace', 'http://www.omg.org/IDL-Mapped/');
77 unless ($self->{xsd}) {
78 $schema->setAttribute('xmlns', 'http://www.w3.org/2001/XMLSchema');
79 }
80 $schema->setAttribute('xmlns:' . $self->{_xsd}, 'http://www.w3.org/2001/XMLSchema');
81 $schema->setAttribute('xmlns:' . $self->{_corba}, 'http://www.omg.org/IDL-WSDL/1.0/');
82 $schema->setAttribute('xmlns:' . $self->{_tns}, 'http://www.omg.org/IDL-Mapped/');
83 if ($self->{xsd}) {
84 $schema->setAttribute('elementFormDefault', 'qualified');
85 $schema->setAttribute('attributeFormDefault', 'unqualified');
86 }
87 $self->{dom_parent}->appendChild($schema);
88
89 if ($self->{root}->{need_corba} or $self->{root}->{need_any}) {
90 my $import = $self->{dom_doc}->createElement($self->{xsd} . 'import');
91 $import->setAttribute('namespace', 'http://www.omg.org/IDL-WSDL/1.0/');
92 $import->setAttribute('schemaLocation', $self->{base} . 'corba.xsd');
93 $schema->appendChild($import);
94 }
95
96 if (exists $node->{list_import}) {
97 foreach (@{$node->{list_import}}) {
98 $_->visit($self, $schema);
99 }
100 }
101 foreach (@{$node->{list_decl}}) {
102 $self->_get_defn($_)->visit($self, $schema);
103 }
104
105 if ($self->{beautify}) {
106 print $FH "<!-- This file was generated (by ",$0,"). DO NOT modify it -->\n";
107 print $FH "<!-- From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
108 print $FH "-->\n";
109 print $FH "\n";
110 print $FH $self->_beautify($self->{dom_doc}->toString());
111 print $FH "\n\n";
112 print $FH "<!-- end of file : ",$self->{filename}," -->\n";
113 }
114 else {
115 print $FH $self->{dom_doc}->toString();
116 }
117 close $FH;
118 $self->{dom_doc}->dispose();
119 }
120
121 #
122 # 3.9 Value Declaration
123 #
124 # See 1.2.7.10 ValueType
125 #
126
127 sub visitRegularValue {
128 my $self = shift;
129 my ($node, $dom_parent, $indirect) = @_;
130
131 foreach (@{$node->{list_decl}}) {
132 my $value_element = $self->_get_defn($_);
133 if ( $value_element->isa('StateMembers')
134 or $value_element->isa('Initializer')
135 or $value_element->isa('Operation')
136 or $value_element->isa('Attributes') ) {
137 next;
138 }
139 $value_element->visit($self, $dom_parent);
140 }
141
142 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
143 $complexType->setAttribute('name', $node->{xsd_name});
144 $dom_parent->appendChild($complexType);
145
146 my $extension;
147 if (exists $node->{inheritance} and exists $node->{inheritance}->{list_value}) {
148 for (@{$node->{inheritance}->{list_value}}) {
149 my $base = $self->_get_defn($_);
150 next unless ($base->isa('RegularValue'));
151 my $complexContent = $self->{dom_doc}->createElement($self->{xsd} . 'complexContent');
152 $complexType->appendChild($complexContent);
153 $extension = $self->{dom_doc}->createElement($self->{xsd} . 'extension');
154 $extension->setAttribute('base', $self->{tns} . $base->{xsd_name});
155 $complexContent->appendChild($extension);
156 last;
157 }
158 }
159
160 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
161 if ($extension) {
162 $extension->appendChild($sequence);
163 }
164 else {
165 $complexType->appendChild($sequence);
166 $self->_value_id($complexType);
167 }
168
169 foreach (@{$node->{list_decl}}) {
170 my $defn = $self->_get_defn($_);
171 if ($defn->isa('StateMembers')) {
172 $defn->visit($self, $sequence);
173 }
174 }
175
176 $self->_standalone($node, $dom_parent) unless ($indirect);
177 }
178
179 sub _value_id {
180 my $self = shift;
181 my ($dom_parent) = @_;
182
183 my $attribute = $self->{dom_doc}->createElement($self->{xsd} . 'attribute');
184 $attribute->setAttribute('name', 'id');
185 $attribute->setAttribute('type', $self->{xsd} . 'ID');
186 $attribute->setAttribute('use', 'optional');
187 $dom_parent->appendChild($attribute);
188
189 }
190
191 sub visitStateMember {
192 my $self = shift;
193 my ($node, $dom_parent) = @_;
194
195 my $type = $self->_get_defn($node->{type});
196 if (exists $node->{array_size}) {
197 # like Array
198 my $idx = scalar(@{$node->{array_size}}) - 1;
199 my $current = $type;
200 while ($current->isa('SequenceType')) {
201 $idx ++;
202 $current = $self->_get_defn($current->{type});
203 }
204
205 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
206 $element->setAttribute('name', $node->{xsd_name});
207 $element->setAttribute('maxOccurs', '1');
208 $element->setAttribute('minOccurs', '1');
209 $dom_parent->appendChild($element);
210
211 $current = $element;
212 my $first = 1;
213 foreach (reverse @{$node->{array_size}}) {
214 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
215 $current->appendChild($complexType);
216
217 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
218 $complexType->appendChild($sequence);
219
220 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
221 my $item = ($idx != 0) ? 'item' . $idx : 'item';
222 $element->setAttribute('name', $item);
223 $element->setAttribute('minOccurs', $self->_value($_));
224 $element->setAttribute('maxOccurs', $self->_value($_));
225 $sequence->appendChild($element);
226
227 $current = $element;
228 $idx --;
229 $first = 0;
230 }
231 if ($type->isa('SequenceType')) {
232 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
233 $current->appendChild($complexType);
234
235 $type->visit($self, $complexType);
236 }
237 else {
238 $current->setAttribute('type', $type->{xsd_qname});
239 }
240 }
241 else {
242 if ($type->isa('RegularValue')) {
243 my $choice = $self->{dom_doc}->createElement($self->{xsd} . 'choice');
244 $dom_parent->appendChild($choice);
245
246 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
247 $element->setAttribute('name', $node->{xsd_name});
248 $element->setAttribute('maxOccurs', '1');
249 $element->setAttribute('minOccurs', '1');
250 $element->setAttribute('type', $type->{xsd_qname});
251 $choice->appendChild($element);
252
253 $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
254 $element->setAttribute('name', '_REF_' . $node->{xsd_name});
255 $element->setAttribute('maxOccurs', '1');
256 $element->setAttribute('minOccurs', '1');
257 $element->setAttribute('type', $self->{corba} . '_VALREF');
258 $choice->appendChild($element);
259 }
260 else {
261 # like Single
262 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
263 $element->setAttribute('name', $node->{xsd_name});
264 $element->setAttribute('maxOccurs', '1');
265 $element->setAttribute('minOccurs', '1');
266 $element->setAttribute('nillable', 'true')
267 if ($type->isa('StringType') or $type->isa('WideStringType'));
268 $dom_parent->appendChild($element);
269
270 if ($type->isa('SequenceType')) {
271 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
272 $element->appendChild($complexType);
273
274 $type->visit($self, $complexType);
275 }
276 else {
277 $element->setAttribute('type', $type->{xsd_qname});
278 }
279 }
280 }
281 }
282
283 sub visitBoxedValue {
284 my $self = shift;
285 my ($node, $dom_parent, $indirect) = @_;
286
287 my $type = $self->_get_defn($node->{type});
288 if ( $type->isa('StructType')
289 or $type->isa('UnionType')
290 or $type->isa('EnumType') ) {
291 $type->visit($self, $dom_parent);
292 }
293
294 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
295 $complexType->setAttribute('name', $node->{xsd_name});
296 $dom_parent->appendChild($complexType);
297
298 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
299 $complexType->appendChild($sequence);
300
301 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
302 $element->setAttribute('name', 'value');
303 $element->setAttribute('maxOccurs', '1');
304 $element->setAttribute('minOccurs', '1');
305 $element->setAttribute('nillable', 'true')
306 if ($type->isa('StringType') or $type->isa('WideStringType'));
307 $sequence->appendChild($element);
308
309 if ($type->isa('SequenceType')) {
310 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
311 $element->appendChild($complexType);
312
313 $type->visit($self, $complexType);
314 }
315 else {
316 $element->setAttribute('type', $type->{xsd_qname});
317 }
318
319 $self->_value_id($complexType);
320
321 $self->_standalone($node, $dom_parent) unless ($indirect);
322 }
323
324 #
325 # 3.11 Type Declaration
326 #
327 # See 1.2.7.3 Typedefs
328 #
329
330 sub visitTypeDeclarator {
331 my $self = shift;
332 my ($node, $dom_parent, $indirect) = @_;
333
334 my $type = $self->_get_defn($node->{type});
335 while ($type->isa('TypeDeclarator') and !exists $type->{array_size}) {
336 $type = $self->_get_defn($type->{type});
337 }
338
339 if ( $type->isa('StructType')
340 or $type->isa('UnionType')
341 or $type->isa('EnumType') ) {
342 $type->visit($self, $dom_parent);
343 }
344
345 if (exists $node->{array_size}) {
346 #
347 # See 1.2.7.6 Arrays
348 #
349 warn __PACKAGE__,"::visitTypeDecalarator $node->{idf} : empty array_size.\n"
350 unless (@{$node->{array_size}});
351
352 my $idx = scalar(@{$node->{array_size}}) - 1;
353 my $current = $type;
354 while ($current->isa('SequenceType')) {
355 $idx ++;
356 $current = $self->_get_defn($current->{type});
357 }
358
359 $current = $dom_parent;
360 my $first = 1;
361 foreach (reverse @{$node->{array_size}}) {
362 my $complexType;
363 if ($indirect and $first) {
364 $complexType = $dom_parent;
365 }
366 else {
367 $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
368 $complexType->setAttribute("name", $node->{xsd_name})
369 if ($first);
370 $current->appendChild($complexType);
371 }
372
373 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
374 $complexType->appendChild($sequence);
375
376 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
377 my $item = ($idx != 0) ? 'item' . $idx : 'item';
378 $element->setAttribute('name', $item);
379 $element->setAttribute('minOccurs', $self->_value($_));
380 $element->setAttribute('maxOccurs', $self->_value($_));
381 $sequence->appendChild($element);
382
383 $current = $element;
384 $idx --;
385 $first = 0;
386 }
387 if ($type->isa('SequenceType')) {
388 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
389 $current->appendChild($complexType);
390
391 $type->visit($self, $complexType);
392 }
393 else {
394 $current->setAttribute("type", $type->{xsd_qname});
395 }
396 }
397 else {
398 if ( $type->isa('SequenceType')
399 or $type->isa('TypeDeclarator') ) {
400 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
401 $complexType->setAttribute('name', $node->{xsd_name});
402 $dom_parent->appendChild($complexType);
403
404 $type->visit($self, $complexType, 1);
405 }
406 else {
407 if ( $type->isa('Value')
408 or $type->isa('StructType')
409 or $type->isa('UnionType') ) {
410 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
411 $complexType->setAttribute('name', $node->{xsd_name});
412 $dom_parent->appendChild($complexType);
413
414 my $complexContext = $self->{dom_doc}->createElement($self->{xsd} . 'complexContent');
415 $complexType->appendChild($complexContext);
416
417 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
418 $restriction->setAttribute('base', $type->{xsd_qname});
419 $complexContext->appendChild($restriction);
420
421 $type->visit($self, $restriction, 1);
422 }
423 else {
424 my $simpleType = $self->{dom_doc}->createElement($self->{xsd} . 'simpleType');
425 $simpleType->setAttribute('name', $node->{xsd_name});
426 $dom_parent->appendChild($simpleType);
427
428 if ( $type->isa('EnumType')
429 or $type->isa('BaseInterface') ) {
430 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
431 $restriction->setAttribute('base', $type->{xsd_qname});
432 $simpleType->appendChild($restriction);
433 }
434 else {
435 $type->visit($self, $simpleType);
436 }
437 }
438 }
439 }
440
441 $self->_standalone($node, $dom_parent) unless ($indirect);
442 }
443
444 #
445 # 3.11.1 Basic Types
446 #
447
448 sub visitCharType {
449 my $self = shift;
450 my ($node, $dom_parent) = @_;
451
452 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
453 $restriction->setAttribute('base', $node->{xsd_qname});
454 $dom_parent->appendChild($restriction);
455
456 my $length = $self->{dom_doc}->createElement($self->{xsd} . 'length');
457 $length->setAttribute('value', '1');
458 $length->setAttribute('fixed', 'true');
459 $restriction->appendChild($length);
460 }
461
462 sub visitBasicType {
463 my $self = shift;
464 my ($node, $dom_parent) = @_;
465
466 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
467 $restriction->setAttribute('base', $node->{xsd_qname});
468 $dom_parent->appendChild($restriction);
469 }
470
471 #
472 # 3.11.2 Constructed Types
473 #
474 # 3.11.2.1 Structures
475 #
476 # See 1.2.7.2 Structure
477 #
478
479 sub visitStructType {
480 my $self = shift;
481 my ($node, $dom_parent, $indirect) = @_;
482
483 if ($indirect) {
484 $self->_StructType_Content($node, $dom_parent);
485 return;
486 }
487
488 return if (exists $self->{done_hash}->{$node->{xsd_name}});
489 $self->{done_hash}->{$node->{xsd_name}} = 1;
490
491 foreach (@{$node->{list_expr}}) {
492 my $type = $self->_get_defn($_->{type});
493 if ( $type->isa('StructType')
494 or $type->isa('UnionType') ) {
495 $type->visit($self, $dom_parent);
496 }
497 }
498
499 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
500 $complexType->setAttribute('name', $node->{xsd_name});
501 $dom_parent->appendChild($complexType);
502
503 $self->_StructType_Content($node, $complexType);
504
505 $self->_standalone($node, $dom_parent) unless ($indirect);
506 }
507
508 sub _StructType_Content {
509 my $self = shift;
510 my ($node, $dom_parent) = @_;
511
512 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
513 $dom_parent->appendChild($sequence);
514
515 foreach (@{$node->{list_member}}) {
516 $self->_get_defn($_)->visit($self, $sequence);
517 }
518 }
519
520 sub visitMember {
521 my $self = shift;
522 my ($node, $dom_parent) = @_;
523
524 my $type = $self->_get_defn($node->{type});
525
526 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
527 $element->setAttribute('name', $node->{xsd_name});
528 $element->setAttribute('maxOccurs', '1');
529 $element->setAttribute('minOccurs', '1');
530 $dom_parent->appendChild($element);
531
532 my $current = $element;
533 if (exists $node->{array_size}) {
534 my $idx = scalar(@{$node->{array_size}}) - 1;
535 my $curr = $type;
536 while ($curr->isa('SequenceType')) {
537 $idx ++;
538 $curr = $self->_get_defn($curr->{type});
539 }
540 my $first = 1;
541 foreach (reverse @{$node->{array_size}}) {
542 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
543 $current->appendChild($complexType);
544
545 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
546 $complexType->appendChild($sequence);
547
548 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
549 my $item = ($idx != 0) ? 'item' . $idx : 'item';
550 $element->setAttribute('name', $item);
551 $element->setAttribute('minOccurs', $self->_value($_));
552 $element->setAttribute('maxOccurs', $self->_value($_));
553 $sequence->appendChild($element);
554
555 $current = $element;
556 $idx --;
557 $first = 0;
558 }
559 }
560 if ($type->isa('SequenceType')) {
561 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
562 $current->appendChild($complexType);
563
564 $type->visit($self, $complexType);
565 }
566 else {
567 $current->setAttribute('type', $type->{xsd_qname});
568 }
569 }
570
571 # 3.11.2.2 Discriminated Unions
572 #
573 # See 1.2.7.4 Unions
574 #
575
576 sub visitUnionType {
577 my $self = shift;
578 my ($node, $dom_parent, $indirect) = @_;
579
580 if ($indirect) {
581 $self->_UnionType_Content($node, $dom_parent);
582 return;
583 }
584
585 return if (exists $self->{done_hash}->{$node->{xsd_name}});
586 $self->{done_hash}->{$node->{xsd_name}} = 1;
587
588 foreach (@{$node->{list_expr}}) {
589 my $type = $self->_get_defn($_->{element}->{type});
590 if ( $type->isa('StructType')
591 or $type->isa('UnionType') ) {
592 $type->visit($self, $dom_parent);
593 }
594 }
595
596 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
597 $complexType->setAttribute('name', $node->{xsd_name});
598 $dom_parent->appendChild($complexType);
599
600 $self->_UnionType_Content($node, $complexType);
601
602 $self->_standalone($node, $dom_parent) unless ($indirect);
603 }
604
605 sub _UnionType_Content {
606 my $self = shift;
607 my ($node, $dom_parent) = @_;
608
609 my $type = $self->_get_defn($node->{type});
610
611 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
612 $dom_parent->appendChild($sequence);
613
614 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
615 $element->setAttribute('name', 'discriminator');
616 $sequence->appendChild($element);
617
618 if ($type->isa('EnumType')) {
619 $type->visit($self, $element, 1);
620 }
621 else {
622 $element->setAttribute('type', $type->{xsd_qname});
623 }
624
625 my $choice = $self->{dom_doc}->createElement($self->{xsd} . 'choice');
626 $sequence->appendChild($choice);
627
628 foreach (@{$node->{list_expr}}) {
629 $_->visit($self, $choice); # case
630 }
631 }
632
633 sub visitCase {
634 my $self = shift;
635 my ($node, $dom_parent) = @_;
636
637 my $str = ' case';
638 my $first = 1;
639 foreach (@{$node->{list_label}}) {
640 $str .= ',' unless ($first);
641 $str .= q{ };
642 if ($_->isa('Default')) {
643 $str .= 'default';
644 }
645 else {
646 $str .= $self->_value($_);
647 }
648 $first = 0;
649 }
650 $str .= q{ };
651
652 my $comment = $self->{dom_doc}->createComment($str);
653 $dom_parent->appendChild($comment);
654
655 $self->_get_defn($node->{element}->{value})->visit($self, $dom_parent); # single or array
656 }
657
658 # 3.11.2.4 Enumerations
659 #
660 # See 1.2.7.1 Enum
661 #
662
663 sub visitEnumType {
664 my $self = shift;
665 my ($node, $dom_parent, $indirect) = @_;
666 return if (exists $self->{done_hash}->{$node->{xsd_name}});
667 $self->{done_hash}->{$node->{xsd_name}} = 1;
668
669 my $simpleType = $self->{dom_doc}->createElement($self->{xsd} . 'simpleType');
670 $simpleType->setAttribute('name', $node->{xsd_name})
671 unless ($indirect);
672 $dom_parent->appendChild($simpleType);
673
674 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
675 $restriction->setAttribute('base', $self->{xsd} . 'string');
676 $simpleType->appendChild($restriction);
677
678 foreach (@{$node->{list_expr}}) {
679 $_->visit($self, $restriction); # enum
680 }
681
682 $self->_standalone($node, $dom_parent) unless ($indirect);
683 }
684
685 sub visitEnum {
686 my $self = shift;
687 my ($node, $dom_parent) = @_;
688 my $FH = $self->{out};
689
690 my $enumeration = $self->{dom_doc}->createElement($self->{xsd} . 'enumeration');
691 $enumeration->setAttribute('value', $node->{xsd_name});
692 $dom_parent->appendChild($enumeration);
693 }
694
695 #
696 # 3.11.3 Template Types
697 #
698 # See 1.2.7.5 Sequences
699 #
700
701 sub visitSequenceType {
702 my $self = shift;
703 my ($node, $dom_parent) = @_;
704
705 my $type = $self->_get_defn($node->{type});
706 my $idx = 0;
707 my $current = $type;
708 while ($current->isa('SequenceType')) {
709 $idx ++;
710 $current = $self->_get_defn($current->{type});
711 }
712
713 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
714 $dom_parent->appendChild($sequence);
715
716 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
717 my $item = ($idx != 0) ? 'item' . $idx : 'item';
718 $element->setAttribute('name', $item);
719 $element->setAttribute('minOccurs', 0);
720 my $max = (exists $node->{max}) ? $self->_value($node->{max}) : 'unbounded';
721 $element->setAttribute('maxOccurs', $max);
722 $sequence->appendChild($element);
723
724 if ($type->isa('SequenceType')) {
725 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
726 $element->appendChild($complexType);
727
728 $type->visit($self, $complexType);
729 }
730 else {
731 $element->setAttribute('type', $type->{xsd_qname});
732 }
733 }
734
735 #
736 # See 1.2.6 Primitive Types
737 #
738
739 sub visitStringType {
740 my $self = shift;
741 my ($node, $dom_parent) = @_;
742
743 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
744 $restriction->setAttribute('base', $node->{xsd_qname});
745 $dom_parent->appendChild($restriction);
746
747 if (exists $node->{max}) {
748 my $maxLength = $self->{dom_doc}->createElement($self->{xsd} . 'maxLength');
749 $maxLength->setAttribute('value', $self->_value($node->{max}));
750 $maxLength->setAttribute('fixed', 'true');
751 $restriction->appendChild($maxLength);
752 }
753 }
754
755 #
756 # See 1.2.6 Primitive Types
757 #
758
759 sub visitWideStringType {
760 my $self = shift;
761 my ($node, $dom_parent) = @_;
762
763 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
764 $restriction->setAttribute('base', $node->{xsd_qname});
765 $dom_parent->appendChild($restriction);
766 }
767
768 #
769 # See 1.2.7.9 Fixed
770 #
771
772 sub visitFixedPtType {
773 my $self = shift;
774 my ($node, $dom_parent) = @_;
775
776 my $restriction = $self->{dom_doc}->createElement($self->{xsd} . 'restriction');
777 $restriction->setAttribute('base', $node->{xsd_qname});
778 $dom_parent->appendChild($restriction);
779
780 my $totalDigits = $self->{dom_doc}->createElement($self->{xsd} . 'totalDigits');
781 $totalDigits->setAttribute('value', $self->_value($node->{d}));
782 $restriction->appendChild($totalDigits);
783
784 my $fractionDigits = $self->{dom_doc}->createElement($self->{xsd} . 'fractionDigits');
785 $fractionDigits->setAttribute('value', $self->_value($node->{s}));
786 $fractionDigits->setAttribute('fixed', 'true');
787 $restriction->appendChild($fractionDigits);
788 }
789
790 #
791 # 3.12 Exception Declaration
792 #
793 # See 1.2.8.5 Exceptions
794 #
795
796 sub visitException {
797 my $self = shift;
798 my ($node, $dom_parent, $indirect) = @_;
799
800 if ($indirect) {
801 $self->_StructType_Content($node, $dom_parent);
802 return;
803 }
804
805 return if (exists $self->{done_hash}->{$node->{xsd_name}});
806 $self->{done_hash}->{$node->{xsd_name}} = 1;
807
808 if (exists $node->{list_expr}) {
809 warn __PACKAGE__,"::visitException $node->{idf} : empty list_expr.\n"
810 unless (@{$node->{list_expr}});
811 foreach (@{$node->{list_expr}}) {
812 my $type = $self->_get_defn($_->{type});
813 if ( $type->isa('StructType')
814 or $type->isa('UnionType') ) {
815 $type->visit($self, $dom_parent);
816 }
817 }
818 }
819
820 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
821 $complexType->setAttribute('name', $node->{xsd_name});
822 $dom_parent->appendChild($complexType);
823
824 $self->_StructType_Content($node, $complexType);
825
826 $self->_standalone($node, $dom_parent) unless ($indirect);
827 }
828
829 #
830 # 3.13 Operation Declaration
831 #
832 # See 1.2.8.2 Interface as Binding Operations
833 #
834
835 sub visitOperation {
836 my $self = shift;
837 my ($node, $dom_parent) = @_;
838
839 return unless ($self->{standalone});
840
841 if (scalar(@{$node->{list_in}}) + scalar(@{$node->{list_inout}})) {
842 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
843 $complexType->setAttribute('name', $node->{xsd_name});
844 $dom_parent->appendChild($complexType);
845
846 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
847 $complexType->appendChild($sequence);
848
849 foreach (@{$node->{list_param}}) { # parameter
850 if ( $_->{attr} eq 'in'
851 or $_->{attr} eq 'inout' ) {
852 $_->visit($self, $sequence);
853 }
854 }
855
856 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
857 $element->setAttribute('name', $node->{xsd_name});
858 $element->setAttribute('type', $node->{xsd_qname});
859 $dom_parent->appendChild($element);
860 }
861
862 my $type = $self->_get_defn($node->{type});
863 if (scalar(@{$node->{list_inout}}) + scalar(@{$node->{list_out}})
864 or ! $type->isa('VoidType') ) {
865 my $complexType = $self->{dom_doc}->createElement($self->{xsd} . 'complexType');
866 $complexType->setAttribute('name', $node->{xsd_name} . 'Response');
867 $dom_parent->appendChild($complexType);
868
869 my $sequence = $self->{dom_doc}->createElement($self->{xsd} . 'sequence');
870 $complexType->appendChild($sequence);
871
872 unless ($type->isa('VoidType')) {
873 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
874 $element->setAttribute('name', '_return');
875 $element->setAttribute('maxOccurs', '1');
876 $element->setAttribute('minOccurs', '1');
877 $element->setAttribute('nillable', 'true')
878 if ($type->isa('StringType') or $type->isa('WideStringType'));
879 $element->setAttribute('type', $type->{xsd_qname});
880 $sequence->appendChild($element);
881 }
882
883 foreach (@{$node->{list_param}}) { # parameter
884 if ( $_->{attr} eq 'inout'
885 or $_->{attr} eq 'out' ) {
886 $_->visit($self, $sequence);
887 }
888 }
889
890 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
891 $element->setAttribute('name', $node->{xsd_name} . 'Response');
892 $element->setAttribute('type', $node->{xsd_qname} . 'Response');
893 $dom_parent->appendChild($element);
894 }
895 }
896
897 sub visitParameter {
898 my $self = shift;
899 my ($node, $dom_parent) = @_;
900 my $type = $self->_get_defn($node->{type});
901
902 my $element = $self->{dom_doc}->createElement($self->{xsd} . 'element');
903 $element->setAttribute('name', $node->{xsd_name});
904 $element->setAttribute('maxOccurs', '1');
905 $element->setAttribute('minOccurs', '1');
906 $element->setAttribute('nillable', 'true')
907 if ($type->isa('StringType') or $type->isa('WideStringType'));
908 $element->setAttribute('type', $type->{xsd_qname});
909 $dom_parent->appendChild($element);
910 }
911
912 1;
913