| 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::Service::Namespace; | ||
| 10 | |||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use vars qw( $METHODS ); | ||
| 15 | |||
| 16 | use LS; | ||
| 17 | use LS::ID; | ||
| 18 | |||
| 19 | use base 'LS::Base'; | ||
| 20 | |||
| 21 | sub BEGIN { | ||
| 22 | |||
| 23 | $METHODS = [ | ||
| 24 | 'name', | ||
| 25 | |||
| 26 | 'handlers', | ||
| 27 | ]; | ||
| 28 | |||
| 29 | LS::makeAccessorMethods($METHODS, __PACKAGE__); | ||
| 30 | } | ||
| 31 | |||
| 32 | # | ||
| 33 | # new( %options ) - | ||
| 34 | # | ||
| 35 | sub new { | ||
| 36 | |||
| 37 | my $self = shift; | ||
| 38 | my (%options) = @_; | ||
| 39 | |||
| 40 | unless(exists($options{'name'}) && defined($options{'name'})) { | ||
| 41 | |||
| 42 | $self->recordError( 'LS::Service::Namespace requires a name parameter in sub new' ); | ||
| 43 | $self->addStackTrace(); | ||
| 44 | |||
| 45 | return undef; | ||
| 46 | } | ||
| 47 | |||
| 48 | unless (ref $self) { | ||
| 49 | |||
| 50 | $self = bless {}, $self; | ||
| 51 | |||
| 52 | $self->name($options{'name'}); | ||
| 53 | |||
| 54 | # Create the handlers for the various methods if the namespace object | ||
| 55 | # is not subclassed | ||
| 56 | $self->handlers( LS::Service::Namespace::Handlers->new() ); | ||
| 57 | |||
| 58 | $self->handlers()->getMetadata($options{'getMetadata'}); | ||
| 59 | $self->handlers()->getMetadataSubset($options{'getMetadataSubset'}); | ||
| 60 | |||
| 61 | $self->handlers()->getData($options{'getData'}); | ||
| 62 | $self->handlers()->getDataByRange($options{'getDataByRange'}); | ||
| 63 | } | ||
| 64 | |||
| 65 | return $self; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | # | ||
| 70 | # name( $name ) | ||
| 71 | # | ||
| 72 | |||
| 73 | |||
| 74 | # | ||
| 75 | # Handler wrappers - All error checking should be done in LS::Service::DataService | ||
| 76 | # | ||
| 77 | |||
| 78 | # | ||
| 79 | # getMetadata( $lsid, $format, @params ) | ||
| 80 | # | ||
| 81 | sub getMetadata { | ||
| 82 | |||
| 83 | my ($self, $lsid, $format, @params) = @_; | ||
| 84 | |||
| 85 | unless($self->handlers()->getMetadata() ) { | ||
| 86 | |||
| 87 | return LS::Service::Fault->fault('Method Not Implemented'); | ||
| 88 | } | ||
| 89 | |||
| 90 | return $self->handlers()->getMetadata()->($lsid, $format, @params); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | # | ||
| 95 | # getMetadataSubset( $lsid, @params ) | ||
| 96 | # | ||
| 97 | sub getMetadataSubset { | ||
| 98 | |||
| 99 | my ($self, $lsid, @params) = @_; | ||
| 100 | |||
| 101 | unless($self->handlers()->getMetadataSubset()) { | ||
| 102 | return LS::Service::Fault->fault('Method Not Implemented'); | ||
| 103 | } | ||
| 104 | |||
| 105 | return $self->handlers()->getMetadataSubset()->($lsid, @params); | ||
| 106 | } | ||
| 107 | |||
| 108 | |||
| 109 | # | ||
| 110 | # getData( $lsid ) | ||
| 111 | # | ||
| 112 | sub getData { | ||
| 113 | |||
| 114 | my ($self, $lsid) = @_; | ||
| 115 | |||
| 116 | unless($self->handlers()->getData()) { | ||
| 117 | return LS::Service::Fault->fault('Method Not Implemented'); | ||
| 118 | } | ||
| 119 | |||
| 120 | return $self->handlers()->getData()->($lsid); | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | # | ||
| 125 | # getDataByRange( $lsid, $start, $length ) | ||
| 126 | # | ||
| 127 | sub getDataByRange { | ||
| 128 | |||
| 129 | my ($self, $lsid, $start, $length) = @_; | ||
| 130 | |||
| 131 | unless($self->handlers()->getDataByRange()) { | ||
| 132 | return LS::Service::Fault->fault('Method Not Implemented'); | ||
| 133 | } | ||
| 134 | |||
| 135 | return $self->handlers()->getDataByRange()->($lsid, $start, $length); | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | package LS::Service::Namespace::Handlers; | ||
| 140 | |||
| 141 | use strict; | ||
| 142 | use warnings; | ||
| 143 | |||
| 144 | use vars qw( $METHODS ); | ||
| 145 | |||
| 146 | sub BEGIN { | ||
| 147 | |||
| 148 | $METHODS = [ | ||
| 149 | 'getMetadata', | ||
| 150 | 'getMetadataSubset', | ||
| 151 | |||
| 152 | 'getData', | ||
| 153 | 'getDataByRange', | ||
| 154 | ]; | ||
| 155 | |||
| 156 | LS::makeAccessorMethods($METHODS, __PACKAGE__); | ||
| 157 | } | ||
| 158 | |||
| 159 | sub new { | ||
| 160 | my $self = shift; | ||
| 161 | return bless {}, $self; | ||
| 162 | } | ||
| 163 | |||
| 164 | 1; | ||
| 165 | |||
| 166 | __END__ |