Copyright (C) 2003,2004 dr. Cristiano Sadun

org.sadun.text.ffp
Class DispatcherListener

java.lang.Object
  extended byorg.sadun.text.ffp.DispatcherListener
All Implemented Interfaces:
FlatFileParser.Listener

public class DispatcherListener
extends java.lang.Object
implements FlatFileParser.Listener

A dispatcher that allows to have different listeners receiving parsing events from a FlatFileParser depending on the line format which matched the line, instead of one monolithic one receiving all parsing events.

It's useful when the flat file contains more than a few different formats - avoiding to have a big switch statement (or multiple if s) to do something different depending on which line format has actually matched a line.

Version:
1.0
Author:
Cristiano Sadun

Constructor Summary
DispatcherListener()
          Create a dispatcher listener which does not require that all events are associated to a listener (see DispatcherListener(boolean) ).
DispatcherListener(boolean allowLostEvents)
          Create a dispatcher listener, with no other listeners associated.
 
Method Summary
 void associateListener(LineFormat format, FlatFileParser.Listener listener)
           
 boolean isAllowLostEvents()
          If true, the dispatcher allows parsing events which are not associated to any listener to be ignored; otherwise, events which are not associated to any listener will raise a NoAssociatedListenerException .
 void lineParsed(LineFormat format, int logicalLinecount, int physicalLineCount, java.lang.String[] values)
          Receive a parsing event and invoke the associated listener, if any.
 void setAllowLostEvents(boolean allowLostEvents)
          Set whether or not true, the dispatcher allows parsing events which are not associated to any listener to be ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatcherListener

public DispatcherListener(boolean allowLostEvents)
Create a dispatcher listener, with no other listeners associated. If allowLostEvents is false, the listener will require that every event be associated to a listener. Otherwise, events which aren't associated to any listener will simply be ignored. Use one associateListener(LineFormat, FlatFileParser.Listener) overload to associate a listener to a specific condition or line format.

Parameters:
allowLostEvents - if true, the listener will not require that all events are associated to a listener.

DispatcherListener

public DispatcherListener()
Create a dispatcher listener which does not require that all events are associated to a listener (see DispatcherListener(boolean) ).

Method Detail

lineParsed

public final void lineParsed(LineFormat format,
                             int logicalLinecount,
                             int physicalLineCount,
                             java.lang.String[] values)
                      throws AbortFFPException
Receive a parsing event and invoke the associated listener, if any.

Specified by:
lineParsed in interface FlatFileParser.Listener
Parameters:
format - the LineFormat object which has executed the parsing
values - the values resulting from the parsing
Throws:
AbortFFPException
See Also:
FlatFileParser.Listener.lineParsed(org.sadun.text.ffp.LineFormat, int, int, java.lang.String[])

associateListener

public void associateListener(LineFormat format,
                              FlatFileParser.Listener listener)

isAllowLostEvents

public boolean isAllowLostEvents()
If true, the dispatcher allows parsing events which are not associated to any listener to be ignored; otherwise, events which are not associated to any listener will raise a NoAssociatedListenerException .

Returns:
Return whether or not the dispatcher allows parsing events which are not associated to any listener to be ignored.

setAllowLostEvents

public void setAllowLostEvents(boolean allowLostEvents)
Set whether or not true, the dispatcher allows parsing events which are not associated to any listener to be ignored. If not, events which are not associated to any listener will raise a NoAssociatedListenerException .

Parameters:
allowLostEvents - Set whether or not the dispatcher allows parsing events which are not associated to any listener to be ignored.

Copyright (C) 2003,2004 dr. Cristiano Sadun