| 1 | package Net::Z3950::UDDI::Database::soap; | ||
| 2 | our @ISA = qw(Net::Z3950::UDDI::Database); | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | sub _on_fault_die { | ||
| 7 | my($soap, $som) = @_; | ||
| 8 | |||
| 9 | my $msg = ref $som ? $som->faultstring : $soap->transport->status; | ||
| 10 | # We have no UDDI or Database object to invoke _throw() on, so we | ||
| 11 | # have to use the fully-qualified function-call form. | ||
| 12 | Net::Z3950::UDDI::_throw(100, "SOAP error: $msg"); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub _on_fault_warn { | ||
| 16 | my($soap, $som) = @_; | ||
| 17 | |||
| 18 | warn ref $som ? $som->faultstring : $soap->transport->status; | ||
| 19 | } | ||
| 20 | |||
| 21 | use SOAP::Lite on_fault => \&_on_fault_die; | ||
| 22 | |||
| 23 | |||
| 24 | sub rebless { | ||
| 25 | my $class = shift(); | ||
| 26 | my($this) = @_; | ||
| 27 | |||
| 28 | my $soap = new SOAP::Lite; | ||
| 29 | foreach my $property (qw(service proxy uri)) { | ||
| 30 | my $val = $this->config()->property("$property"); | ||
| 31 | $soap->$property($val) if defined $val; | ||
| 32 | } | ||
| 33 | |||
| 34 | my $params = $this->config()->{params}; | ||
| 35 | my $soap_fault = $params->property("soap-fault"); | ||
| 36 | if (defined $soap_fault) { | ||
| 37 | #warn "soap_fault='$soap_fault'"; | ||
| 38 | if ($soap_fault eq "die") { | ||
| 39 | $soap->on_fault(\&_on_fault_die); | ||
| 40 | } elsif ($soap_fault eq "warn") { | ||
| 41 | $soap->on_fault(\&_on_fault_warn); | ||
| 42 | } elsif ($soap_fault eq "ignore") { | ||
| 43 | $soap->on_fault(undef); | ||
| 44 | } else { | ||
| 45 | $this->_throw(1, "unrecognised soap-fault value " . | ||
| 46 | "'$soap_fault' [die|warn|ignore]"); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | my $soap_debug = $params->property("soap-debug"); | ||
| 51 | if (defined $soap_debug) { | ||
| 52 | #warn "soap_debug='$soap_debug'"; | ||
| 53 | SOAP::Lite->import(+trace => [ split /[,\s]+/, $soap_debug ]); | ||
| 54 | } | ||
| 55 | |||
| 56 | $this->{_soap} = $soap; | ||
| 57 | bless $this, $class; | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | sub _soap { shift()->{_soap} } | ||
| 62 | |||
| 63 | |||
| 64 | sub search { | ||
| 65 | my $this = shift(); | ||
| 66 | my($rpn) = @_; | ||
| 67 | |||
| 68 | my $query = $rpn->{query}; | ||
| 69 | $this->_throw(6, "only single-term queries are supported for now") | ||
| 70 | if ref $query ne "Net::Z3950::RPN::Term"; | ||
| 71 | |||
| 72 | ### Ignore attribute set for now | ||
| 73 | ### Ignore all attributes apart from access point, for now | ||
| 74 | my $attrs = $query->{attributes}; | ||
| 75 | my $ap = undef; | ||
| 76 | foreach my $attr (@$attrs) { | ||
| 77 | $ap = $attr->{attributeValue} if $attr->{attributeType} == 1; | ||
| 78 | } | ||
| 79 | $this->_throw(116) if !defined $ap; | ||
| 80 | |||
| 81 | my $map = $this->config()->property("indexmap"); | ||
| 82 | my $bib1map = $map->{"bib-1"}; | ||
| 83 | my $method = $bib1map->{$ap}; | ||
| 84 | $this->_throw(114, $ap) if !defined $method; | ||
| 85 | |||
| 86 | my $term = $query->{term}; | ||
| 87 | my $som = $this->_soap()->call($method, $term); | ||
| 88 | return new Net::Z3950::UDDI::ResultSet::soap($this, $som); | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | package Net::Z3950::UDDI::ResultSet::soap; | ||
| 93 | |||
| 94 | use Net::Z3950::UDDI::ResultSet; | ||
| 95 | our @ISA = qw(Net::Z3950::UDDI::ResultSet); | ||
| 96 | use strict; | ||
| 97 | use warnings; | ||
| 98 | |||
| 99 | sub new { | ||
| 100 | my $class = shift(); | ||
| 101 | my($db, $som) = @_; | ||
| 102 | |||
| 103 | my $this = $class->SUPER::new($db); | ||
| 104 | $this->{som} = $som; | ||
| 105 | $this->{count} = undef; | ||
| 106 | $this->{records} = []; | ||
| 107 | bless $this, $class; | ||
| 108 | |||
| 109 | ### Parse the SOM and extract count and records! | ||
| 110 | |||
| 111 | return $this; | ||
| 112 | } | ||
| 113 | |||
| 114 | sub count { | ||
| 115 | my $this = shift(); | ||
| 116 | |||
| 117 | return 12345; $this->{count}; | ||
| 118 | } | ||
| 119 | |||
| 120 | sub record { | ||
| 121 | my $this = shift(); | ||
| 122 | my($index0) = @_; | ||
| 123 | |||
| 124 | return $this->{records}->[$index0]; | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | 1; |