Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2299 - in development/main/metro/composition/testing/activity/src: main/net/dpml/test test/net/dpml/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: peter AT neubauer.se
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2299 - in development/main/metro/composition/testing/activity/src: main/net/dpml/test test/net/dpml/test
  • Date: Sun, 17 Apr 2005 03:33:02 -0400

Author: peter AT neubauer.se
Date: Sun Apr 17 03:32:58 2005
New Revision: 2299

Modified:

development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java

development/main/metro/composition/testing/activity/src/main/net/dpml/test/Container.java

development/main/metro/composition/testing/activity/src/test/net/dpml/test/ComponentTestCase.java
Log:
adding State package behaviour to the testcases. This should be applied to
the ContainerTestCase and not the the Component testcase, but had no time to
debug why the Component.Controller is not returned by the

StateManager manager = parts.selectTestStateManager(); in
Container.java.


Modified:
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
==============================================================================
---
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
(original)
+++
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Component.java
Sun Apr 17 03:32:58 2005
@@ -18,76 +18,83 @@

package net.dpml.test;

-import java.util.Map;
-import java.util.Map.Entry;
import java.util.logging.Logger;
-import java.lang.reflect.Method;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

+import net.dpml.state.State;
+import net.dpml.state.StateManager;

/**
* Experimental component dealing with activitiy state management.
*
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library</a>
*/
public class Component
{
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// static
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------

public static final boolean TYPE_THREADSAFE_CAPABLE = true;

- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// state
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------

- private final Logger m_logger;
+ private final Logger m_logger;

- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// constructor
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------

- /**
- * Creation of a component that describes an activity model.
- *
- * @param logger the logging channel assigned by the container
- */
+ /**
+ * Creation of a component that describes an activity model.
+ *
+ * @param logger
+ * the logging channel assigned by the container
+ */
public Component( final Logger logger )
- {
- m_logger = logger;
- }
+ {
+ m_logger = logger;
+ }

private Logger getLogger()
{
return m_logger;
}

- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// Activity
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------

- public static class Controller
+ public static class Controller implements StateManager
{
- public static final State AVAILABLE = new Available();
- public static final State STARTED = new Started();
- public static final State STOPPED = new Stopped();
- public static final State TERMINATED = new Terminated();
+ public static final AbstractState AVAILABLE = new Available();

- protected final Component m_instance;
- protected final ChangeListener m_listener;
- protected final Logger m_logger;
+ public static final AbstractState STARTED = new Started();

- protected State m_state = AVAILABLE;
+ public static final AbstractState STOPPED = new Stopped();

- public Controller( Component instance, Logger logger, ChangeListener
listener )
- {
- m_instance = instance;
- m_listener = listener;
- m_logger = logger;
- }
+ public static final AbstractState TERMINATED = new Terminated();
+
+ protected final Component m_instance;
+
+ protected final ChangeListener m_listener;
+
+ protected final Logger m_logger;
+
+ protected State m_state = AVAILABLE;
+
+ public Controller( Component instance, Logger logger,
+ ChangeListener listener )
+ {
+ m_instance = instance;
+ m_listener = listener;
+ m_logger = logger;
+ }

public synchronized State getState()
{
@@ -97,46 +104,74 @@
public synchronized void initialize()
{
m_logger.info( "initializing" );
- if( m_state == AVAILABLE )
+ if ( null!=m_state && m_state == AVAILABLE )
{
- m_instance.start();
- setState( STARTED );
+ setState(AVAILABLE);
}
else
{
- final String error =
- "Cannot initialize from state: " + m_state;
+ final String error = "Cannot initialize from state: " +
m_state;
throw new IllegalStateException( error );
}
m_logger.info( "initialized" );
}

+
+
+ public synchronized void terminate()
+ {
+ m_logger.info( "terminating" );
+ if ( m_state == STARTED )
+ {
+ m_instance.stop();
+ }
+ setState( TERMINATED );
+ m_logger.info( "terminated" );
+ }
+
private synchronized void setState( State state )
{
- if( m_state != state )
+ if ( m_state != state )
{
+ ( (AbstractState) m_state ).execute(m_instance);
m_state = state;
ChangeEvent event = new ChangeEvent( this );
m_listener.stateChanged( event );
}
}

- public synchronized void terminate()
+ public State apply( String iTransition ) throws Exception
{
- m_logger.info( "terminating" );
- if( m_state == STARTED )
+ // No transitions routed (yet), so nothing to do
+ // TODO: move the state logic from initialize into here
+ State next = null;
+ if ( iTransition.equals( STARTED.getName() ) )
{
- m_instance.stop();
+ next = STARTED;
}
- setState( TERMINATED );
- m_logger.info( "terminated" );
+ if ( iTransition.equals( AVAILABLE.getName() ) )
+ {
+ next = AVAILABLE;
+ }
+ if ( iTransition.equals( STOPPED.getName() ) )
+ {
+ next = STOPPED;
+ }
+ if ( iTransition.equals( TERMINATED.getName() ) )
+ {
+ next = TERMINATED;
+ }
+ if ( null != next )
+ {
+ setState( next );
+ }
+ return m_state;
}
}

- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// state transitions
- //------------------------------------------------------------------
-
+ // ------------------------------------------------------------------

private void start()
{
@@ -148,33 +183,79 @@
getLogger().info( "stopped" );
}

- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
// states
- //------------------------------------------------------------------
+ // ------------------------------------------------------------------
+
+ public static abstract class AbstractState implements State
+ {
+
+ public String getName()
+ {
+ return getClass().getName();
+ }
+
+ public abstract void execute( Component activity );

- public static class State{}
+ }
+
+ public static class Available extends AbstractState
+ {

- public static class Available extends State{}
+ public void execute( Component iActivity )
+ {
+ }
+
+ public String[] getTransitions()
+ {
+ String[] transitions = {Controller.STARTED.getName()};
+ return transitions;
+ }
+ }

- public static class Started extends Available
+ public static class Started extends AbstractState
{
- public State stop( Component activity )
+ public String[] getTransitions()
{
- activity.stop();
- return Controller.STOPPED;
+ String[] transitions = {Controller.STOPPED.getName()};
+ return transitions;
+ }
+
+ public void execute( Component iActivity )
+ {
+
+ iActivity.start();
}
}

- public static class Stopped extends Available
+ public static class Stopped extends AbstractState
{
- public State start( Component activity )
+
+ public void execute( Component iActivity )
+ {
+
+ iActivity.stop();
+
+ }
+
+ public String[] getTransitions()
{
- activity.start();
- return Controller.STARTED;
+ String[] transitions = {Controller.TERMINATED.getName()};
+ return transitions;
}
}

- public static class Terminated extends State
+ public static class Terminated extends AbstractState
{
+
+ public void execute( Component iActivity )
+ {
+ }
+
+ public String[] getTransitions()
+ {
+ // this is the end
+ return null;
+ }
}
}

Modified:
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Container.java
==============================================================================
---
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Container.java
(original)
+++
development/main/metro/composition/testing/activity/src/main/net/dpml/test/Container.java
Sun Apr 17 03:32:58 2005
@@ -21,9 +21,8 @@
import java.util.logging.Logger;

import net.dpml.activity.Executable;
-
-import net.dpml.state.StateManager;
import net.dpml.state.State;
+import net.dpml.state.StateManager;

/**
* Demonstration of a component that manages the state of a contained part.
@@ -103,8 +102,4 @@
Component selectTest();
}

- private void debug( String message )
- {
- getLogger().fine( message );
- }
}

Modified:
development/main/metro/composition/testing/activity/src/test/net/dpml/test/ComponentTestCase.java
==============================================================================
---
development/main/metro/composition/testing/activity/src/test/net/dpml/test/ComponentTestCase.java
(original)
+++
development/main/metro/composition/testing/activity/src/test/net/dpml/test/ComponentTestCase.java
Sun Apr 17 03:32:58 2005
@@ -20,63 +20,53 @@
package net.dpml.test;

import java.net.URI;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Map.Entry;
-import java.lang.reflect.Method;

import junit.framework.TestCase;
-
import net.dpml.automation.model.Model;
-import net.dpml.composition.unit.CompositionHelper;
import net.dpml.composition.models.Holder;
+import net.dpml.composition.unit.CompositionHelper;
+import net.dpml.state.State;
+import net.dpml.state.StateManager;

/**
* Test a simple component case.
- *
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Id: AbstractDescriptorTestCase.java 1556 2005-01-22 12:43:42Z
niclas $
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta
+ * Library</a>
+ * @version $Id: AbstractDescriptorTestCase.java 1556 2005-01-22 12:43:42Z
+ * niclas $
*/
public class ComponentTestCase extends TestCase
{
- /**
- * Test the construction of the example component and the invocation of
- * an operation on the example service interface.
- */
+ /**
+ * Test the construction of the example component and the invocation of
+ * the provided controller via </code>the
net.dpml.state.StateManager</code> interface
+ */
public void testManagedComponent() throws Exception
{
Holder holder = getComponentHolder();
- Component.Controller manager =
- (Component.Controller) holder.getProcessController();
+ StateManager manager = (StateManager) holder.getProcessController();
manager.initialize();
- Method[] transitions = getTransitions( manager );
- for( int i=0; i<transitions.length; i++ )
+ boolean finished = false;
+ while ( !finished )
{
- Method method = transitions[i];
- System.out.println( "# transition: " + method.getName() );
- }
- manager.terminate();
- holder.dispose();
- }

- private Method[] getTransitions( Component.Controller manager )
- {
- List list = new ArrayList();
- Method[] methods = manager.getState().getClass().getMethods();
- for( int i=0; i<methods.length; i++ )
- {
- Method method = methods[i];
- if( method.getDeclaringClass() != Object.class )
+ State currentState = manager.getState();
+ String[] transitions = currentState.getTransitions();
+ System.out.println( "current state: " + currentState.getName() );
+ if ( transitions != null && transitions.length > 0 )
+ {
+ // just always take the first transition
+ System.out.println( "# transition: " + transitions[0] );
+ currentState = manager.apply( transitions[0] );
+ }
+ else
{
- Class returnType = method.getReturnType();
- if( null != returnType )
- {
- list.add( method );
- }
+ finished = true;
}
}
- return (Method[]) list.toArray( new Method[0] );
+ manager.terminate();
+ holder.dispose();
}

Holder getComponentHolder() throws Exception
@@ -87,5 +77,3 @@
return (Holder) helper.getCompositionManager().create( model );
}
}
-
-



  • svn commit: r2299 - in development/main/metro/composition/testing/activity/src: main/net/dpml/test test/net/dpml/test, peter, 04/16/2005

Archive powered by MHonArc 2.6.24.

Top of Page