E.3 The show_biz UDDI Application


This application was presented in Chapter 10 to illustrate the usage of the UDDI::Lite classes that are a part of the SOAP::Lite package. In particular, it outlines how the UDDI::Data class provides an object-model view of the UDDI data structures, as returned by UDDI registry servers in response to queries.

The application takes any of three optional command-line switch arguments and a string representing a business name (or partial name ) to search for. All matching business records are dumped to the terminal in a fairly readable layout that goes down to the level of the bindingTemplate structures. For brevity, the application stops at that point, though adding functionality to follow tModel references and deconstruct the identifierBag or categoryBag lists would be fairly easy.

Example E-3. show_biz
 #!/usr/bin/perl     use strict; use vars qw(%opts $name @qualifiers @params $SHOWKEYS); use subs qw(dump_business dump_service dump_template);     # Text::Wrap will be used to format <description> blocks use Text::Wrap qw(wrap $columns); use Getopt::Long 'GetOptions'; # This example will make use of the autodispatch ability use UDDI::Lite +autodispatch =>                proxy => 'http://uddi.microsoft.com/inquire',                import => 'UDDI::Data';     # --case:     Do the matching in a case-sensitive manner # --exact:    Match a string exactly # --showkeys: Display record UUIDs right after the name GetOptions(\%opts, qw(case exact showkeys)) and     $name = shift or     die "USAGE: 
 #!/usr/bin/perl     use strict; use vars qw(%opts $name @qualifiers @params $SHOWKEYS); use subs qw(dump_business dump_service dump_template);     # Text::Wrap will be used to format <description> blocks use Text::Wrap qw(wrap $ columns ); use Getopt::Long 'GetOptions'; # This example will make use of the autodispatch ability use UDDI::Lite +autodispatch =>                proxy => 'http://uddi.microsoft.com/ inquire ',                import => 'UDDI::Data';     # --case:     Do the matching in a case-sensitive manner # --exact:    Match a string exactly # --showkeys: Display record UUIDs right after the name GetOptions(\%opts, qw(case exact showkeys)) and     $name = shift or     die "USAGE: $0 [ --case ] [ --exact ] [ --showkeys ] " .         "name\n"; $SHOWKEYS++ if ($opts{showkeys});     # Building up the qualifiers this way makes it cleaner to # create the <findQualifiers> structure. And since the # parameters are being pre- constructed , throw the search # string on at the end for convenience. @qualifiers = ('sortByNameAsc'); push(@qualifiers, 'exactNameMatch')     if ($opts{exact}); push(@qualifiers, 'caseSensitiveMatch') if ($opts{case}); push(@params,      findQualifiers(findQualifier(@qualifiers)),      name($name));     # First UDDI call: find all businesses that match the # criteria, then loop over them passing each to the # dump_business routine. my $result = find_business(@params); dump_business($_)     for ($result->businessInfos->businessInfo);     exit;     # Dump the contents of a <businessInfo> (an abbreviated # form of a <businessEntity>) record. sub dump_business {     my $business = shift;         print $business->name, "\n";     print 'uuid:', $business->businessKey, "\n"         if $SHOWKEYS;     print "\n";     if (my $description = $business->description) {         $columns = 72;         print wrap("\t", "\t", $description), "\n\n";     }     # Hand off each service entry to the dump_service     # routine.     dump_service($_)         for ($business->serviceInfos->serviceInfo); }     # Dump the contents of a <businessService> record. What # gets passed in is just a brief overview, however. sub dump_service {     my $svc = shift;         my ($key, $service);         # First order of business (so to speak) is to get the     # full <businessService> record, since what was passed     # in was a <serviceInfo>, that lacks a lot of data.     $key = $svc->serviceKey;     # Call get_serviceDetail using the serviceKey attribute     # from the short-form data.     return unless         $service = get_serviceDetail($key);     $service = $service->businessService;     print '    Service: ', $service->name, "\n";     print '    uuid:', $service->serviceKey, "\n"         if $SHOWKEYS;     if (my $description = $service->description) {         $columns = 64;         print wrap("\t    ", "\t    ", $description), "\n";     }     print "\n";     # Hand off a third time to handle <bindingTemplate>     # records.     dump_template($_)         for ($service->bindingTemplates->bindingTemplate); }     # Dump the contents of a <bindingTemplate> record. This # doesn't need an extra call, because all the needed data # was retrieved in the earlier get_serviceDetail call. sub dump_template {     my $template = shift;         print "\tTemplate:\n";     print "\tuuid:", $template->bindingKey, "\n"         if $SHOWKEYS;     if (my $description = $template->description) {         $columns = 60;         print wrap("\t\t", "\t\t", $description), "\n";     }     # Display either the access point (with a parenthetical     # comment about the URLType) or the redirector key.     # If neither are present, well, the registry should     # never have permitted that, but we can't count on it.     if (my $access = $template->accessPoint) {         printf "\t    Access point (%s): %s\n",             $access->attr->URLType, $access->value;     } elsif (my $redir = $template->hostingRedirector) {         print "\t    Hosting redirect to ",             $redir->value, "\n";     } else {         print "\t    No access point or hosting " ,             "redirector?\n";     }     print "\n"; } 
[ --case ] [ --exact ] [ --showkeys ] " . "name\n"; $SHOWKEYS++ if ($opts{showkeys}); # Building up the qualifiers this way makes it cleaner to # create the <findQualifiers> structure. And since the # parameters are being pre-constructed, throw the search # string on at the end for convenience. @qualifiers = ('sortByNameAsc'); push(@qualifiers, 'exactNameMatch') if ($opts{exact}); push(@qualifiers, 'caseSensitiveMatch') if ($opts{case}); push(@params, findQualifiers(findQualifier(@qualifiers)), name($name)); # First UDDI call: find all businesses that match the # criteria, then loop over them passing each to the # dump_business routine. my $result = find_business(@params); dump_business($_) for ($result->businessInfos->businessInfo); exit; # Dump the contents of a <businessInfo> (an abbreviated # form of a <businessEntity>) record. sub dump_business { my $business = shift; print $business->name, "\n"; print 'uuid:', $business->businessKey, "\n" if $SHOWKEYS; print "\n"; if (my $description = $business->description) { $columns = 72; print wrap("\t", "\t", $description), "\n\n"; } # Hand off each service entry to the dump_service # routine. dump_service($_) for ($business->serviceInfos->serviceInfo); } # Dump the contents of a <businessService> record. What # gets passed in is just a brief overview, however. sub dump_service { my $svc = shift; my ($key, $service); # First order of business (so to speak) is to get the # full <businessService> record, since what was passed # in was a <serviceInfo>, that lacks a lot of data. $key = $svc->serviceKey; # Call get_serviceDetail using the serviceKey attribute # from the short-form data. return unless $service = get_serviceDetail($key); $service = $service->businessService; print ' Service: ', $service->name, "\n"; print ' uuid:', $service->serviceKey, "\n" if $SHOWKEYS; if (my $description = $service->description) { $columns = 64; print wrap("\t ", "\t ", $description), "\n"; } print "\n"; # Hand off a third time to handle <bindingTemplate> # records. dump_template($_) for ($service->bindingTemplates->bindingTemplate); } # Dump the contents of a <bindingTemplate> record. This # doesn't need an extra call, because all the needed data # was retrieved in the earlier get_serviceDetail call. sub dump_template { my $template = shift; print "\tTemplate:\n"; print "\tuuid:", $template->bindingKey, "\n" if $SHOWKEYS; if (my $description = $template->description) { $columns = 60; print wrap("\t\t", "\t\t", $description), "\n"; } # Display either the access point (with a parenthetical # comment about the URLType) or the redirector key. # If neither are present, well, the registry should # never have permitted that, but we can't count on it. if (my $access = $template->accessPoint) { printf "\t Access point (%s): %s\n", $access->attr->URLType, $access->value; } elsif (my $redir = $template->hostingRedirector) { print "\t Hosting redirect to ", $redir->value, "\n"; } else { print "\t No access point or hosting " , "redirector?\n"; } print "\n"; }


Programming Web Services with Perl
Programming Web Services with Perl
ISBN: 0596002068
EAN: 2147483647
Year: 2000
Pages: 123

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net