Keel 2.1RC2

org.apache.avalon.fortress.util.test
Class ComponentStateValidator

java.lang.Object
  extended byorg.apache.avalon.fortress.util.test.ComponentStateValidator

public final class ComponentStateValidator
extends java.lang.Object

This class provides basic facilities for enforcing Avalon's contracts within your own code. Based on Avalon version from Sandbox.

Version:
CVS $Revision: 1.1 $ $Date: 2004/03/29 17:04:15 $
Author:

Field Summary
private static long COMPOSABLE
           
private static long COMPOSE
           
private static long CONFIGURABLE
           
private static long CONFIGURE
           
private static long CONTEXTUALIZABLE
           
private static long CONTEXTUALIZE
           
private static long DISPOSABLE
           
private static long DISPOSE
           
private static long ENABLE_LOGGING
           
private static long INIT_COMPLETE
           
private static long INIT_MASK
           
private static long INITIALIZABLE
           
private static long INITIALIZE
           
private static long LOG_ENABLED
           
private static long LOGGABLE
           
private  boolean m_active
           
private  long m_interfaces
           
private  long m_methods
           
private  java.lang.Object m_object
           
private  long m_state
           
private static long PARAMETERIZABLE
           
private static long PARAMETERIZE
           
private static long RECOMPOSABLE
           
private static long RECOMPOSE
           
private static long RECONFIGURABLE
           
private static long RECONFIGURE
           
private static long RECONTEXTUALIZABLE
           
private static long RECONTEXTUALIZE
           
private static long RESUME
           
private static long SERVICE
           
private static long SERVICEABLE
           
private static long SET_LOGGER
           
private static long START
           
private static long STARTABLE
           
private static long STOP
           
private static long SUSPEND
           
private static long SUSPENDABLE
           
private static java.lang.String WRITE_FAIL
           
 
Constructor Summary
ComponentStateValidator(java.lang.Object object)
          Create state validator from object (this can be used for more than just components).
 
Method Summary
 void checkActive()
          Checks to see if the state is active.
 void checkActive(java.lang.String message)
          Checks to see if the state is active.
 void checkComposed()
          Throw an exception if the initialization is out of order.
 void checkComposed(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkConfigured()
          Throw an exception if the initialization is out of order.
 void checkConfigured(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkContextualized()
          Throw an exception if the initialization is out of order.
 void checkContextualized(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkDisposed()
          Throw an exception if the initialization is out of order.
 void checkDisposed(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkInitialized()
          Throw an exception if the initialization is out of order.
 void checkInitialized(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkLogEnabled()
          Throw an exception if the initialization is out of order.
 void checkLogEnabled(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkLoggable()
          Throw an exception if the initialization is out of order.
 void checkLoggable(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkNotAssigned(java.lang.Object object)
          Make sure object has not been assigned yet.
 void checkNotAssigned(java.lang.Object object, java.lang.String message)
          Make sure object has not been assigned yet.
 void checkParameterized()
          Throw an exception if the initialization is out of order.
 void checkParameterized(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkResumed()
          Throw an exception if the initialization is out of order.
 void checkResumed(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkServiced()
          Throw an exception if the initialization is out of order.
 void checkServiced(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkStarted()
          Throw an exception if the initialization is out of order.
 void checkStarted(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkStopped()
          Throw an exception if the initialization is out of order.
 void checkStopped(java.lang.String message)
          Throw an exception if the initialization is out of order.
 void checkSuspended()
          Throw an exception if the initialization is out of order.
 void checkSuspended(java.lang.String message)
          Throw an exception if the initialization is out of order.
private  void generalCheckActive(java.lang.String message, long interfaceId, long methodId)
          Active Service methods may only be called after all of the Initialization methods have been called, any before any of the Descruction methods have been called.
private  void generalCheckDest(java.lang.String message, long interfaceId, long methodId)
          Descruction Methods must be called in order.
private  void generalCheckInit(java.lang.String message, long interfaceId, long methodId)
          Initialization methods must be called in order, must all be called, may not be called more than once, and may not be called once any of the Descruction methods have been called.
private  void generalCheckInitComplete()
          Test to see if this was the last initialization method.
private  java.lang.String getInterfaceName(long interfaceId)
           
private  java.lang.String getLastMethod(long state)
           
private  java.lang.String getMethodName(long methodId)
           
 boolean isActive()
          Checks to see if the state is active, and returns true or false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WRITE_FAIL

private static final java.lang.String WRITE_FAIL
See Also:
Constant Field Values

LOG_ENABLED

private static final long LOG_ENABLED
See Also:
Constant Field Values

LOGGABLE

private static final long LOGGABLE
See Also:
Constant Field Values

CONTEXTUALIZABLE

private static final long CONTEXTUALIZABLE
See Also:
Constant Field Values

COMPOSABLE

private static final long COMPOSABLE
See Also:
Constant Field Values

SERVICEABLE

private static final long SERVICEABLE
See Also:
Constant Field Values

CONFIGURABLE

private static final long CONFIGURABLE
See Also:
Constant Field Values

PARAMETERIZABLE

private static final long PARAMETERIZABLE
See Also:
Constant Field Values

INITIALIZABLE

private static final long INITIALIZABLE
See Also:
Constant Field Values

STARTABLE

private static final long STARTABLE
See Also:
Constant Field Values

SUSPENDABLE

private static final long SUSPENDABLE
See Also:
Constant Field Values

RECONTEXTUALIZABLE

private static final long RECONTEXTUALIZABLE
See Also:
Constant Field Values

RECOMPOSABLE

private static final long RECOMPOSABLE
See Also:
Constant Field Values

RECONFIGURABLE

private static final long RECONFIGURABLE
See Also:
Constant Field Values

DISPOSABLE

private static final long DISPOSABLE
See Also:
Constant Field Values

ENABLE_LOGGING

private static final long ENABLE_LOGGING
See Also:
Constant Field Values

SET_LOGGER

private static final long SET_LOGGER
See Also:
Constant Field Values

CONTEXTUALIZE

private static final long CONTEXTUALIZE
See Also:
Constant Field Values

SERVICE

private static final long SERVICE
See Also:
Constant Field Values

COMPOSE

private static final long COMPOSE
See Also:
Constant Field Values

CONFIGURE

private static final long CONFIGURE
See Also:
Constant Field Values

PARAMETERIZE

private static final long PARAMETERIZE
See Also:
Constant Field Values

INITIALIZE

private static final long INITIALIZE
See Also:
Constant Field Values

START

private static final long START
See Also:
Constant Field Values

INIT_COMPLETE

private static final long INIT_COMPLETE
See Also:
Constant Field Values

SUSPEND

private static final long SUSPEND
See Also:
Constant Field Values

RECONTEXTUALIZE

private static final long RECONTEXTUALIZE
See Also:
Constant Field Values

RECOMPOSE

private static final long RECOMPOSE
See Also:
Constant Field Values

RECONFIGURE

private static final long RECONFIGURE
See Also:
Constant Field Values

RESUME

private static final long RESUME
See Also:
Constant Field Values

STOP

private static final long STOP
See Also:
Constant Field Values

DISPOSE

private static final long DISPOSE
See Also:
Constant Field Values

INIT_MASK

private static final long INIT_MASK
See Also:
Constant Field Values

m_interfaces

private final long m_interfaces

m_methods

private final long m_methods

m_state

private long m_state

m_active

private boolean m_active

m_object

private final java.lang.Object m_object
Constructor Detail

ComponentStateValidator

public ComponentStateValidator(java.lang.Object object)
Create state validator from object (this can be used for more than just components).

Method Detail

getInterfaceName

private java.lang.String getInterfaceName(long interfaceId)

getMethodName

private java.lang.String getMethodName(long methodId)

getLastMethod

private java.lang.String getLastMethod(long state)

generalCheckInitComplete

private void generalCheckInitComplete()
Test to see if this was the last initialization method.


generalCheckInit

private void generalCheckInit(java.lang.String message,
                              long interfaceId,
                              long methodId)
Initialization methods must be called in order, must all be called, may not be called more than once, and may not be called once any of the Descruction methods have been called.


generalCheckActive

private void generalCheckActive(java.lang.String message,
                                long interfaceId,
                                long methodId)
Active Service methods may only be called after all of the Initialization methods have been called, any before any of the Descruction methods have been called. While in the active state, the contracts of the methods allow the active state methods to be called any number of times, in any order. The resume() method should do nothing if suspend() has not yet been called for example.


generalCheckDest

private void generalCheckDest(java.lang.String message,
                              long interfaceId,
                              long methodId)
Descruction Methods must be called in order. They may be called before all of the Initialization methods have been called if there was an error.


checkLogEnabled

public void checkLogEnabled()
Throw an exception if the initialization is out of order. It tests to see if the ENABLE_LOGGING state has already been set, if the component implements LogEnabled, and if the state has progressed beyond the Logger stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkLogEnabled

public void checkLogEnabled(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the ENABLE_LOGGING state has already been set, if the component implements LogEnabled, and if the state has progressed beyond the Logger stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkLoggable

public void checkLoggable()
Throw an exception if the initialization is out of order. It tests to see if the SET_LOGGER state has already been set, if the component implements Loggable, and if the state has progressed beyond the Logger stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkLoggable

public void checkLoggable(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the SET_LOGGER state has already been set, if the component implements Loggable, and if the state has progressed beyond the Logger stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkContextualized

public void checkContextualized()
Throw an exception if the initialization is out of order. It tests to see if the CONTEXTUALIZED state has already been set, if the component implements Contextualizable, and if the state has progressed beyond the Context stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkContextualized

public void checkContextualized(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the CONTEXTUALIZED state has already been set, if the component implements Contextualizable, and if the state has progressed beyond the Context stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkServiced

public void checkServiced()
Throw an exception if the initialization is out of order. It tests to see if the SERVICE state has already been set, if the component implements Composable, and if the state has progressed beyond the Configuration stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkServiced

public void checkServiced(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the SERVICE state has already been set, if the component implements Composable, and if the state has progressed beyond the Configuration stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkComposed

public void checkComposed()
Throw an exception if the initialization is out of order. It tests to see if the COMPOSED state has already been set, if the component implements Composable, and if the state has progressed beyond the Configuration stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkComposed

public void checkComposed(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the COMPOSED state has already been set, if the component implements Composable, and if the state has progressed beyond the Configuration stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkConfigured

public void checkConfigured()
Throw an exception if the initialization is out of order. It tests to see if the CONFIGURED state has already been set, if the component implements Configurable, and if the state has progressed beyond the Configuration stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkConfigured

public void checkConfigured(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the CONFIGURED state has already been set, if the component implements Configurable, and if the state has progressed beyond the Configuration stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkParameterized

public void checkParameterized()
Throw an exception if the initialization is out of order. It tests to see if the PARAMETERIZED state has already been set, if the component implements Parameterizable, and if the state has progressed beyond the Parameters stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkParameterized

public void checkParameterized(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the PARAMETERIZED state has already been set, if the component implements Parameterizable, and if the state has progressed beyond the Parameters stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkInitialized

public void checkInitialized()
Throw an exception if the initialization is out of order. It tests to see if the INITIALIZED state has already been set, if the component implements Initializable, and if the state has progressed beyond the initialize stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkInitialized

public void checkInitialized(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the INITIALIZED state has already been set, if the component implements Initializable, and if the state has progressed beyond the initialize stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkStarted

public void checkStarted()
Throw an exception if the initialization is out of order. It tests to see if the STARTED state has already been set, if the component implements Startable, and if the state has progressed beyond the start stage.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkStarted

public void checkStarted(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the STARTED state has already been set, if the component implements Startable, and if the state has progressed beyond the start stage.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkSuspended

public void checkSuspended()
Throw an exception if the initialization is out of order. It tests to see if the SUSPENDED state has already been set, if the component implements Suspendable, and if the Component is active.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkSuspended

public void checkSuspended(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the SUSPENDED state has already been set, if the component implements Suspendable, and if the Component is active.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkResumed

public void checkResumed()
Throw an exception if the initialization is out of order. It tests to see if the SUSPENDED state has not been set, if the component implements Suspendable, and if the Component is active.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkResumed

public void checkResumed(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the SUSPENDED state has not been set, if the component implements Suspendable, and if the Component is active.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkStopped

public void checkStopped()
Throw an exception if the initialization is out of order. It tests to see if the STOPPED state has not been set, if the component implements Startable, and if the Component is active.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkStopped

public void checkStopped(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the STOPPED state has not been set, if the component implements Startable, and if the Component is active.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkDisposed

public void checkDisposed()
Throw an exception if the initialization is out of order. It tests to see if the DISPOSED state has not been set, if the component implements Disposable.

Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkDisposed

public void checkDisposed(java.lang.String message)
Throw an exception if the initialization is out of order. It tests to see if the DISPOSED state has not been set, if the component implements Disposable.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkActive

public void checkActive()
Checks to see if the state is active.

Throws:
java.lang.IllegalStateException - if the component is not active

checkActive

public void checkActive(java.lang.String message)
Checks to see if the state is active.

Parameters:
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the component is not active

isActive

public boolean isActive()
Checks to see if the state is active, and returns true or false.

Returns:
true if active, false if not

checkNotAssigned

public void checkNotAssigned(java.lang.Object object)
Make sure object has not been assigned yet.

Parameters:
object - to test
Throws:
java.lang.IllegalStateException - if the state is manage out of order

checkNotAssigned

public void checkNotAssigned(java.lang.Object object,
                             java.lang.String message)
Make sure object has not been assigned yet.

Parameters:
object - to test
message - the message to include in the thrown exception
Throws:
java.lang.IllegalStateException - if the state is manage out of order

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.