| 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::AdvancedDataService; | ||
| 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::Service::DataService'; | ||
| 20 | |||
| 21 | sub BEGIN { | ||
| 22 | |||
| 23 | $METHODS = [ | ||
| 24 | 'mappings', | ||
| 25 | ]; | ||
| 26 | |||
| 27 | LS::makeAccessorMethods($METHODS, __PACKAGE__); | ||
| 28 | } | ||
| 29 | |||
| 30 | # | ||
| 31 | # new( %options ) - | ||
| 32 | # | ||
| 33 | sub new { | ||
| 34 | |||
| 35 | my $self = shift; | ||
| 36 | $self = $self->SUPER::new( @_ ); | ||
| 37 | |||
| 38 | return undef | ||
| 39 | unless(ref $self); | ||
| 40 | |||
| 41 | $self->mappings( {} ); | ||
| 42 | return $self; | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | # | ||
| 47 | # addNamespaceMappings( %mappings ) - | ||
| 48 | # | ||
| 49 | sub addNamespaceMappings { | ||
| 50 | |||
| 51 | my $self = shift; | ||
| 52 | my %mappings = @_; | ||
| 53 | |||
| 54 | foreach my $regex (keys(%mappings)) { | ||
| 55 | $self->mappings()->{ $regex } = $mappings{ $regex }; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | # | ||
| 61 | # findNamespace( $namespace ) - | ||
| 62 | # | ||
| 63 | sub findNamespace { | ||
| 64 | |||
| 65 | my $self = shift; | ||
| 66 | my $namespace = shift; | ||
| 67 | |||
| 68 | my $ns = $self->SUPER::findNamespace( $namespace ); | ||
| 69 | |||
| 70 | # Exact match takes precedence | ||
| 71 | return $ns | ||
| 72 | if($ns); | ||
| 73 | |||
| 74 | # Look for a mapping | ||
| 75 | foreach my $regex (keys(%{ $self->mappings() }) ) { | ||
| 76 | |||
| 77 | if($namespace =~ m/$regex/) { | ||
| 78 | |||
| 79 | my $cmp_namespace = $self->mappings->{ $regex }; | ||
| 80 | |||
| 81 | $ns = $self->SUPER::findNamespace( $cmp_namespace ); | ||
| 82 | last | ||
| 83 | if($ns); | ||
| 84 | } | ||
| 85 | |||
| 86 | } # end foreach | ||
| 87 | |||
| 88 | return $ns; | ||
| 89 | } | ||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | __END__ |