# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/sbin/install/ecc/lib/ECC/DialPropertyManager.pm 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
package DialPropertyManager;

use constant dial_separator => ' = ';

sub new {
	my ($class) = @_;
	my ($self) = {};
    bless $self, $class;
    return $self;
}

sub read {
	my ($self, $file) = @_;
	open CONFIGFILE, "< $file";
	while ($line = <CONFIGFILE>) {
		chomp $line;
		my ($key, $value) = split( dial_separator, $line);
		$self->{$key} = $value;
	}
	close CONFIGFILE;
	return 0;
}

sub get {
	my ($self, $key) = @_;
    return $self->{$key};
}

sub set {
	my ($self, $key, $value) = @_;
    $self->{$key} = $value;
}

sub add {
	my ($self, $key, $value) = @_;
    $self->{$key} = $value;
}

sub remove {
	my ($self, $key) = @_;
    delete $self->{$key};
}

sub write {
    my ($self, $file) = @_;

	open CONFIGFILE, "+> $file" or return 0;

	# sort and write out our properties
	foreach $key (sort (keys(%$self))) {
		print CONFIGFILE "$key".dial_separator."$self->{$key}\n";
	}
	close CONFIGFILE;

	return 0;
}

sub dump {
    my ($self) = @_;
    foreach $key (sort (keys(%$self))) {
        print STDOUT "$key".dial_separator."$self->{$key}\n";
    }
}

1;
