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 Format ($$)
103{
104    my $self = shift;
105    my $concatenation = shift;
106
107    my $result = "";
108    my $first = 1;
109    my $index = 0;
110    my $column_count = $self->{'table'}->GetColumnCount();
111    foreach my $item (@{$self->{'values'}})
112    {
113        ++$index;
114
115        if ( ! $first)
116        {
117            $result .= $concatenation;
118        }
119        else
120        {
121            $first = 0;
122        }
123        $result .= $item;
124    }
125    return $result;
126}
127
128
129
130
131sub Clone ($$)
132{
133    my ($self, $new_table) = @_;
134
135    my $clone = { %$self };
136    $clone->{'values'} = [ @{$self->{'values'}} ];
137    $clone->{'table'} = $new_table;
138    bless($clone, "MsiRow");
139
140    return $clone;
141}
142
143
144
145
146sub SetTable ($$)
147{
148    my ($self, $new_table) = @_;
149
150    if (defined $self->{'table'} && $self->{'table'} != $new_table)
151    {
152        MsiTools::Die("can not reset table of row");
153    }
154    else
155    {
156        $self->{'table'} = $new_table;
157    }
158}
159
1601;
161