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