/usr/share/perl5/Bio/DB/ESoap/WSDL.pm is in libbio-perl-run-perl 1.7.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | # $Id$
#
# BioPerl module for Bio::DB::ESoap::WSDL
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Mark A. Jensen <maj -at- fortinbras -dot- us>
#
# Copyright Mark A. Jensen
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::DB::ESoap::WSDL - WSDL parsing for Entrez SOAP EUtilities
=head1 SYNOPSIS
Used by L<Bio::DB::ESoap>
# url
$wsdl = Bio::DB::ESoap::WSDL->new(
-url => "http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/eutils.wsdl"
);
# local copy
$wsdl = Bio::DB::ESoap::WSDL->new(
-wsdl => "local/eutils.wsdl"
);
%opns = %{ $wsdl->operations };
=head1 DESCRIPTION
This module is a lightweight parser and container for WSDL XML files
associated with the NCBI EUtilities SOAP server. XML facilities are
provided by L<XML::Twig>.
The following accessors provide names and structures useful for
creating SOAP messages using L<SOAP::Lite> (e.g.):
service() : the URL of the SOAP service
operations() : hashref of the form {.., $operation_name => $soapAction, ...}
request_parameters($operation) :
request field names and namelists as an array of hashes
result_parameters($operation) :
result field names and namelists as an array of hashes
The following accessors provide L<XML::Twig::Elt> objects pointing at
key locations in the WSDL:
root : the root of the WSDL docment
_types_elt : the <types> element
_portType_elt : the <portType> element
_binding_elt : the <binding> element
_service_elt : the <service> element
_message_elts : an array of all top-level <message> elements
_operation_elts : an array of all <operation> elements contained in <binding>
Parsing occurs lazily (on first read, not on construction); all
information is cached. To clear the cache and force re-parsing, run
$wsdl->clear_cache;
The globals C<$NCBI_BASEURL>, C<$NCBI_ADAPTOR>, and C<%WSDL> are exported.
$NCBI_ADAPTOR : the soap service cgi
To construct a URL for a WSDL:
$wsdl_eutils = $NCBI_BASEURL.$WSDL{'eutils'}
$wsdl_efetch_omim = $NCBI_BASEURL.$WSDL{'f_omim'}
# etc.
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
L<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
http://redmine.open-bio.org/projects/bioperl/
=head1 AUTHOR - Mark A. Jensen
Email maj -at- fortinbras -dot- us
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
package Bio::DB::ESoap::WSDL;
use strict;
use Bio::Root::Root;
use XML::Twig;
use Bio::WebAgent;
use File::Temp;
use base qw(Bio::Root::Root Exporter);
our @EXPORT = qw( $NCBI_BASEURL $NCBI_ADAPTOR %WSDL );
our $NCBI_BASEURL = "http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/";
our $NCBI_ADAPTOR = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/soap_adapter_2_0.cgi";
our %WSDL = (
'eutils' => 'eutils.wsdl',
'f_pubmed' => 'efetch_pubmed.wsdl',
'f_pmc' => 'efetch_pmc.wsdl',
'f_nlmc' => 'efetch_nlmc.wsdl',
'f_journals' => 'efetch_journals.wsdl',
'f_omim' => 'efetch_omim.wsdl',
'f_taxon' => 'efetch_taxon.wsdl',
'f_snp' => 'efetch_snp.wsdl',
'f_gene' => 'efetch_gene.wsdl',
'f_seq' => 'efetch_seq.wsdl'
);
=head2 new
Title : new
Usage : my $obj = new Bio::DB::ESoap::WSDL();
Function: Builds a new Bio::DB::ESoap::WSDL object
Returns : an instance of Bio::DB::ESoap::WSDL
Args : named args:
-URL => $url_of_desired_wsdl -OR-
-WSDL => $filename_of_local_wsdl_copy
( -WSDL will take precedence if both specified )
=cut
sub new {
my ($class,@args) = @_;
my $self = $class->SUPER::new(@args);
my ($url, $wsdl) = $self->_rearrange( [qw( URL WSDL )], @args );
my (%sections, %cache);
my $doc = 'wsdl:definitions';
$sections{'_message_elts'} = [];
$sections{'_operation_elts'} = [];
$self->_sections(\%sections);
$self->_cache(\%cache);
$self->_twig(
XML::Twig->new(
twig_handlers => {
$doc => sub { $self->root($_) },
"$doc/binding" => sub { $self->_sections->{'_binding_elt'} = $_ },
"$doc/binding/operation" => sub { push @{$self->_sections->{'_operation_elts'}},$_ },
"$doc/message" => sub { push @{$self->_sections->{'_message_elts'}}, $_ },
"$doc/portType" => sub { $self->_sections->{'_portType_elt'} = $_ },
"$doc/service" => sub { $self->_sections->{'_service_elt'} = $_ },
"$doc/types" => sub { $self->_sections->{'_types_elt'} = $_ },
}
)
);
if ($url || $wsdl ) {
$self->url($url);
$self->wsdl($wsdl);
$self->_parse;
}
return $self;
}
=head1 Getters
=head2 request_parameters()
Title : request_parameters
Usage : @params = $wsdl->request_parameters($operation_name)
Function: get array of request (input) fields required by
specified operation, according to the WSDL
Returns : hash of arrays of hashes...
Args : scalar string (operation or action name)
=cut
sub request_parameters {
my $self = shift;
my ($operation) = @_;
my $is_action;
$self->throw("Operation name must be specified") unless defined $operation;
my $opn_hash = $self->operations;
unless ( grep /^$operation$/, keys %$opn_hash ) {
$is_action = grep /^$operation$/, values %$opn_hash;
$self->throw("Operation name '$operation' is not recognized")
unless ($is_action);
}
#check the cache here....
return $self->_cache("request_params_$operation") if
$self->_cache("request_params_$operation");
# find the input message type in the portType elt
if ($is_action) {
my @a = grep {$$opn_hash{$_} eq $operation} keys %$opn_hash;
# note this takes the first match
$operation = $a[0];
$self->throw("Whaaa??") unless defined $operation;
}
#check the cache once more after translation....
return $self->_cache("request_params_$operation") if
$self->_cache("request_params_$operation");
my $bookmarks = $self->_operation_bookmarks($operation);
my $imsg_elt = $bookmarks->{'i_msg_elt'};
my $opn_schema = $bookmarks->{'schema'};
my $ret = { $imsg_elt->att('name') => [] };
# do a quick recursion:
_get_types((values %$ret)[0], $imsg_elt, $opn_schema);
return $self->_cache("request_params_$operation", $ret);
1;
}
=head2 result_parameters()
Title : result_parameters
Usage : $result_hash = $wsdl->result_parameters
Function: retrieve a hash structure describing the
result of running the specified operation
according to the WSDL
Returns : hash of arrays of hashes...
Args : operation (scalar string)
=cut
sub result_parameters {
my $self = shift;
my ($operation) = @_;
my $is_action;
$self->throw("Operation name must be specified") unless defined $operation;
my $opn_hash = $self->operations;
unless ( grep /^$operation$/, keys %$opn_hash ) {
$is_action = grep /^$operation$/, values %$opn_hash;
$self->throw("Operation name '$operation' is not recognized")
unless ($is_action);
}
#check the cache here....
return $self->_cache("result_params_$operation") if
$self->_cache("result_params_$operation");
# find the input message type in the portType elt
if ($is_action) {
my @a = grep {$$opn_hash{$_} eq $operation} keys %$opn_hash;
# note this takes the first match
$operation = $a[0];
$self->throw("Whaaa??") unless defined $operation;
}
#check the cache once more after translation....
return $self->_cache("result_params_$operation") if
$self->_cache("result_params_$operation");
# do work
my $bookmarks = $self->_operation_bookmarks($operation);
# eutilities results seem to be a mixture of xs:string element
# and complex types which are just xs:seqs of xs:string elements
#
# cast these as a hash of hashes...
my $omsg_elt = $bookmarks->{'o_msg_elt'};
my $opn_schema = $bookmarks->{'schema'};
my $ret = { $omsg_elt->att('name') => [] };
# do a quick recursion:
_get_types((values %$ret)[0], $omsg_elt, $opn_schema);
return $self->_cache("result_params_$operation", $ret);
}
sub response_parameters { shift->result_parameters( @_ ) }
=head2 operations()
Title : operations
Usage : @opns = $wsdl->operations;
Function: get a hashref with elts ( $operation_name => $soapAction )
for all operations defined by this WSDL
Returns : array of scalar strings
Args : none
=cut
sub operations {
my $self = shift;
return $self->_cache('operations') if $self->_cache('operations');
my %opns;
foreach (@{$self->_parse->_operation_elts}) {
$opns{$_->att('name')} =
($_->descendants('soap:operation'))[0]->att('soapAction');
}
return $self->_cache('operations', \%opns);
}
=head2 service()
Title : service
Usage : $wsdl->service
Function: gets the SOAP service url associated with this WSDL
Returns : scalar string
Args : none
=cut
sub service {
my $self = shift;
return $self->_cache('service') ||
$self->_cache('service', ($self->_parse->_service_elt->descendants('soap:address'))[0]->att('location'));
}
=head2 db()
Title : db
Usage :
Function: If this is an efetch WSDL, returns the db name
associated with it
Returns : scalar string or undef
Args : none
=cut
sub db {
my $self = shift;
$self->root->namespace('nsef') =~ /efetch_(.*?)$/;
return $1;
}
=head1 Internals
=head2 _operation_bookmarks()
Title : _operation_bookmarks
Usage :
Function: find useful WSDL elements associated with the specified
operation; return a hashref of the form
{ $key => $XML_Twig_Elt_obj, }
Returns : hashref with keys:
portType namespace schema
i_msg_type i_msg_elt
o_msg_type o_msg_elt
Args : operation name (scalar string)
Note : will import schema if necessary
=cut
sub _operation_bookmarks {
my $self = shift;
my $operation = shift;
# check cache
return $self->_cache("bookmarks_$operation") if
$self->_cache("bookmarks_$operation");
# do work
my %bookmarks;
my $pT_opn = $self->_portType_elt->first_child(
qq/ operation[\@name="$operation"] /
);
my $imsg_type = $pT_opn->first_child('input')->att('message');
my $omsg_type = $pT_opn->first_child('output')->att('message');
# now lookup the schema element name from among the message elts
my ($imsg_elt, $omsg_elt);
foreach ( @{$self->_message_elts} ) {
my $msg_name = $_->att('name');
if ( $imsg_type =~ qr/$msg_name/ ) {
$imsg_elt = $_->first_child('part[@element=~/[Rr]equest/]')->att('element');
}
if ( $omsg_type =~ qr/$msg_name/) {
$omsg_elt = $_->first_child('part[@element=~/[Rr]esult/]')->att('element');
}
last if ($imsg_elt && $omsg_elt);
}
$self->throw("Can't find request schema element corresponding to '$operation'") unless $imsg_elt;
$self->throw("Can't find result schema element corresponding to '$operation'") unless $omsg_elt;
# $imsg_elt has a namespace prefix, to lead us to the correct schema
# as defined in the wsdl <types> element. Get that schema
$imsg_elt =~ /(.*?):/;
my $opn_ns = $self->root->namespace($1);
my $opn_schema = $self->_types_elt->first_child("xs:schema[\@targetNamespace='$opn_ns']");
$opn_schema ||= $self->_types_elt->first_child("xs:schema"); # only one
$self->throw("Can't find types schema corresponding to '$operation'") unless defined $opn_schema;
# need to import the schema? do it here.
if ( my $import_elt = $opn_schema->first_child("xs:import") ) {
my $import_url = $NCBI_BASEURL.$import_elt->att('schemaLocation');
my $imported = XML::Twig->new();
# better error checking here?
eval {
$imported->parse(Bio::WebAgent->new()->get($import_url)->content);
};
$self->throw("Schema import failed (tried url '$import_url') : $@") if $@;
my $imported_schema = $imported->root;
# get included schemata
my @included = $imported_schema->children("xs:include");
foreach (@included) {
my $url = $NCBI_BASEURL.$_->att('schemaLocation');
my $incl = XML::Twig->new();
eval {
$incl->parse( Bio::WebAgent->new()->get($url)->content );
};
$self->throw("Schema include failed (tried url '$url') : $@") if $@;
# cut-n-paste
my @incl = $incl->root->children;
$_->cut;
foreach my $child (@incl) {
$child->cut;
$child->paste( last_child => $_->former_parent );
}
}
# cut-n-paste
$opn_schema->cut;
$imported_schema->cut;
$imported_schema->paste( first_child => $opn_schema->former_parent );
$opn_schema = $imported_schema;
}
# find the definition of $imsg_elt in $opn_schema
$imsg_elt =~ s/.*?://;
$imsg_elt = $opn_schema->first_child("xs:element[\@name='$imsg_elt']");
$self->throw("Can't find request element definition in schema corresponding to '$operation'") unless defined $imsg_elt;
$omsg_elt =~ s/.*?://;
$omsg_elt = $opn_schema->first_child("xs:element[\@name='$omsg_elt']");
$self->throw("Can't find result element definition in schema corresponding to '$operation'") unless defined $omsg_elt;
@bookmarks{qw(portType i_msg_type o_msg_type
namespace schema i_msg_elt o_msg_elt ) } =
($pT_opn, $imsg_type, $omsg_type, $opn_ns, $opn_schema,
$imsg_elt, $omsg_elt);
return $self->_cache("bookmarks_$operation", \%bookmarks);
}
=head2 _parse()
Title : _parse
Usage : $wsdl->_parse
Function: parse the wsdl at url and create accessors for
section twig elts
Returns : self
Args :
=cut
sub _parse {
my $self = shift;
my @args = @_;
return $self if $self->_parsed; # already done
$self->throw("Neither URL nor WSDL set in object") unless $self->url || $self->wsdl;
eval {
if ($self->wsdl) {
$self->_twig->parsefile($self->wsdl);
}
else {
eval {
my $tfh = File::Temp->new(-UNLINK=>1);
Bio::WebAgent->new()->get($self->url, ':content_file' => $tfh->filename);
$tfh->close;
$self->_twig->parsefile($tfh->filename);
$self->wsdl($tfh->filename);
};
$self->throw("URL parse failed : $@") if $@;
}
};
# $self->throw("Parser issue : $@") if $@;
die $@ if $@;
$self->_set_from_args( $self->_sections,
-methods => [qw(_types_elt _message_elts
_portType_elt _binding_elt
_operation_elts _service_elt)],
-create => 1 );
$self->_parsed(1);
return $self;
}
=head2 root()
Title : root
Usage : $obj->root($newval)
Function: holds the root Twig elt of the parsed WSDL
Example :
Returns : value of root (an XML::Twig::Elt)
Args : on set, new value (an XML::Twig::Elt or undef, optional)
=cut
sub root {
my $self = shift;
return $self->{'root'} = shift if @_;
return $self->{'root'};
}
=head2 url()
Title : url
Usage : $obj->url($newval)
Function: get/set the WSDL url
Example :
Returns : value of url (a scalar string)
Args : on set, new value (a scalar or undef, optional)
=cut
sub url {
my $self = shift;
return $self->{'url'} = shift if @_;
return $self->{'url'};
}
=head2 wsdl()
Title : wsdl
Usage : $obj->wsdl($newval)
Function: get/set wsdl XML filename
Example :
Returns : value of wsdl (a scalar string)
Args : on set, new value (a scalar string or undef, optional)
=cut
sub wsdl {
my $self = shift;
my $file = shift;
if (defined $file) {
$self->throw("File not found") unless (-e $file) || (ref $file eq 'File::Temp');
return $self->{'wsdl'} = $file;
}
return $self->{'wsdl'};
}
=head2 _twig()
Title : _twig
Usage : $obj->_twig($newval)
Function: XML::Twig object for handling the wsdl
Example :
Returns : value of _twig (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub _twig {
my $self = shift;
return $self->{'_twig'} = shift if @_;
return $self->{'_twig'};
}
=head2 _sections()
Title : _sections
Usage : $obj->_sections($newval)
Function: holds hashref of twigs corresponding to main wsdl
elements; filled by _parse()
Example :
Returns : value of _sections (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub _sections {
my $self = shift;
return $self->{'_sections'} = shift if @_;
return $self->{'_sections'};
}
=head2 _cache()
Title : _cache
Usage : $wsdl->_cache($newval)
Function: holds the wsdl info cache
Example :
Returns : value of _cache (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub _cache {
my $self = shift;
my ($name, $value) = @_;
unless (@_) {
return $self->{'_cache'} = {};
}
if (defined $value) {
return $self->{'_cache'}->{$name} = $value;
}
return $self->{'_cache'}->{$name};
}
sub clear_cache { shift->_cache() }
=head2 _parsed()
Title : _parsed
Usage : $obj->_parsed($newval)
Function: flag to indicate wsdl already parsed
Example :
Returns : value of _parsed (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub _parsed {
my $self = shift;
return $self->{'_parsed'} = shift if @_;
return $self->{'_parsed'};
}
# =head2 _get_types()
# Title : _get_types
# Usage : very internal
# Function: recursively parse through custom types
# Returns :
# Args : arrayref, XML::Twig::Elt, XML::Twig::Elt
# (return array, type element, schema root)
# =cut
sub _get_types {
my ($res, $elt, $sch, $visited) = @_;
my $is_choice;
$visited ||= [];
# assuming max 1 xs:sequence or xs:choice per element
my $seq = ($elt->descendants('xs:sequence'))[0];
$is_choice = ($seq ? '' : '|');
$seq ||= ($elt->descendants('xs:choice'))[0];
return 1 unless $seq;
foreach ( $seq->descendants('xs:element') ) {
for my $type ($_->att('type') || $_->att('ref')) {
!defined($type) && do {
Bio::Root::Root->throw("neither type nor ref attributes defined; cannot proceed");
last;
};
$type eq 'xs:string' && do {
push @$res, { $_->att('name').$is_choice => 1};
last;
};
do { # custom type
# find the type def in schema
$type =~ s/.*?://; # strip tns
if (grep /^$type$/, @$visited) { # check for circularity
push @$res, { $_->att('name').$is_choice => "$type(reused)"}if $_->att('name');
last;
}
push @$visited, $type;
my $new_elt = $sch->first_child("xs:complexType[\@name='$type']");
if (defined $new_elt) {
my $new_res = [];
push @$res, { $_->att('name').$is_choice => $new_res };
_get_types($new_res, $new_elt, $sch, $visited);
}
else { # a 'ref', make sure it's defined
$new_elt = $sch->first_child("xs:element[\@name='$type']");
$DB::single=1 unless $new_elt;
Bio::Root::Root->throw("type not defined in schema; cannot proceed") unless defined $new_elt;
push @$res, { $new_elt->att('name').$is_choice => 1 };
}
last;
}
}
}
return 1;
}
sub DESTROY {
my $self = shift;
if (ref($self->wsdl) eq 'File::Temp') {
unlink $self->wsdl->filename;
}
}
1;
|