################################################################## 
## Class Name: DefaultInputController                           ##
##                                                              ##
## Description: This class is the default concrete controller   ##
##              class that is instantiated and returned by the  ##
##              default input controller factory.               ##
##                                                              ##
## Arguments: None.                                             ##
##                                                              ##
##################################################################
package APE::InputControllerFactory::ConcreteInputController::DefaultInputController;

use base 'APE::InputControllerFactory::ConcreteInputController::InputController';

$APE::InputControllerFactory::ConcreteInputController::DefaultInputController::VERSION = '0.6';

use strict;
use warnings;
use Carp;

use APE::InputControllerFactory::ConcreteInputController::Requirement;
use APE::InputControllerFactory::ConcreteInputController::RequirementContainer;


=head1 NAME

APE::InputControllerFactory::ConcreteInputController::DefaultInputController
- standard InputController returned by the default
InputControllerFactory class if a more suitable InputController can
not be found
.

=head1 SYNOPSIS


=head1 DESCRIPTION

The default InputController returned by the
DefaultInputControllerFactory class if a more suitable InputController
can not be found. The DefaultInputControllerFactory is the factory
used by the APE::AtomicProcessEngine class if no
InputControllerFactory is passed to it.


=head1 CONSTANTS

=over 5

=item TRUE

Boolean true.

=cut

use constant TRUE => 1;


=item FALSE

Boolean false.

=cut

use constant FALSE => 0;

{

=back

=head1 CONSTRUCTOR

=over 5

=item $ic = APE::InputControllerFactory::ConcreteInputController::DefaultInputController->new(option => value, ...?)

Use this syntax to create a new DefaultInputController instance.

=over 5

=item atomicProcessContainer

An APE::AtomicProcessContainer object that represents the arraying
process that this InputController should create and manage
Requirements for.

=item parentProcessId

The process id of the parent process. Normally found by calling the
APE::AtomicProcessContainer::getParentProcessId() method.

=item rules

A hash of rules to be executed after the createRequirements() method
has been called. See the
APE::InputControllerFactory::ConcreteInputController::InputController::execRules()
method.

=back

=back

=cut

    my %_attributes = ();

    my %object;


=head2 INSTANTIATION PROCESS

The new method for this object calls the _init() method on $self. If
$self is a derived class then it's _init() method will be called
giving it the chance to remove any arguments it requires from the
%args hash. If there is no _init() method in the derived class then
the _init() method in this class is called.

Derived classes implementing a _init() method should return the %args
hash to the base class:

package Derived::Class;

sub _init {
   my ($self,%args) = @_;
   my $argument = delete $args{classArgument};
   return $self->SUPER::_init(%args);
}


=head1 METHODS

=over 10

=item $ic->_init(%args);

Private method. This method is called by the new method during object
instantiation (see the INSTANTIATION process). The method removes any
of the arguments required by the object from the %args hash and
returns it.

See the INSTANTIATION section for information on how to use this
method in a derived class.

=cut

    sub _init {
	my ($self,%args) = @_;
	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) {
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}

	$args{description} = "Default InputController object";

	return $self->SUPER::_init(%args);
    }


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


=item $ic->getData(APE::InputControllerFactory::ConcreteInputController::Requirement)

Implementation of base class interface method. Sets the Requirement
objects arraying data using its Requirement::setDataStore() method
with the arraying data held in the base classes arrayingData
attribute. The arrayingData is retrieved using the inherited
getArrayingData() method. The arrayingData attribute is set by the
base classes process() method.

=cut

    sub getData {
	my ($self,$requirement) = @_;
	my $arrayingData = $self->getArrayingData;
	croak "Error: no arrayingData has been set ".
            "- default method is via the process method"
	    unless $arrayingData;
	$requirement->setDataStore($arrayingData);
    }


=item $ic->getSessionId()

Implementation of base class interface method. Returns a default
session id number of 1 (one).

=cut

    sub getSessionId {
	my $self = shift;
	return 1;
    }


=item DESTROY

Destroys an instance of this class. Derived classes should call this
method as part of their destructor.

=cut

    sub DESTROY {
	my $self = shift;
	delete $object{ $self };
    }
}

=back

=head1 ALSO SEE

APE::InputControllerFactory::ConcreteInputController::InputController,
APE::InputControllerFactory::DefaultInputControllerFactory

=head1 AUTHOR

Simon Holroyd <holroyd@sanger.ac.uk>

=cut

1;
