/*!
  @header FTExceptions
  @abstract Module of FT
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Free Software Foundation, Inc.
  
  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

  <pre>
  -------------------------------------------------------------------------
  Modification history

  14.02.05 ola     initial version
  23.08.06 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#if !defined(__FTExceptions_H)
#define __FTExceptions_H

#include <BDB/BDB.h>
#include <Encore/ECExceptions.h>
#include <FT/FTObject.h>
#include <FT/FTId.h>

/*!
 * @class FTExceptions
 * @abstract Base class of all FT exceptions
 */
@interface FTException : ECException 
@end


/*!
 * @class FTUnknownException
 * @abstract Thrown in case of receiving an unknown exception
 * @discussion if the FT receives an exception which it did not expect
 *   (e.g. through catching NSException) then it might throw instances of
 *   this class
 */
@interface FTUnknownException : FTException {
  @private 
    NSString *contextInfo;
	NSException *exception;
}


/*!
 * @method initWithContextInfo
 * @param aContextInfo a string giving a hint about the context where 
 *  the unknown exception has been thrown
 * @param anException an exception which has been caught in the context
 * @result self
 */
- initWithContextInfo: (NSString *) aContextInfo
  exception: (NSException *) anException;


/*!
 * @method contextInfo
 * @result a string giving a hint about the context where 
 *  the unknown exception has been thrown
 */
- (NSString *) contextInfo;


/*!
 * @method exception
 * @abstract return the unknown exception
 * @result  exception which has been caught in the context
 */
- (NSException *) exception;
@end


/*!
 * @class FTInternalDatamanagementException
 * @abstract Thrown in case of an error while accessing BDB
 */
@interface FTInternalDatamanagementException : FTException {
  @private
    BDBOperationStatus operationStatus;
	BDBException *bdbException;
}

- int;

/*!
 * @mehod initWithOperationStatus
 * @abstract Hand of the operation status code of BDB
 * @param status giving a hint about the error
 */
- initWithOperationStatus: (BDBOperationStatus) status;


/*!
 * @method initWithBDBException
 * @param anException raisen BDB exception
 */
- initWithBDBException: (BDBException *) anException;
- (void) dealloc;

/*!
 * @method operationStatus
 * @result operation status, if it had been given before; otherwise
 *   BDB_STATUS_UNKNOWN will be returned
 */
- (BDBOperationStatus) operationStatus;


/*!
 * @method bdbException
 * @result returns the underlying bdb exception or nil if it had not been
 *   specified
 */
- (BDBException *) bdbException;
@end


/*!
 * @class FTDatabaseCreationFailedException
 * @abstract Thrown if the creation of a database failed
 */
@interface FTDatabaseCreationFailedException : FTException {
  @private 
    NSString *theReason;
}

/*!
 * @method initWithReason
 * @abstract Initializes the exception with the underlying information
 *   about the reason 
 * @result self
 */
- initWithReason: (NSString *) aReason;
- (void) dealloc;


/*!
 * @method reason
 * @result the underlying reason
 */
- (NSString *) reason;
@end


/*!
 * @class FTTransactionStepException
 * @abstract Thrown if a transaction step {@link FTTransactionStep} within 
 *   a transaction throws an exception.
 * @discussion This may be during a commitment or during an "undo" of previously
 *   performed steps of a commitment.<p/>
 *   Instances of this class contain the original exception.
 */
@interface FTTransactionStepException : FTException {
  @private
    /**
     * Reference to the original transaction step exception
     */
    id transactionStepException;
}

/*!
 * @method initWithTransactionStepException
 * @abstract Initializer used to hand off the causing exception
 * @param causingException exception thrown by transaction step
 * @result self
 */
- initWithTransactionStepException: (id) causingException;
- (void) dealloc;


/*!
 * @method transactionStepException returns the exception the transaction step
 *   originally has thrown
 * @result exception thrown by transaction step
 */
- transactionStepException;
@end


/*!
 * @class FTDatabaseUpdateException
 * @abstract this exception is thrown if the addition, update etc. of data
 *   failed for a more or less unknown reason
 */
@interface FTDatabaseUpdateException : FTException {
  @private
    BDBOperationStatus operationStatus;
    NSString *operationInfo;
}

- initWithOperationStatus: (BDBOperationStatus) aStatus
  operationInformation: (NSString *) anInfo;
- (void) dealloc;


/*!
 * @method operationStatus
 * @result status of the operation
 */
- (BDBOperationStatus) operationStatus;


/*!
 * @method operationInfo
 * @result additional information regarding the failure
 */
- (NSString *) operationInfo;
@end


/*!
 * @class FTGraphRemoveException
 * @abstract Thrown in case of an exception while removing a graph. 
 */
@interface FTGraphRemoveException : FTException {
  @private
    id <FTId> graphId;
}

- initWithGraphId: (id <FTId>) graphId withReason: (NSString *) aReason;
- (void) dealloc;


/*!
 * @method graphId
 * @result id of the affected graph
 */
- (id <FTId>) graphId;
@end

#endif
