cvs server: Diffing .
cvs server: Diffing documentation
cvs server: Diffing documentation/diagrams
cvs server: Diffing documentation/diagrams/images
cvs server: Diffing documentation/diagrams/images/uml
cvs server: Diffing documentation/resources
cvs server: Diffing documentation/resources/images
cvs server: Diffing documentation/stylesheets
cvs server: Diffing documentation/stylesheets/system
cvs server: Diffing documentation/xdocs
cvs server: Diffing documentation/xdocs/authors
cvs server: Diffing documentation/xdocs/authors/dtd
cvs server: Diffing documentation/xdocs/authors/dtd/ent
cvs server: Diffing documentation/xdocs/developing
cvs server: Diffing documentation/xdocs/developing/dtd
cvs server: Diffing documentation/xdocs/developing/dtd/ent
cvs server: Diffing documentation/xdocs/dtd
cvs server: Diffing documentation/xdocs/framework
cvs server: Diffing documentation/xdocs/framework/dtd
cvs server: Diffing documentation/xdocs/history
cvs server: Diffing java
cvs server: Diffing java/org
cvs server: Diffing java/org/apache
cvs server: Diffing java/org/apache/avalon
cvs server: Diffing java/org/apache/avalon/framework
Index: java/org/apache/avalon/framework/AbstractComponent.java
===================================================================
RCS file: /home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/AbstractComponent.java,v
retrieving revision 1.3
diff -u -r1.3 AbstractComponent.java
--- java/org/apache/avalon/framework/AbstractComponent.java	2001/11/30 21:54:02	1.3
+++ java/org/apache/avalon/framework/AbstractComponent.java	2001/11/30 22:58:28
@@ -102,6 +102,11 @@
         m_mask = mask &(~ACTIVE);
     }
 
+    protected final void checkAssigned( Object source )
+    {
+        checkAssigned( source, "Attempt to set write-once value." );
+    }
+
     /**
      * Throw an exception if a value is already set on a write-once object.
      *
@@ -117,6 +122,32 @@
         }
     }
 
+    private final void checkState( final String message, final long state )
+    {
+        if( ( (m_state & m_mask & state) > 0 ) ||
+            ( (m_mask & state) == 0 ) ||
+            ( m_state > state ) )
+        {
+            throw new IllegalStateException( message );
+        }
+
+        m_state |= state;
+        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
+        {
+            m_state |= ACTIVE;
+        }
+    }
+
+    private final String getDefaultMessage ( final String stage )
+    {
+        return "Lifecycle phases out of order for " + getClass().getName() + " - did not expect the " + stage + " stage at this time.";
+    }
+
+    public final void checkLogEnabled()
+    {
+        checkLogEnabled( getDefaultMessage ( "LogEnabled" ) );
+    }
+
     /**
      * 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
@@ -128,18 +159,12 @@
      */
     public final void checkLogEnabled( final String message )
     {
-        if( ( (m_state & m_mask & LOG_ENABLED) > 0 ) ||
-            ( (m_mask & LOG_ENABLED) == 0 ) ||
-            ( m_state > LOG_ENABLED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, LOG_ENABLED );
+    }
 
-        m_state |= LOG_ENABLED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkContextualized()
+    {
+        checkContextualized( getDefaultMessage ( "Contextualized" ) );
     }
 
     /**
@@ -152,17 +177,12 @@
      */
     protected final void checkContextualized( final String message )
     {
-        if ( ( (m_state & m_mask & CONTEXTUALIZED) > 0 ) ||
-             ( (m_mask & CONTEXTUALIZED) == 0 ) || ( m_state > CONTEXTUALIZED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, CONTEXTUALIZED );
+    }
 
-        m_state |= CONTEXTUALIZED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkParameterized()
+    {
+        checkParameterized( getDefaultMessage ( "Parameterized" ) );
     }
 
     /**
@@ -175,17 +195,12 @@
      */
     protected final void checkParameterized( final String message )
     {
-        if ( ( (m_state & m_mask & PARAMETERIZED) > 0 ) ||
-             ( (m_mask & PARAMETERIZED) == 0 ) || ( m_state > PARAMETERIZED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, PARAMETERIZED );
+    }
 
-        m_state |= PARAMETERIZED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkConfigured()
+    {
+        checkConfigured( getDefaultMessage ( "Configured" ) );
     }
 
     /**
@@ -198,17 +213,12 @@
      */
     protected final void checkConfigured( final String message )
     {
-        if ( ( (m_state & m_mask & CONFIGURED) > 0 ) ||
-             ( (m_mask & CONFIGURED) == 0 ) || ( m_state > CONFIGURED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, CONFIGURED );
+    }
 
-        m_state |= CONFIGURED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkComposed()
+    {
+        checkComposed( getDefaultMessage ( "Composed" ) );
     }
 
     /**
@@ -221,17 +231,12 @@
      */
     protected final void checkComposed( final String message )
     {
-        if ( ( (m_state & m_mask & COMPOSED) > 0 ) ||
-             ( (m_mask & COMPOSED) == 0 ) || ( m_state > COMPOSED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, COMPOSED );
+    }
 
-        m_state |= COMPOSED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkInitialized()
+    {
+        checkInitialized( getDefaultMessage ( "Initialized" ) );
     }
 
     /**
@@ -244,17 +249,12 @@
      */
     protected final void checkInitialized( final String message )
     {
-        if ( ( (m_state & m_mask & INITIALIZED) > 0 ) ||
-             ( (m_mask & INITIALIZED) == 0 ) || ( m_state > INITIALIZED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, INITIALIZED );
+    }
 
-        m_state |= INITIALIZED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkStarted()
+    {
+        checkInitialized( getDefaultMessage ( "Started" ) );
     }
 
     /**
@@ -267,17 +267,12 @@
      */
     protected final void checkStarted( final String message )
     {
-        if ( ( (m_state & m_mask & STARTED) > 0 ) ||
-             ( (m_mask & STARTED) == 0 ) || ( m_state > STARTED ) )
-        {
-            throw new IllegalStateException( message );
-        }
+        checkState( message, STARTED );
+    }
 
-        m_state |= STARTED;
-        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
-        {
-            m_state |= ACTIVE;
-        }
+    public final void checkSuspended()
+    {
+        checkSuspended( getDefaultMessage ( "Suspended" ) );
     }
 
     /**
@@ -290,7 +285,7 @@
      */
     protected final void checkSuspended( final String message )
     {
-        ComponentUtil.checkActive( m_state, m_mask, message );
+        checkActive( message );
         if ( ( (m_state & m_mask & SUSPENDED) > 0 ) || ( (m_mask & SUSPENDED) == 0 ) )
         {
             throw new IllegalStateException( message );
@@ -299,6 +294,11 @@
         m_state |= SUSPENDED;
     }
 
+    public final void checkResumed()
+    {
+        checkResumed( getDefaultMessage ( "Resumed" ) );
+    }
+
     /**
      * 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
@@ -309,7 +309,7 @@
      */
     protected final void checkResumed( final String message )
     {
-        ComponentUtil.checkActive( m_state, m_mask, message );
+        checkActive( message );
         if ( ( (m_state & m_mask & SUSPENDED) == 0 ) || ( (m_mask & SUSPENDED) == 0 ) )
         {
             throw new IllegalStateException( message );
@@ -318,6 +318,11 @@
         m_state &= ~SUSPENDED;
     }
 
+    public final void checkStopped()
+    {
+        checkStopped( getDefaultMessage ( "Stopped" ) );
+    }
+
     /**
      * 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
@@ -338,6 +343,11 @@
         m_state |= STOPPED;
     }
 
+    public final void checkDisposed()
+    {
+        checkDisposed( getDefaultMessage ( "Disposed" ) );
+    }
+
     /**
      * 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
@@ -355,6 +365,11 @@
 
         m_state &= ~ACTIVE;
         m_state |= DISPOSED;
+    }
+
+    public final void checkActive()
+    {
+        checkActive( getClass().getName() + " has not been properly initialized." );
     }
 
     /**
cvs server: Diffing java/org/apache/avalon/framework/activity
cvs server: Diffing java/org/apache/avalon/framework/component
cvs server: Diffing java/org/apache/avalon/framework/configuration
cvs server: Diffing java/org/apache/avalon/framework/context
cvs server: Diffing java/org/apache/avalon/framework/logger
cvs server: Diffing java/org/apache/avalon/framework/parameters
cvs server: Diffing java/org/apache/avalon/framework/thread
cvs server: Diffing logos
cvs server: Diffing proposal
cvs server: Diffing proposal/persistable
cvs server: Diffing skins
cvs server: Diffing test
cvs server: Diffing test/org
cvs server: Diffing test/org/apache
cvs server: Diffing test/org/apache/avalon
cvs server: Diffing test/org/apache/avalon/framework
cvs server: Diffing test/org/apache/avalon/framework/component
cvs server: Diffing test/org/apache/avalon/framework/component/test
cvs server: Diffing test/org/apache/avalon/framework/configuration
cvs server: Diffing test/org/apache/avalon/framework/configuration/test
cvs server: Diffing test/org/apache/avalon/framework/context
cvs server: Diffing test/org/apache/avalon/framework/context/test
cvs server: Diffing test/org/apache/avalon/framework/parameters
cvs server: Diffing test/org/apache/avalon/framework/parameters/test
cvs server: Diffing test/org/apache/avalon/framework/test
