################################################################## 
## Class Name: FlushController                                  ##
##                                                              ##
## Description: This abstract class represents a concrete flush ##
##              controller and should be implemented by any     ##
##              flush controller class.                         ##
##                                                              ##
## Arguments: arrayingEntity - the target ArrayingEntity object.##
##            outputController - the output controller object.  ##
##            programName - the name of the flushing program.   ##
##                                                              ##
##################################################################
package APE::FlushControllerFactory::ConcreteFlushController::FlushController;

$APE::FlushControllerFactory::ConcreteFlushController::FlushController::VERSION = '0.6';

use strict;
use warnings;
use Carp;

use constant TRUE  => 1;
use constant FALSE => 0;

{
    my %_attributes = (arrayingEntity => undef);

    my %object;

    foreach my $attName (keys(%_attributes)) {
	no strict 'refs';
	*{__PACKAGE__ . "::get\u$attName"} = sub { $object{ $_[0] }->{$attName} }
    }

    #################################################################
    ## Constructor method for this object. Returns a new
    ## DefaultInputController object.
    #################################################################
    sub new {
	my ($proto,%args) = @_;

	## This is an abstract class, instances of it can not be created.
	confess "Error: can not create an instance of the ".
	  "abstract class ".
	    "'APE::FlushControllerFactory::ConcreteFlushController::FlushController'."
	    if $proto eq
	      'APE::FlushControllerFactory::ConcreteFlushController::FlushController';

	my $class = ref($proto) || $proto;
	my $self  = bless {}, $class;

	%args = $self->_init(%args);

	my @leftover = keys %args;

	confess "Error: the following arguments are unknown - @leftover\n" if @leftover;

	return $self;
    }


    #################################################################
    ## Initialise the objects private attributes. The argument is
    ## deleted as it is found, initialised and set.
    #################################################################
    sub _init {	
	my ($self,%args) = @_;
	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) { 
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}

	## Verify that all of the attributes have been set.
	croak "Error: attribute 'arrayingEntity' is required ".
	    "by the FlushController abstract class."
	    unless exists($object{ $self }->{arrayingEntity});

	return %args;
    }


    ## Abstract methods.
    sub beginTrasaction     { die "Error: abstract method ".
                                  "- requires overriding." }
    sub flush               { die "Error: abstract method ".
                                  "- requires overriding." }
    sub commitTransaction   { die "Error: abstract method ".
                                  "- requires overriding." }
    sub rollbackTransaction { die "Error: abstract method ".
                                  "- requires overriding." }
    sub getDescription      { die "Error: abstract method ".
                                  "- requires overriding." }

}

1;
