1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
package SOAP::WSDL::Generator::Iterator::WSDL11;
use strict; use warnings;
use Class::Std::Fast;
our $VERSION = 3.004;
my %definitions_of :ATTR(:name<definitions> :default<[]>);
my %nodes_of :ATTR(:name<nodes> :default<[]>);
# memoization attributes
my %portType_of :ATTR();
my %types_of :ATTR();
my %METHOD_OF = (
'SOAP::WSDL::Definitions' => 'get_service',
'SOAP::WSDL::Service' => 'get_port',
'SOAP::WSDL::Port' => sub {
my ($self, $node) = @_;
return if ! $node->first_address()
or ! $node->first_address()->isa('SOAP::WSDL::SOAP::Address');
return [ $self->get_definitions()
->find_binding( $node->expand( $node->get_binding() ) ) || () ];
},
'SOAP::WSDL::Binding' => sub {
my ($self, $node) = @_;
# remember referenced portType
$portType_of{ ident $self } = $self->get_definitions()
->find_portType( $node->expand( $node->get_type ) )
or return [];
return $node->get_operation();
},
'SOAP::WSDL::Operation' => sub {
my ($self, $node) = @_;
my $name = $node->get_name();
# get the equally named operation from the portType
my ($op) = grep { $_->get_name() eq $name }
@{ $portType_of{ ident $self }->get_operation() }
or return [];
return [ @{ $op->get_input }, @{ $op->get_output }, @{ $op->get_fault } ]
},
'SOAP::WSDL::OpMessage' => sub {
my ($self, $node) = @_;
return if ( ref $node->get_parent() eq 'SOAP::WSDL::Binding' ); # we're in binding
# TODO maybe allow more messages && overloading by specifying name
return [ $self->get_definitions()->find_message(
$node->expand( $node->get_message() )
) || () ];
},
'SOAP::WSDL::Message' => 'get_part',
'SOAP::WSDL::Part' => sub {
my ($self, $node) = @_;
my $ident = ident $self;
my $types = $types_of{ $ident } = $definitions_of{ $ident }->get_types()->[0]
or return [];
return [
# If we have a type, this type is to be used in document/literal
# as global type. However this is forbidden, at least by WS-I.
# We should store the style/encoding somewhere, and regard it.
# TODO: auto-generate element for RPC bindings
$node->get_type()
? do {
die "unsupported global type <"
. $node->get_type . "> found in part <". $node->get_name() . ">\n"
. "Looks like a rpc/literal WSDL, which is not supported by SOAP::WSDL\n";
## use this once we can auto-generate an element for RPC bindings
# $types->find_type( $node->expand($node->get_type) )
}
: (),
$node->get_element()
? $types->find_element( $node->expand($node->get_element) )
: (),
];
},
);
sub init {
my ($self, $arg_of) = @_;
my $ident = ident $self;
undef $portType_of{ $ident };
undef $types_of{ $ident };
$nodes_of{ $ident } = [
exists($arg_of->{ node })
? $arg_of->{ node }
: $definitions_of{ ident $self }
];
}
sub get_next {
my $self = shift;
my $ident = ident $self;
my $node = shift @{ $nodes_of{ $ident }};
return if ! defined $node;
unshift @{ $nodes_of{ $ident }}, @{ $self->get_nextNodes( $node ) || [] };
return $node;
}
sub get_nextNodes {
my ($self, $node) = @_;
my $method = $METHOD_OF{ ref $node }
or return [];
return (ref($method) eq 'CODE')
? $method->( $self, $node )
: $node->can($method)->( $node );
}
1;
__END__
=pod
=head1 NAME
SOAP::WSDL::Generator::Iterator::WSDL11 - WSDL 1.1 Iterator
=head1 SYNOPSIS
my $iter = SOAP::WSDL::Generator::Iterator::WSDL11->new({
definitions => $wsdl
});
$iter->init();
while (my $node = $iter->get_next()) {
# do something with node - possibly call _accept with a visitor on it...
}
=head1 DESCRIPTION
Iterator for walking a WSDL 1.1 definition.
The iterator performs a depth-first search along the following path:
service
port
binding
operation
input/output/fault of operation in portType
message
part
type/element in XML schema
If you wonder about this path: This is how to look up which XML Schema element
is associated with a operation from a service/port.
=head2 Example
The nodes are returned in the order denoted in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<!-- 1 -->
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:HelloWorld"
targetNamespace="urn:HelloWorld"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema elementFormDefault="qualified" targetNamespace="urn:HelloWorld">
<!-- 9 -->
<s:element name="sayHello">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="givenName" type="s:string" nillable="1" />
</s:sequence>
<s:attribute name="testAttr" type="s:string" use="optional"></s:attribute>
</s:complexType>
</s:element>
<!-- 13 -->
<s:element name="sayHelloResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1"
name="sayHelloResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<!-- 7 -->
<message name="sayHelloSoapIn">
<!-- 8 -->
<part name="parameters" element="s0:sayHello" />
</message>
<!-- 11 -->
<message name="sayHelloSoapOut">
<!-- 12 -->
<part name="parameters" element="s0:sayHelloResponse" />
</message>
<portType name="Service1Soap">
<operation name="sayHello">
<!-- 6 -->
<input message="s0:sayHelloSoapIn" />
<!-- 10 -->
<output message="s0:sayHelloSoapOut" />
</operation>
</portType>
<!-- 4 -->
<binding name="Service1Soap" type="s0:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<!-- 5 -->
<operation name="sayHello">
<soap:operation soapAction="urn:HelloWorld#sayHello"
style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<!-- 2 -->
<service name="Service1">
<!-- 3 -->
<port name="Service1Soap" binding="s0:Service1Soap">
<soap:address
location="http://localhost:81/soap-wsdl-test/helloworld.pl" />
</port>
</service>
</definitions>
You should not rely too much on this order - it may change. Even though the
current order will probably remain, the nodes currently skipped might
be returned somewhere along the path.
=head1 LICENSE AND COPYRIGHT
Copyright 2004-2008 Martin Kutter.
This file is part of SOAP-WSDL. You may distribute/modify it under
the same terms as perl itself
=head1 AUTHOR
Martin Kutter E<lt>martin.kutter fen-net.deE<gt>
=head1 REPOSITORY INFORMATION
$Rev: 239 $
$LastChangedBy: kutterma $
$Id: Client.pm 239 2007-09-11 09:45:42Z kutterma $
$HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Client.pm $
=cut
|