TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.util
Class AbstractExceptionBuilder<C extends Exception,E extends Exception>

java.lang.Object
  extended by de.schlichtherle.truezip.util.AbstractExceptionBuilder<C,E>
Type Parameters:
C - The type of the cause exception.
E - The type of the assembled exception.
All Implemented Interfaces:
ExceptionBuilder<C,E>, ExceptionHandler<C,E>
Direct Known Subclasses:
ChainableIOExceptionBuilder

@NotThreadSafe
public abstract class AbstractExceptionBuilder<C extends Exception,E extends Exception>
extends Object
implements ExceptionBuilder<C,E>

Abstract implementation of an exception builder. Subclasses must implement update(Exception, Exception) and may override post(Exception).

Author:
Christian Schlichtherle

Field Summary
private  E assembly
           
 
Constructor Summary
AbstractExceptionBuilder()
           
 
Method Summary
 void check()
          Either returns or checks out and throws the result of the assembly in order to enable the assembly of another exception.
private  E checkout()
           
 E fail(C cause)
          Adds the cause exception to the assembly and checks out and returns the result in order to enable the assembly of another exception.
protected  E post(E assembly)
          This method is called to post-process the given result of the assembly after it has been checked out.
protected abstract  E update(C cause, E previous)
          This method is called to update the given previous result of the assembly with the given cause.
 void warn(C cause)
          Adds the cause exception to the assembly and either returns or checks out and throws the result in order to enable the assembly of another exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

assembly

private E extends Exception assembly
Constructor Detail

AbstractExceptionBuilder

public AbstractExceptionBuilder()
Method Detail

update

protected abstract E update(C cause,
                            E previous)
This method is called to update the given previous result of the assembly with the given cause.

Parameters:
previous - The previous result of the assembly or null if this is the first call since the creation of this instance or the last assembly has been checked out.
cause - A(nother) non-null cause exception to add to the assembly.
Returns:
The assembled exception. null is not permitted.

post

protected E post(E assembly)
This method is called to post-process the given result of the assembly after it has been checked out.

The implementation in the class AbstractExceptionBuilder simply returns the parameter.

Parameters:
assembly - The checked out result of the exception assembly - may be null.
Returns:
The post-processed checked out result of the exception assembly - may be null.

checkout

private E checkout()

fail

public final E fail(C cause)
Adds the cause exception to the assembly and checks out and returns the result in order to enable the assembly of another exception.

Called to handle an exceptional condition which does not allow the caller to proceed its task. The implementation must return an appropriate exception to be thrown by the cooperative algorithm. Finally, if the implementation maintains a state, it must be updated so that this instance can be reused to handle more exceptions!

Specified by:
fail in interface ExceptionBuilder<C extends Exception,E extends Exception>
Specified by:
fail in interface ExceptionHandler<C extends Exception,E extends Exception>
Parameters:
cause - the exception to handle.
Returns:
The assembled exception to throw.
See Also:
update(Exception, Exception), post(Exception)

warn

public final void warn(C cause)
Adds the cause exception to the assembly and either returns or checks out and throws the result in order to enable the assembly of another exception.

Called to handle an exceptional condition which does allow the caller to proceed its task. The implementation may throw an exception of the parameter type T or return from the call. If the implementation maintains a state, it must be updated so that this instance can be reused to handle more exceptions.

Specified by:
warn in interface ExceptionBuilder<C extends Exception,E extends Exception>
Specified by:
warn in interface ExceptionHandler<C extends Exception,E extends Exception>
Parameters:
cause - the exception to handle - null is not permitted.
See Also:
update(Exception, Exception)

check

public final void check()
                 throws E extends Exception
Either returns or checks out and throws the result of the assembly in order to enable the assembly of another exception.

Specified by:
check in interface ExceptionBuilder<C extends Exception,E extends Exception>
Throws:
E extends Exception
See Also:
post(Exception)

TrueZIP Kernel 7.0-rc1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.