org.apache.cocoon.stax
Class AbstractStAXTransformer

java.lang.Object
  extended by org.apache.cocoon.pipeline.component.AbstractPipelineComponent
      extended by org.apache.cocoon.stax.AbstractStAXPipelineComponent
          extended by org.apache.cocoon.stax.AbstractStAXProducer
              extended by org.apache.cocoon.stax.AbstractStAXTransformer
All Implemented Interfaces:
Consumer, PipelineComponent, Producer, StAXConsumer, StAXPipelineComponent, StAXProducer
Direct Known Subclasses:
CleaningTransformer, IncludeTransformer, SAXForStAXPipelineWrapper

public abstract class AbstractStAXTransformer
extends AbstractStAXProducer
implements StAXConsumer

Abstract transformer could/should be used for each StAXTransformer. This class implements the default behavior of the StAXConsumer and the StAXConsumer interfaces. Further more the AbstractStAXTransformer contains the queuing for StAX-events. This transformer abstracts the entire handling of nextEvent() and peek() behind a template method produceEvents() which saves all produced events in a buffer and handles peek(), nextEvent() and hasNext().


Constructor Summary
AbstractStAXTransformer()
           
 
Method Summary
protected  void addAllEventsToQueue(Collection<? extends XMLEvent> events)
          Adds a Collection of XMLEvents to an internal Queue.
protected  void addEventToQueue(XMLEvent event)
          Add a specific XMLEvent to an internal Queue.
protected  StAXProducer getParent()
          This StAXProducer is the parent of the module overwriting this AbstractStAXTransformer.
 boolean hasNext()
          Check if there are more events.
 void initiatePullProcessing()
          Since the workflow in a pull pipeline is completely inverted compared to for example a SAX pipeline, this method is required to push the Starter.execute() to the Finisher which should start processing.
protected  boolean isQueueEmpty()
          Checks and returns if the internal Queue of XMLEvents is empty.
 XMLEvent nextEvent()
          Get the next XMLEvent
 XMLEvent peek()
          Check the next XMLEvent without reading it from the stream.
protected abstract  void produceEvents()
          Template method which has to produce at least one XMLEvent and should add this to the internal Queue with the #add(XMLEvent) and #addAll(Collection) methods.
 void setParent(StAXProducer parent)
          Used to connect a consumer to it's producer.
 
Methods inherited from class org.apache.cocoon.stax.AbstractStAXProducer
getConsumer, setConsumer
 
Methods inherited from class org.apache.cocoon.pipeline.component.AbstractPipelineComponent
finish, setConfiguration, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.pipeline.component.PipelineComponent
finish, setConfiguration, setup
 

Constructor Detail

AbstractStAXTransformer

public AbstractStAXTransformer()
Method Detail

initiatePullProcessing

public final void initiatePullProcessing()
Since the workflow in a pull pipeline is completely inverted compared to for example a SAX pipeline, this method is required to push the Starter.execute() to the Finisher which should start processing.

Specified by:
initiatePullProcessing in interface StAXConsumer
See Also:
StAXConsumer.initiatePullProcessing()

setParent

public final void setParent(StAXProducer parent)
Used to connect a consumer to it's producer. As to the nature of the control inversion and pulling it is required to specify a parent, which provides the consumer with events to consume. This function is called when the pipeline sets it's consumers.

Specified by:
setParent in interface StAXConsumer
See Also:
StAXConsumer.setParent(StAXProducer)

hasNext

public final boolean hasNext()
                      throws XMLStreamException
Check if there are more events. Returns true if there are more events and false otherwise.

Specified by:
hasNext in interface StAXProducer
Returns:
true if the event reader has more events, false otherwise
Throws:
XMLStreamException - Error which could occure during producing events.
See Also:
StAXProducer.hasNext()

nextEvent

public final XMLEvent nextEvent()
Get the next XMLEvent

Specified by:
nextEvent in interface StAXProducer
See Also:
StAXProducer.nextEvent()

peek

public final XMLEvent peek()
Check the next XMLEvent without reading it from the stream. Returns null if the stream is at EOF or has no more XMLEvents. A call to peek() will be equal to the next return of next().

Specified by:
peek in interface StAXProducer
See Also:
StAXProducer.peek()

addEventToQueue

protected final void addEventToQueue(XMLEvent event)
Add a specific XMLEvent to an internal Queue.

Parameters:
event - which should be added to the queue.

getParent

protected final StAXProducer getParent()
This StAXProducer is the parent of the module overwriting this AbstractStAXTransformer. It could be used in the produceEvents() method to pull events from the parent or ask if it still has some.


addAllEventsToQueue

protected final void addAllEventsToQueue(Collection<? extends XMLEvent> events)
Adds a Collection of XMLEvents to an internal Queue.

Parameters:
events - are a Collection of XMLEvents which should be added to an internal Queue.

isQueueEmpty

protected final boolean isQueueEmpty()
Checks and returns if the internal Queue of XMLEvents is empty.

Returns:
checks and returns if the internal Queue of XMLEvents is empty.

produceEvents

protected abstract void produceEvents()
                               throws XMLStreamException
Template method which has to produce at least one XMLEvent and should add this to the internal Queue with the #add(XMLEvent) and #addAll(Collection) methods. If no XMLEvent is added by this method to the internal Queue an exception is thrown.

Throws:
XMLStreamException - thrown if the StAXProducer.nextEvent() or the StAXProducer.peek() method, called in the produceEvents() method throw any exceptions they have to be forwarded to the end of the pipeline.


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.