Trull

edu.luc.cs.trull
Class Switch

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.Switch
All Implemented Interfaces:
Combinator, Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener
Direct Known Subclasses:
If

public class Switch
extends AbstractCombinator

A data-driven selection mechanism that immediately evaluates its valuator (criterium) and chooses the corresponding branch. The resulting component terminates when the chosen branch terminates.


Nested Class Summary
protected  class Switch.LocalListener
          A dedicated listener that forwards the event to all external listeners.
protected  class Switch.SwitchTerminationListener
          This component terminates as soon as the chosen branch component terminates.
 
Nested classes/interfaces inherited from class edu.luc.cs.trull.AbstractCombinator
AbstractCombinator.DefaultTerminationListener
 
Field Summary
private  int currentComponentIndex
          The index of the chosen branch.
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 for this component.
private  EventValuator valuator
          The valuator (criterium) for this switch.
 
Fields inherited from class edu.luc.cs.trull.AbstractCombinator
components
 
Constructor Summary
Switch()
          Constructs a Switch component.
Switch(EventValuator valuator, Component[] components)
          Constructs a Switch component.
 
Method Summary
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()
          The chosen branch comopnent.
 EventValuator getValuator()
          Returns the criterium used by this Switch.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          This method forwards events received from external sources to the components of this combinator.
 void removeComponent(Component c)
          Removes the specified component from this combinator.
 void resume()
          Resumes this suspendable component.
 void setValuator(EventValuator valuator)
          Sets the criterium of this Switch to the given valuator.
 void start(java.beans.PropertyChangeEvent incoming)
          Starts this startable component.
 void stop()
          Stops this startable component.
 void suspend()
          Suspends this suspendable component.
protected  void switchToComponent(int choice)
          Switches to the branch component with the given index.
 
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 chosen branch.


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 for this component.


valuator

private EventValuator valuator
The valuator (criterium) for this switch.

Constructor Detail

Switch

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


Switch

public Switch(EventValuator valuator,
              Component[] components)
Constructs a Switch component.

Parameters:
valuator - the criterium used to choose a branch.
components - the array of branch components.
Method Detail

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()
The chosen branch comopnent.

Returns:
the chosen branch comopnent.

getValuator

public EventValuator getValuator()
Returns the criterium used by this Switch.

Returns:
the valuator used as the criterium.

propertyChange

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

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

setValuator

public void setValuator(EventValuator valuator)
Sets the criterium of this Switch to the given valuator.

Parameters:
valuator - the valuator to be used as the criterium.

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

switchToComponent

protected void switchToComponent(int choice)
Switches to the branch component with the given index.

Parameters:
choice - the index of the branch.

Trull

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