bloritsch 01/12/03 13:42:37
Modified: src/scratchpad/org/apache/avalon/excalibur/util
ComponentStateValidator.java
src/scratchpad/org/apache/avalon/excalibur/util/test
FullLifecycleComponent.java
Log:
add no-comment methods to ComponentValidator
Revision Changes Path
1.4 +186 -2
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/ComponentStateValidator.java
Index: ComponentStateValidator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/ComponentStateValidator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ComponentStateValidator.java 2001/12/03 21:11:57 1.3
+++ ComponentStateValidator.java 2001/12/03 21:42:37 1.4
@@ -24,10 +24,25 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Michael McKibben</a>
- * @version CVS $Revision: 1.3 $ $Date: 2001/12/03 21:11:57 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/12/03 21:42:37 $
*/
public final class ComponentStateValidator
{
+ private static final String OOO_FAIL = "Initialization out of
order";
+ private static final String LOG_FAIL = OOO_FAIL + ": LogEnabled";
+ private static final String CONTEXT_FAIL = OOO_FAIL + ":
Contextualizable";
+ private static final String PARAMETER_FAIL = OOO_FAIL + ":
Parameterizable";
+ private static final String CONFIGURE_FAIL = OOO_FAIL + ": Configurable";
+ private static final String COMPOSE_FAIL = OOO_FAIL + ": Composable";
+ private static final String INIT_FAIL = OOO_FAIL + ":
Initializable";
+ private static final String START_FAIL = OOO_FAIL + ":
Startable.start()";
+ private static final String STOP_FAIL = OOO_FAIL + ":
Startable.stop()";
+ private static final String SUSPEND_FAIL = OOO_FAIL + ":
Suspendable.suspend()";
+ private static final String RESUME_FAIL = OOO_FAIL + ":
Suspendable.resume()";
+ private static final String DISPOSE_FAIL = OOO_FAIL + ": Disposable";
+ private static final String ACTIVE_FAIL = "Component is not Active";
+ private static final String WRITE_FAIL = "Value is already bound";
+
private static final long LOG_ENABLED = 0x00000001;
private static final long CONTEXTUALIZED = 0x00000002;
private static final long PARAMETERIZED = 0x00000004;
@@ -108,6 +123,19 @@
* LogEnabled or Logger, and if the state has progressed beyond the
Logger
* stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkLogEnabled()
+ {
+ checkLogEnabled( LOG_FAIL );
+ }
+
+ /**
+ * Throw an exception if the initialization is out of order. It tests
to see
+ * if the LOG_ENABLED state has already been set, if the component
implements
+ * LogEnabled or Logger, and if the state has progressed beyond the
Logger
+ * stage.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -131,6 +159,18 @@
* if the CONTEXTUALIZED state has already been set, if the component
implements
* Contextualizable, and if the state has progressed beyond the Context
stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkContextualized()
+ {
+ checkContextualized(CONTEXT_FAIL);
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -154,6 +194,18 @@
* if the PARAMETERIZED state has already been set, if the component
implements
* Parameterizable, and if the state has progressed beyond the
Parameters stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkParameterized()
+ {
+ checkParameterized( PARAMETER_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -172,6 +224,17 @@
}
}
+ /**
+ * 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 IllegalStateException if the state is manage out of order
+ */
+ public void checkConfigured()
+ {
+ checkConfigured( CONFIGURE_FAIL );
+ }
/**
* Throw an exception if the initialization is out of order. It tests
to see
@@ -201,6 +264,18 @@
* if the COMPOSED state has already been set, if the component
implements
* Composable, and if the state has progressed beyond the Configuration
stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkComposed()
+ {
+ checkComposed( COMPOSE_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -224,6 +299,18 @@
* if the INITIALIZED state has already been set, if the component
implements
* Initializable, and if the state has progressed beyond the
<code>initialize</code> stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkInitialized()
+ {
+ checkInitialized( INIT_FAIL );
+ }
+
+ /**
+ * 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
<code>initialize</code> stage.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -247,6 +334,18 @@
* if the STARTED state has already been set, if the component implements
* Startable, and if the state has progressed beyond the
<code>start</code> stage.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkStarted()
+ {
+ checkStarted( START_FAIL );
+ }
+
+ /**
+ * 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
<code>start</code> stage.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -270,6 +369,18 @@
* if the SUSPENDED state has already been set, if the component
implements
* Suspendable, and if the Component is active.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkSuspended()
+ {
+ checkSuspended( SUSPEND_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -290,6 +401,18 @@
* if the SUSPENDED state has not been set, if the component implements
* Suspendable, and if the Component is active.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkResumed()
+ {
+ checkResumed( RESUME_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -310,6 +433,18 @@
* if the STOPPED state has not been set, if the component implements
* Startable, and if the Component is active.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkStopped()
+ {
+ checkStopped( STOP_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -331,6 +466,18 @@
* if the DISPOSED state has not been set, if the component implements
* Disposable.
*
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkDisposed()
+ {
+ checkDisposed( DISPOSE_FAIL );
+ }
+
+ /**
+ * 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.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
@@ -348,12 +495,22 @@
/**
* Checks to see if the state is active.
*
+ * @throws IllegalStateException if the component is not active
+ */
+ public void checkActive()
+ {
+ checkActive( ACTIVE_FAIL );
+ }
+
+ /**
+ * Checks to see if the state is active.
+ *
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the component is not active
*/
public void checkActive( final String message )
{
- if ( (ACTIVE & m_state) > 0 )
+ if ( isActive() )
{
return;
}
@@ -362,8 +519,35 @@
}
/**
+ * Checks to see if the state is active, and returns true or false.
+ *
+ * @returns <code>true</code> if active, <code>false</code> if not
+ */
+ public boolean isActive()
+ {
+ if ( (ACTIVE & m_state) > 0 )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Make sure object has not been assigned yet.
+ *
+ * @param object to test
+ * @throws IllegalStateException if the state is manage out of order
+ */
+ public void checkNotAssigned( final Object object )
+ {
+ checkNotAssigned( object, WRITE_FAIL );
+ }
+
+ /**
* Make sure object has not been assigned yet.
*
+ * @param object to test
* @param message the message to include in the thrown exception
* @throws IllegalStateException if the state is manage out of order
*/
1.2 +17 -17
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/FullLifecycleComponent.java
Index: FullLifecycleComponent.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/FullLifecycleComponent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FullLifecycleComponent.java 2001/12/02 15:15:36 1.1
+++ FullLifecycleComponent.java 2001/12/03 21:42:37 1.2
@@ -32,7 +32,7 @@
* This test class is used to test the AbstractComponent facilities for you.
*
* @author <a href="[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.1 $ $Date: 2001/12/02 15:15:36 $
+ * @version CVS $Revision: 1.2 $ $Date: 2001/12/03 21:42:37 $
*/
public final class FullLifecycleComponent
implements LogEnabled, Contextualizable, Parameterizable, Configurable,
@@ -48,8 +48,8 @@
public void enableLogging( Logger logger )
{
- m_validator.checkNotAssigned( m_logger, "Logger already set!" );
- m_validator.checkLogEnabled( "Logger: Initialization out of order."
);
+ m_validator.checkNotAssigned( m_logger );
+ m_validator.checkLogEnabled();
m_logger = logger;
}
@@ -57,8 +57,8 @@
public void contextualize( Context context )
throws ContextException
{
- m_validator.checkNotAssigned( m_context, "Context already set!" );
- m_validator.checkContextualized( "Context: Initialization out of
order." );
+ m_validator.checkNotAssigned( m_context );
+ m_validator.checkContextualized();
m_context = context;
}
@@ -66,8 +66,8 @@
public void parameterize( Parameters params )
throws ParameterException
{
- m_validator.checkNotAssigned( m_parameters, "Parameters already
set!" );
- m_validator.checkParameterized( "Parameters: Initialization out of
order." );
+ m_validator.checkNotAssigned( m_parameters );
+ m_validator.checkParameterized();
m_parameters = params;
}
@@ -75,8 +75,8 @@
public void configure( Configuration config )
throws ConfigurationException
{
- m_validator.checkNotAssigned( m_configuration, "Configuration
already set!" );
- m_validator.checkConfigured( "Configuration: Initialization out of
order." );
+ m_validator.checkNotAssigned( m_configuration );
+ m_validator.checkConfigured();
m_configuration = config;
}
@@ -84,41 +84,41 @@
public void compose( ComponentManager manager )
throws ComponentException
{
- m_validator.checkNotAssigned( m_componentManager, "Component Manager
already set!" );
- m_validator.checkComposed( "ComponentManager: Initialization out of
order." );
+ m_validator.checkNotAssigned( m_componentManager );
+ m_validator.checkComposed();
}
public void initialize()
throws Exception
{
- m_validator.checkInitialized( "Initialize: Initialization out of
order." );
+ m_validator.checkInitialized();
}
public void start()
throws Exception
{
- m_validator.checkStarted( "Start: Initialization out of order." );
+ m_validator.checkStarted();
}
public void suspend()
{
- m_validator.checkSuspended( "Suspend: Initialization out of order."
);
+ m_validator.checkSuspended();
}
public void resume()
{
- m_validator.checkResumed( "Resume: Initialization out of order." );
+ m_validator.checkResumed();
}
public void stop()
throws Exception
{
- m_validator.checkStopped( "Stop: Initialization out of order." );
+ m_validator.checkStopped();
}
public void dispose()
{
- m_validator.checkDisposed( "Dispose: Initialization out of order." );
+ m_validator.checkDisposed();
m_logger = null;
m_context = null;
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>