LS/Authority/WSDL/Bindings.pm untested

filter: Statementstmt 0.0% 0 / 166 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 298 CC 35 SCAR 36.6
CC
35
Cov
0%
from_xpath_node
110.0
xml
72.0
new
42.0
CRAP 38.9
1 # ====================================================================
2 # Copyright (c) 2002,2003 IBM Corporation
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Common Public License v1.0
5 # which accompanies this distribution, and is available at
6 # http://www.opensource.org/licenses/cpl.php
7 #
8 # =====================================================================
9 package LS::Authority::WSDL::Bindings;
10  
11 use strict;
12 use warnings;
13  
14 use vars qw(
15 %NAMESPACES
16 );
17  
18 use LS::Authority::WSDL::Constants;
19  
20 #
21 # %NAMESPACES -
22 #
23 %NAMESPACES = (
24
25  
26 );
27  
28  
29  
30  
31 # The following Binding related objects are unused
32  
33 package LS::Authority::WSDL::Binding;
34  
35 use strict;
36 use warnings;
37  
38 use vars qw( $METHODS );
39  
40  
41 use LS::Authority::WSDL::Constants;
42  
43  
44 #
45 # BEGIN( ) -
46 #
47 sub BEGIN {
48  
49 $METHODS = [
50 'name',
51 'port_type',
52 'implementation',
53 ];
54 }
55  
56  
57 #
58 # Create the accessor / mutator methods for the bindings class
59 #
60 for my $field (@{ $METHODS }) {
61  
62 no strict "refs";
63  
64 my $slot = __PACKAGE__ . $field;
65
66 *$field = sub {
67  
68 my $self = shift;
69 my $param = shift;
70
71 $param ? $self->{ $slot } = $param : return $self->{ $slot };
72 }
73 }
74  
75  
76 #
77 # new( %options ) -
78 #
79 sub new {
80 my $self = shift;
81 my %params = @_;
82  
83 unless(ref $self) {
84 $self = bless {
85 operations=> [] # operations
86 }, $self;
87
88 $self->name($params{name}) if defined $params{name};
89 $self->port_type($params{port_type}) if defined $params{port_type};
90 $self->implementation($params{implementation}) if defined $params{implementation};
91 }
92
93 return $self;
94 }
95  
96  
97 sub operations {
98 my $self = shift;
99
100 return $self->{'operations'};
101 }
102  
103 sub add_operation {
104 my $self = shift;
105 my ($op) = @_;
106
107 push(@{$self->operations}, $op);
108 }
109  
110 sub get_operation_by_name {
111 my $self = shift;
112 my ($name) = @_;
113  
114 foreach my $op (@{$self->operations}) {
115 return $op if $op->name eq $name;
116 }
117  
118 return undef;
119 }
120  
121 sub xml {
122 my $self = shift;
123  
124 require LS::Authority::WSDL;
125
126 my $operations_xml = '';
127
128 foreach my $operation (@{$self->operations}) {
129 $operations_xml .= $operation->xml;
130 }
131
132 return
133 '<binding name="' . $self->name .'" type="' . $LS::Authority::WSDL::_STD_DEFS_PREFIX . ':' . $self->port_type . '">' .
134 ($self->implementation ? $self->implementation->xml : '') .
135 $operations_xml .
136 '</binding>';
137 }
138  
139 sub from_xpath_node {
140 my $self = shift->new;
141 my ($node, $xpath) = @_;
142  
143 my $name = $node->getAttribute('name') || return;
144 my $port_type = $node->getAttribute('type') || return;
145  
146 $port_type =~ s/^\w+://;
147  
148 my $imp_nodes = $xpath->find('*[local-name() = "binding"]', $node);
149 return unless $imp_nodes->size == 1;
150  
151 my $imp_node = $imp_nodes->get_node(1);
152 my $imp = LS::Authority::WSDL::Implementation->from_xpath_node($imp_node, $xpath);
153  
154 return unless $imp;
155  
156 $self->name($name);
157 $self->port_type($port_type);
158 $self->implementation($imp);
159  
160 my $op_nodes = $xpath->find('operation', $node);
161
162 foreach my $op_node ($op_nodes->get_nodelist) {
163 my $op = LS::Authority::WSDL::Binding::Operation->from_xpath_node($op_node, $xpath);
164 next unless $op;
165  
166 $self->add_operation($op);
167 }
168
169 return $self;
170 }
171  
172  
173 package LS::Authority::WSDL::Binding::Operation;
174  
175 sub new {
176 my $self = shift;
177 my %params = @_;
178  
179 unless(ref $self) {
180 $self = bless [
181 undef, # name,
182 undef, # implementation,
183 undef, # input,
184 undef # output
185 ], $self;
186
187 $self->name($params{name}) if defined $params{name};
188 $self->implementation($params{implementation}) if defined $params{implementation};
189 $self->input($params{input}) if defined $params{input};
190 $self->output($params{output}) if defined $params{output};
191 }
192
193 return $self;
194 }
195  
196 sub name {
197 my $self = shift;
198  
199 @_ ? $self->[0] = $_[0] : $self->[0];
200 }
201  
202 sub implementation {
203 my $self = shift;
204  
205 @_ ? $self->[1] = $_[0] : $self->[1];
206 }
207  
208 sub input {
209 my $self = shift;
210  
211 @_ ? $self->[2] = $_[0] : $self->[2];
212 }
213  
214 sub output {
215 my $self = shift;
216  
217 @_ ? $self->[3] = $_[0] : $self->[3];
218 }
219  
220 sub xml {
221 my $self = shift;
222  
223 my $input_xml = '';
224 my $input = $self->input;
225  
226 if ($input) {
227 if (ref $input eq 'ARRAY') {
228 foreach my $impl (@$input) {
229 $input_xml .= $impl->xml;
230 }
231 }
232 else {
233 $input_xml = $input->xml;
234 }
235 }
236
237 my $output_xml = '';
238 my $output = $self->output;
239
240 if ($output) {
241 if (ref $output eq 'ARRAY') {
242 foreach my $impl (@$output) {
243 $output_xml .= $impl->xml;
244 }
245 }
246 else {
247 $output_xml = $output->xml;
248 }
249 }
250  
251 return
252 '<operation name="' . $self->name . '">' .
253 ($self->implementation ? $self->implementation->xml : '') .
254 ($input ? '<input>' . $input_xml . '</input>' : '<input/>') .
255 ($output ? '<output>' . $output_xml . '</output>' : '<output/>') .
256 '</operation>';
257 }
258  
259 sub from_xpath_node {
260 my $self = shift->new;
261 my ($node, $xpath) = @_;
262  
263 my $name = $node->getAttribute('name') || return;
264 $self->name($name);
265  
266 my $imp_nodes = $xpath->find('*[local-name() = "operation"]', $node);
267 return unless $imp_nodes->size == 1;
268  
269 my $imp_node = $imp_nodes->get_node(1);
270 my $imp = LS::Authority::WSDL::Implementation->from_xpath_node($imp_node, $xpath) || return;
271  
272 $self->implementation($imp);
273  
274 my $input_nodes = $xpath->find('input', $node);
275 return if $input_nodes->size > 1;
276  
277 if ($input_nodes->size > 0) {
278 my $input_node = $input_nodes->get_node(1);
279 my $impl_nodes = $xpath->find('*', $input_node);
280
281 if ($impl_nodes->size == 1) {
282 my $input_imp_node = $impl_nodes->get_node(1);
283 my $input_imp = LS::Authority::WSDL::Implementation->from_xpath_node($input_imp_node, $xpath) || return;
284  
285 $self->input($input_imp);
286 }
287 elsif ($impl_nodes->size > 1) {
288 my @imp = ();
289  
290 for(my $i=1; $i<=$impl_nodes->size; $i++) {
291 my $input_imp_node = $impl_nodes->get_node($i);
292 my $input_imp = LS::Authority::WSDL::Implementation->from_xpath_node($input_imp_node, $xpath) || return;
293  
294 push(@imp, $input_imp);
295 }
296
297 $self->input(\@imp);
298 }
299 }
300  
301 my $output_nodes = $xpath->find('output', $node);
302 return if $output_nodes->size > 1;
303  
304 if ($output_nodes->size > 0) {
305 my $output_node = $output_nodes->get_node(1);
306 my $impl_nodes = $xpath->find('*', $output_node);
307
308 if ($impl_nodes->size == 1) {
309 my $output_imp_node = $impl_nodes->get_node(1);
310 my $output_imp = LS::Authority::WSDL::Implementation->from_xpath_node($output_imp_node, $xpath) || return;
311  
312 $self->output($output_imp);
313 }
314 elsif ($impl_nodes->size > 1) {
315 my @imp = ();
316
317 for(my $i=1; $i<=$impl_nodes->size; $i++) {
318 my $output_imp_node = $impl_nodes->get_node($i);
319 my $output_imp = LS::Authority::WSDL::Implementation->from_xpath_node($output_imp_node, $xpath) || return;
320  
321 push (@imp, $output_imp);
322 }
323  
324 $self->output(\@imp);
325 }
326 }
327  
328 return $self;
329 }
330  
331  
332 1;
333  
334 __END__