1 |
joko |
1.1 |
## ---------------------------------------------------------------------- |
2 |
joko |
1.3 |
## $Id: Metadata.pm,v 1.2 2003/02/20 20:04:35 joko Exp $ |
3 |
joko |
1.1 |
## ---------------------------------------------------------------------- |
4 |
joko |
1.2 |
## $Log: Metadata.pm,v $ |
5 |
joko |
1.3 |
## Revision 1.2 2003/02/20 20:04:35 joko |
6 |
|
|
## renamed methods |
7 |
|
|
## - refactored xml-specific code to Data::Storage::Handler::XML |
8 |
|
|
## |
9 |
joko |
1.2 |
## Revision 1.1 2003/02/18 15:35:49 joko |
10 |
|
|
## + initial commit |
11 |
|
|
## |
12 |
joko |
1.1 |
## ---------------------------------------------------------------------- |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
package Data::Rap::Metadata; |
16 |
|
|
|
17 |
|
|
use strict; |
18 |
|
|
use warnings; |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
use Data::Dumper; |
22 |
joko |
1.2 |
use DesignPattern::Object; |
23 |
joko |
1.1 |
|
24 |
|
|
|
25 |
joko |
1.2 |
sub accessMetadata { |
26 |
joko |
1.1 |
my $self = shift; |
27 |
joko |
1.2 |
|
28 |
|
|
# create instance of storage object once |
29 |
|
|
if (!$self->{__rap}->{metadbengine}) { |
30 |
|
|
$self->{__rap}->{metadbengine} = |
31 |
|
|
DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $self->{__rap}->{filename} ); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
return $self->{__rap}->{metadbengine}; |
35 |
|
|
|
36 |
joko |
1.1 |
} |
37 |
|
|
|
38 |
joko |
1.2 |
sub getTargetList { |
39 |
joko |
1.1 |
my $self = shift; |
40 |
|
|
|
41 |
joko |
1.3 |
$self->log( "Reading database of targets (dot) from XML.", 'notice' ); |
42 |
joko |
1.1 |
|
43 |
joko |
1.2 |
# prepare access to metadata (assure instantiated storage handle) |
44 |
|
|
my $mdbe = $self->accessMetadata(); |
45 |
|
|
|
46 |
|
|
$mdbe->sendQuery("*/target"); |
47 |
|
|
$mdbe->circumflex('result'); |
48 |
|
|
|
49 |
|
|
# checks |
50 |
|
|
if ($mdbe->isEmpty) { |
51 |
|
|
$self->log("XML metadata was empty.", 'critical'); |
52 |
|
|
return; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
# trace |
56 |
|
|
#print Dumper($self->{buffer}); |
57 |
|
|
#exit; |
58 |
|
|
|
59 |
|
|
# behaviour |
60 |
|
|
#$self->xml2simplehash(); |
61 |
|
|
my $tree = $mdbe->toEasyTree(); |
62 |
joko |
1.1 |
#return $result; |
63 |
|
|
|
64 |
joko |
1.2 |
# trace |
65 |
|
|
#print Dumper($tree); |
66 |
|
|
#exit; |
67 |
|
|
|
68 |
|
|
# build result |
69 |
|
|
my @targets; |
70 |
|
|
foreach my $entry (@{$tree->{content}}) { |
71 |
|
|
my $description = $entry->{content}->[0]->{content}->[0]->{content}; |
72 |
|
|
push @targets, { name => $entry->{attrib}->{name}, description => $description }; |
73 |
joko |
1.1 |
} |
74 |
|
|
|
75 |
joko |
1.2 |
return \@targets; |
76 |
|
|
|
77 |
|
|
} |
78 |
joko |
1.1 |
|
79 |
|
|
|
80 |
joko |
1.2 |
sub getTargetDetails { |
81 |
joko |
1.1 |
my $self = shift; |
82 |
joko |
1.2 |
my $target = shift; |
83 |
joko |
1.3 |
|
84 |
|
|
# get metadata for single task from storage |
85 |
joko |
1.2 |
my $mdbe = $self->accessMetadata(); |
86 |
|
|
$mdbe->sendQuery("*/target[\@name=\"$target\"]"); |
87 |
joko |
1.3 |
|
88 |
|
|
# FIXME: this is wrong behaviour! upper statement should return a proper |
89 |
|
|
# result, which itself (already) has the method 'isEmpty' or similar... |
90 |
|
|
if ($mdbe->isEmpty()) { |
91 |
|
|
$self->log( "Target '$target' not found.", 'notice' ); |
92 |
|
|
return; |
93 |
|
|
} |
94 |
|
|
|
95 |
joko |
1.2 |
my $tree = $mdbe->toEasyTree(); |
96 |
joko |
1.3 |
|
97 |
|
|
# trace |
98 |
|
|
#print Dumper($tree); |
99 |
|
|
#exit; |
100 |
|
|
|
101 |
joko |
1.2 |
return $tree; |
102 |
joko |
1.1 |
} |
103 |
|
|
|
104 |
|
|
|
105 |
|
|
1; |
106 |
|
|
__END__ |