1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22package installer::patch::MsiRow;
23
24=head1 NAME
25
26    package installer::patch::MsiRow - Class that represents a single row of an Msi table.
27
28=cut
29
30
31=head2 new ($class, $table, @data)
32
33    Create a new MsiRow object for the given table row data.  Each row
34    stores a reference to its $table so that it can access global
35    values like column names.
36
37=cut
38sub new ($$@)
39{
40    my ($class, $table, @data) = @_;
41
42    my $self = {
43        'table' => $table,
44        'values' => [@data]
45    };
46    bless($self, $class);
47
48    my $column_count = $table->GetColumnCount();
49    while (scalar @{$self->{'values'}} < $column_count)
50    {
51        push @{$self->{'values'}}, "";
52    }
53
54    return $self;
55}
56
57
58
59=head2 GetValue($self, $column)
60
61    Return the value in the column specified by $column, which can be
62    either the column name or the index of the column.
63
64=cut
65sub GetValue ($$)
66{
67    my ($self, $column) = @_;
68
69    if ($column =~ /^\d+$/)
70    {
71        return $self->{'values'}->[$column];
72    }
73    else
74    {
75        my $column_index = $self->{'table'}->GetColumnIndex($column);
76        return $self->{'values'}->[$column_index];
77    }
78}
79
80
81
82
83sub SetValue ($$$)
84{
85    my ($self, $column, $value) = @_;
86
87    if ($column =~ /^\d+$/)
88    {
89        $self->{'values'}->[$column] = $value;
90    }
91    else
92    {
93        my $column_index = $self->{'table'}->GetColumnIndex($column);
94        $self->{'values'}->[$column_index] = $value;
95    }
96    $self->{'table'}->MarkAsModified();
97}
98
99
100
101
102sub GetAllValues ($)
103{
104    my ($self) = @_;
105    return @{$self->{'values'}};
106}
107
108
109
110
111sub Format ($$)
112{
113    my $self = shift;
114    my $concatenation = shift;
115
116    my $result = "";
117    my $first = 1;
118    my $index = 0;
119    my $column_count = $self->{'table'}->GetColumnCount();
120    foreach my $item (@{$self->{'values'}})
121    {
122        ++$index;
123
124        if ( ! $first)
125        {
126            $result .= $concatenation;
127        }
128        else
129        {
130            $first = 0;
131        }
132        $result .= $item;
133    }
134    return $result;
135}
136
137
138
139
140sub Clone ($$)
141{
142    my ($self, $new_table) = @_;
143
144    my $clone = { %$self };
145    $clone->{'values'} = [ @{$self->{'values'}} ];
146    $clone->{'table'} = $new_table;
147    bless($clone, "MsiRow");
148
149    return $clone;
150}
151
152
153
154
155sub SetTable ($$)
156{
157    my ($self, $new_table) = @_;
158
159    if (defined $self->{'table'} && $self->{'table'} != $new_table)
160    {
161        MsiTools::Die("can not reset table of row");
162    }
163    else
164    {
165        $self->{'table'} = $new_table;
166    }
167}
168
1691;
170