Trull

edu.luc.cs.trull
Class Sequence

java.lang.Object
  extended by edu.luc.cs.trull.EmptyComponent
      extended by edu.luc.cs.trull.TerminatingComponent
          extended by edu.luc.cs.trull.AbstractComponent
              extended by edu.luc.cs.trull.AbstractCombinator
                  extended by edu.luc.cs.trull.Sequence
All Implemented Interfaces:
Combinator, Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener

public class Sequence
extends AbstractCombinator

A combinator for executing zero or more components in sequence. The components that form part of the sequence should indicate termination. A sequence terminates when its last component terminates.


Nested Class Summary
protected  class Sequence.ForwardListener
          A dedicated listener that forwards the event to all external listeners.
protected  class Sequence.SequenceTerminationListener
          A termination listener that, when the current component terminates, starts the next component in the sequence.
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.AbstractCombinator
AbstractCombinator.DefaultTerminationListener
 
Field Summary
private  int currentComponentIndex
          The index of the currently active component.
private  Done DONE
          An instance of Done used as the default child.
private  java.beans.PropertyChangeListener internalListener
          An internal listener that listens to the currently active child branch of this component and forwards events to the external listeners.
private static org.apache.log4j.Logger logger
           
private  TerminationListener terminationListener
          The child termination listener of this component.
 
Fields inherited from class edu.luc.cs.trull.AbstractCombinator
components
 
Constructor Summary
Sequence()
          Constructs a Sequence component.
Sequence(Component[] components)
          Constructs a Sequence component consisting of the given list of components.
Sequence(Component first, Component second)
          Constructs a Sequence component consisting of the two given components in order.
 
Method Summary
protected  void connectComponent(Component c)
          Hooks up the given component for communication and termination.
protected  void disconnectComponent(Component c)
          Unhooks the given component from communication and termination.
protected  TerminationListener getChildTerminationListener()
          Returns the internal listener that is notified if the child component terminates.
protected  Component getCurrentComponent()
          Returns the currently active component.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          This method forwards events received from external sources to the components of this composite.
 void removeComponent(Component c)
          Removes the specified component from this combinator.
 void resume()
          Resumes this suspendable component.
 void start(java.beans.PropertyChangeEvent incoming)
          Starts this startable component.
 void stop()
          Stops this startable component.
 void suspend()
          Suspends this suspendable component.
protected  void switchToFirstComponent()
          Switches to the first component in the sequence.
protected  void switchToNextComponent()
          Switches to the next component in the sequence.
 
Methods inherited from class edu.luc.cs.trull.AbstractCombinator
addComponent, addComponent, addComponent, getComponent, getComponentCount, getComponents, removeAllComponents, removeComponent
 
Methods inherited from class edu.luc.cs.trull.AbstractComponent
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getExternalListeners, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from class edu.luc.cs.trull.TerminatingComponent
fireTermination, getParent, getTermEvent, scheduleTermination, setTerminationListener
 
Methods inherited from class edu.luc.cs.trull.EmptyComponent
getTerminationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.luc.cs.trull.PropertyChangeSource
addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener
 
Methods inherited from interface edu.luc.cs.trull.Terminating
getTerminationListener, setTerminationListener
 

Field Detail

currentComponentIndex

private int currentComponentIndex
The index of the currently active component.


DONE

private final Done DONE
An instance of Done used as the default child.


internalListener

private java.beans.PropertyChangeListener internalListener
An internal listener that listens to the currently active child branch of this component and forwards events to the external listeners.


logger

private static final org.apache.log4j.Logger logger

terminationListener

private TerminationListener terminationListener
The child termination listener of this component.

Constructor Detail

Sequence

public Sequence()
Constructs a Sequence component. Specific properties can be changed later.


Sequence

public Sequence(Component[] components)
Constructs a Sequence component consisting of the given list of components.

Parameters:
components - the list of components in the sequence.

Sequence

public Sequence(Component first,
                Component second)
Constructs a Sequence component consisting of the two given components in order.

Parameters:
first - the first component in the sequence.
second - the second component in the sequence.
Method Detail

connectComponent

protected void connectComponent(Component c)
Hooks up the given component for communication and termination.

Parameters:
c - the component to be hooked up.

disconnectComponent

protected void disconnectComponent(Component c)
Unhooks the given component from communication and termination.

Parameters:
c - the component to be unhooked.

getChildTerminationListener

protected TerminationListener getChildTerminationListener()
Description copied from class: AbstractCombinator
Returns the internal listener that is notified if the child component terminates.

Specified by:
getChildTerminationListener in class AbstractCombinator
Returns:
the termination listener.

getCurrentComponent

protected Component getCurrentComponent()
Returns the currently active component.

Returns:
the currently active component.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
This method forwards events received from external sources to the components of this composite.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class EmptyComponent
Parameters:
evt - the event received.

removeComponent

public void removeComponent(Component c)
Description copied from class: AbstractCombinator
Removes the specified component from this combinator.

Specified by:
removeComponent in interface Combinator
Overrides:
removeComponent in class AbstractCombinator
Parameters:
c - the component to be removed.

resume

public void resume()
Description copied from interface: Suspendable
Resumes this suspendable component.

Specified by:
resume in interface Suspendable
Overrides:
resume in class EmptyComponent

start

public void start(java.beans.PropertyChangeEvent incoming)
Description copied from interface: Startable
Starts this startable component.

Specified by:
start in interface Startable
Overrides:
start in class EmptyComponent
Parameters:
incoming - the event that triggered the invocation of this method. May be null.

stop

public void stop()
Description copied from interface: Startable
Stops this startable component.

Specified by:
stop in interface Startable
Overrides:
stop in class EmptyComponent

suspend

public void suspend()
Description copied from interface: Suspendable
Suspends this suspendable component.

Specified by:
suspend in interface Suspendable
Overrides:
suspend in class EmptyComponent

switchToFirstComponent

protected void switchToFirstComponent()
Switches to the first component in the sequence.


switchToNextComponent

protected void switchToNextComponent()
Switches to the next component in the sequence.


Trull

http://www.cs.luc.edu/trull/