/******************************************************************************
   EncoreExceptions
   Encore
 
  Copyright (C) 2004, 2005 Free Software Foundation, Inc.
  
  @copyright 2004, 2005, 2006 Oliver Langer

  Author: Oliver Langer

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

 -------------------------------------------------------------------------
  Modification history

  04.01.2005 ola     initial version
  22.08.2006 ola     license changed
  -------------------------------------------------------------------------
******************************************************************************/

#include <ECExceptions.h>

@implementation ECException

- init {
  return [self initWithReason: nil];
}


- initWithReason: (NSString *) aReason {
  self = [ super initWithName: [ self description ]
    reason: aReason userInfo: nil ];
    
  self->cause = nil;
  
  return self;
}

- (void) dealloc {
  if( nil != self->cause ) {
    [self->cause release];
  }
  
  [super dealloc];
}


- (NSException *) cause {
  return self->cause;
}


- (void) raiseWithPredecessor: (NSException *) predecessor {
  [[self setCause: predecessor] raise];
}


- setCause: (NSException *) causingException {
  if( nil != self->cause ) {
    [[[ECIllegalArgumentException alloc]
      initWithArgumentInfo: @"ECException::setCause: Cause has already been"\
        " set."] raiseWithPredecessor: self ];
  }
  
  self->cause = [causingException retain];
  
  return self;
}
@end


@implementation ECIllegalArgumentException

- init {
  self = [ super init ];
  self->argumentInfo = nil;

  return self;
}


- initWithArgumentInfo: (NSString *) anArgumentInfo {
  self = [ super initWithReason: anArgumentInfo];
  self->argumentInfo = [ argumentInfo retain ];

  return self;
}


- (void) dealloc {
  [ self->argumentInfo release ];
  [ super dealloc ];
}


- (NSString *) argumentInfo {
  return self->argumentInfo;
}
@end


@implementation ECPermissionDeniedException

- initForAccessObject: (NSString *) theAccessObject {
  self = [super initWithReason: theAccessObject];
  self->accessObject = [theAccessObject retain];
  
  return self;
}


- (void) dealloc {
  [self->accessObject release];
  [super dealloc];
}


- (NSString *) accessObject {
  return self->accessObject;
}
@end


@implementation ECIncompleteInitializationException
@end


@implementation ECIllegalStateException

- initWithIllegalStateInfo: (NSString *) aStateInfo {
  self = [super initWithReason: aStateInfo];
  self->stateInfo = [stateInfo retain];
  self->caughtException = nil;
  
  return self;
}


- initWithIllegalStateInfo: (NSString *) aStateInfo 
  caughtException: (NSException *) anException {
  self = [self initWithIllegalStateInfo: aStateInfo];
  self->caughtException = [anException retain];
  
  return self;
}


- (void) dealloc {
  [self->stateInfo release];
  [self->caughtException release];
  [super dealloc];
}


- (NSException *) caughtException {
  return self->caughtException;
}


- (NSString *) stateInfo {
  return self->stateInfo;
}
@end


@implementation ECAlreadyExistsException

- initWithResourceInformation: (NSString *) aResourceInfo {
  self = [super initWithReason: aResourceInfo];
  self->resourceInformation = [aResourceInfo retain];
  
  return self;
}


- (void) dealloc {
  [self->resourceInformation release];
  [super dealloc];
}


- (NSString *) resourceInformation {
  return self->resourceInformation;
}
@end


@implementation ECIllegalOperationException

- initWithOperationInformation: (NSString *) operationInfo {
  self = [super initWithReason: operationInfo];
  self->operationInformation = [operationInfo retain];
  
  return self;
}


- (void) dealloc {
  if( nil != self->operationInformation ) {
    [self->operationInformation release];
  }
  
  [super dealloc];
}


- (NSString *) operationInformation {
  return self->operationInformation;
}
@end


@implementation ECNotImplementedException

- initWithOperationInformation: (NSString *) anInfo {
  self = [super initWithReason: anInfo];
  self->operationInformation = [anInfo retain];
  
  return self;
}


- (void) dealloc {
  if( nil != self->operationInformation ) {
    [self->operationInformation release];
  }
  
  [super dealloc];
}


- (NSString *) operationInformation {
  return self->operationInformation;
}
@end


@implementation ECAssertionException
- initWithAssertionInfo: (NSString *) theInfo {
  self = [super initWithReason: theInfo ];
  self->assertionInfo = [theInfo retain];
  
  return self;
}


- (void) dealloc {
  if( nil != self->assertionInfo ) {
    [self->assertionInfo release];
  }
  
  [super dealloc];
}


- (NSString *) assertionInfo {
  return self->assertionInfo;
}

@end

