org.cyberneko.pull.util
Class EventCollector

java.lang.Object
  extended byorg.cyberneko.pull.util.EventQueue
      extended byorg.cyberneko.pull.util.EventCollector
All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.XMLDocumentHandler

public class EventCollector
extends EventQueue
implements org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.XMLDocumentHandler

This class converts XNI document handler callbacks into pull parser event objects, storing them on an event queue. In order to work with any kind of XNI generator, the data passed via the XNI callbacks is buffered internally when converted to event objects. Therefore, this class is for general use and is not intended for high performance pull parsing. For better performance, a parser written directly to the pull parser API should be used.

Note: There is a performance hit to buffering the underlying XNI events. While the difference is negligible for small documents, it becomes more pronounced as the document size increases.

Version:
$Id: EventCollector.java,v 1.6 2003/06/25 19:00:27 andyc Exp $
Author:
Andy Clark
See Also:
EventDispatcher

Field Summary
protected  org.apache.xerces.xni.parser.XMLDocumentSource fDocumentSource
          XNI document source.
protected static java.lang.Boolean[] FEATURE_DEFAULTS
          Feature defaults.
protected  XMLEvent[] fEventCache
          Event cache.
protected  XMLEvent fLastEvent
          The last event.
protected  org.apache.xerces.xni.NamespaceContext fNamespaceContext
          Namespace context.
protected  boolean fReuseBuffers
          Underlying buffers are re-used by the creator of the XNI events.
protected static java.lang.String[] RECOGNIZED_FEATURES
          Recognized features.
protected static java.lang.String REUSE_BUFFERS
          Feature identifer: reuse buffers.
 
Fields inherited from class org.cyberneko.pull.util.EventQueue
fHead, fSize, fTail
 
Constructor Summary
EventCollector()
           
 
Method Summary
protected  void attrs(org.apache.xerces.xni.XMLAttributes src, org.apache.xerces.xni.XMLAttributes dest)
          Copies the source attributes into the specified destination.
protected  org.apache.xerces.xni.Augmentations augs(org.apache.xerces.xni.Augmentations augs)
          Returns a copy of the specified args.
 void characters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
          Character content.
 void comment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
          A comment.
 XMLEvent dequeue()
          Removes an event from the queue.
 void doctypeDecl(java.lang.String rootElement, java.lang.String publicId, java.lang.String systemId, org.apache.xerces.xni.Augmentations augs)
          Notifies of the presence of the DOCTYPE line in the document.
protected  void dropEvent(XMLEvent event)
          Drops an event by putting it back on the event cache so that it can be re-used when needed.
 void emptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
          An empty element.
 void endCDATA(org.apache.xerces.xni.Augmentations augs)
          The end of a CDATA section.
 void endDocument(org.apache.xerces.xni.Augmentations augs)
          The end of the document.
 void endElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs)
          The end of an element.
 void endGeneralEntity(java.lang.String name, org.apache.xerces.xni.Augmentations augs)
          This method notifies the end of a general entity.
 void endPrefixMapping(java.lang.String prefix, org.apache.xerces.xni.Augmentations augs)
          The end of a namespace prefix mapping.
 org.apache.xerces.xni.parser.XMLDocumentSource getDocumentSource()
          Returns the document source.
protected  XMLEvent getEvent(short type)
          Returns an event object for the given type.
 java.lang.Boolean getFeatureDefault(java.lang.String featureId)
          Returns feature default.
 java.lang.Object getPropertyDefault(java.lang.String propertyId)
          Returns property default.
 java.lang.String[] getRecognizedFeatures()
          Returns recognized features.
 java.lang.String[] getRecognizedProperties()
          Returns recognized properties.
protected  void handleEndElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs, boolean empty)
          Handles an end element by copying the necessary data.
protected  void handleStartElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs, boolean empty)
          Handles a start element by copying the necessary data.
 void ignorableWhitespace(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)
          Ignorable whitespace.
 void processingInstruction(java.lang.String target, org.apache.xerces.xni.XMLString data, org.apache.xerces.xni.Augmentations augs)
          A processing instruction.
 void reset(org.apache.xerces.xni.parser.XMLComponentManager manager)
          Reset.
 void setDocumentSource(org.apache.xerces.xni.parser.XMLDocumentSource source)
          Sets the document source.
 void setFeature(java.lang.String featureId, boolean state)
          Set feature.
 void setProperty(java.lang.String propertyId, java.lang.Object value)
          Set property.
 void startCDATA(org.apache.xerces.xni.Augmentations augs)
          The start of a CDATA section.
 void startDocument(org.apache.xerces.xni.XMLLocator locator, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
          The start of the document.
 void startDocument(org.apache.xerces.xni.XMLLocator locator, java.lang.String encoding, org.apache.xerces.xni.NamespaceContext nscontext, org.apache.xerces.xni.Augmentations augs)
          Start document.
 void startElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)
          The start of an element.
 void startGeneralEntity(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
          This method notifies the start of a general entity.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri, org.apache.xerces.xni.Augmentations augs)
          The start of a namespace prefix mapping.
protected  org.apache.xerces.xni.XMLString string(org.apache.xerces.xni.XMLString text, boolean content)
          Returns a copy of the specified string.
 void textDecl(java.lang.String version, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)
          Notifies of the presence of a TextDecl line in an entity.
 void xmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, org.apache.xerces.xni.Augmentations augs)
          Notifies of the presence of an XMLDecl line in the document.
 
Methods inherited from class org.cyberneko.pull.util.EventQueue
clear, enqueue, isEmpty, size, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REUSE_BUFFERS

protected static final java.lang.String REUSE_BUFFERS
Feature identifer: reuse buffers.

Note: This capability is not yet implemented in the Xerces2 parser. Therefore, this feature identifier is a placeholder for future capability to improve performance of a pull parser impl built on top of Xerces2.

See Also:
Constant Field Values

RECOGNIZED_FEATURES

protected static final java.lang.String[] RECOGNIZED_FEATURES
Recognized features.


FEATURE_DEFAULTS

protected static final java.lang.Boolean[] FEATURE_DEFAULTS
Feature defaults.


fEventCache

protected XMLEvent[] fEventCache
Event cache.


fLastEvent

protected XMLEvent fLastEvent
The last event.


fReuseBuffers

protected boolean fReuseBuffers
Underlying buffers are re-used by the creator of the XNI events.


fDocumentSource

protected org.apache.xerces.xni.parser.XMLDocumentSource fDocumentSource
XNI document source.


fNamespaceContext

protected org.apache.xerces.xni.NamespaceContext fNamespaceContext
Namespace context.

Constructor Detail

EventCollector

public EventCollector()
Method Detail

dequeue

public XMLEvent dequeue()
Removes an event from the queue.

Overrides:
dequeue in class EventQueue

reset

public void reset(org.apache.xerces.xni.parser.XMLComponentManager manager)
           throws org.apache.xerces.xni.parser.XMLConfigurationException
Reset.

Specified by:
reset in interface org.apache.xerces.xni.parser.XMLComponent
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException

getRecognizedFeatures

public java.lang.String[] getRecognizedFeatures()
Returns recognized features.

Specified by:
getRecognizedFeatures in interface org.apache.xerces.xni.parser.XMLComponent

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws org.apache.xerces.xni.parser.XMLConfigurationException
Set feature.

Specified by:
setFeature in interface org.apache.xerces.xni.parser.XMLComponent
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException

getRecognizedProperties

public java.lang.String[] getRecognizedProperties()
Returns recognized properties.

Specified by:
getRecognizedProperties in interface org.apache.xerces.xni.parser.XMLComponent

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object value)
                 throws org.apache.xerces.xni.parser.XMLConfigurationException
Set property.

Specified by:
setProperty in interface org.apache.xerces.xni.parser.XMLComponent
Throws:
org.apache.xerces.xni.parser.XMLConfigurationException

getFeatureDefault

public java.lang.Boolean getFeatureDefault(java.lang.String featureId)
Returns feature default.

Specified by:
getFeatureDefault in interface org.apache.xerces.xni.parser.XMLComponent

getPropertyDefault

public java.lang.Object getPropertyDefault(java.lang.String propertyId)
Returns property default.

Specified by:
getPropertyDefault in interface org.apache.xerces.xni.parser.XMLComponent

startDocument

public void startDocument(org.apache.xerces.xni.XMLLocator locator,
                          java.lang.String encoding,
                          org.apache.xerces.xni.NamespaceContext nscontext,
                          org.apache.xerces.xni.Augmentations augs)
                   throws org.apache.xerces.xni.XNIException
Start document.

Specified by:
startDocument in interface org.apache.xerces.xni.XMLDocumentHandler
Throws:
org.apache.xerces.xni.XNIException

startDocument

public void startDocument(org.apache.xerces.xni.XMLLocator locator,
                          java.lang.String encoding,
                          org.apache.xerces.xni.Augmentations augs)
                   throws org.apache.xerces.xni.XNIException
The start of the document.

Parameters:
locator - The document locator, or null if the document location cannot be reported during the parsing of this document. However, it is strongly recommended that a locator be supplied that can at least report the system identifier of the document.
encoding - The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

xmlDecl

public void xmlDecl(java.lang.String version,
                    java.lang.String encoding,
                    java.lang.String standalone,
                    org.apache.xerces.xni.Augmentations augs)
             throws org.apache.xerces.xni.XNIException
Notifies of the presence of an XMLDecl line in the document. If present, this method will be called immediately following the startDocument call.

Specified by:
xmlDecl in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
version - The XML version.
encoding - The IANA encoding name of the document, or null if not specified.
standalone - The standalone value, or null if not specified.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

doctypeDecl

public void doctypeDecl(java.lang.String rootElement,
                        java.lang.String publicId,
                        java.lang.String systemId,
                        org.apache.xerces.xni.Augmentations augs)
                 throws org.apache.xerces.xni.XNIException
Notifies of the presence of the DOCTYPE line in the document.

Specified by:
doctypeDecl in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
rootElement - The name of the root element.
publicId - The public identifier if an external DTD or null if the external DTD is specified using SYSTEM.
systemId - The system identifier if an external DTD, null otherwise.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

comment

public void comment(org.apache.xerces.xni.XMLString text,
                    org.apache.xerces.xni.Augmentations augs)
             throws org.apache.xerces.xni.XNIException
A comment.

Specified by:
comment in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
text - The text in the comment.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by application to signal an error.

processingInstruction

public void processingInstruction(java.lang.String target,
                                  org.apache.xerces.xni.XMLString data,
                                  org.apache.xerces.xni.Augmentations augs)
                           throws org.apache.xerces.xni.XNIException
A processing instruction. Processing instructions consist of a target name and, optionally, text data. The data is only meaningful to the application.

Typically, a processing instruction's data will contain a series of pseudo-attributes. These pseudo-attributes follow the form of element attributes but are not parsed or presented to the application as anything other than text. The application is responsible for parsing the data.

Specified by:
processingInstruction in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
target - The target.
data - The data or null if none specified.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri,
                               org.apache.xerces.xni.Augmentations augs)
                        throws org.apache.xerces.xni.XNIException
The start of a namespace prefix mapping. This method will only be called when namespace processing is enabled.

Parameters:
prefix - The namespace prefix.
uri - The URI bound to the prefix.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

startElement

public void startElement(org.apache.xerces.xni.QName element,
                         org.apache.xerces.xni.XMLAttributes attributes,
                         org.apache.xerces.xni.Augmentations augs)
                  throws org.apache.xerces.xni.XNIException
The start of an element.

Specified by:
startElement in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
element - The name of the element.
attributes - The element attributes.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

emptyElement

public void emptyElement(org.apache.xerces.xni.QName element,
                         org.apache.xerces.xni.XMLAttributes attributes,
                         org.apache.xerces.xni.Augmentations augs)
                  throws org.apache.xerces.xni.XNIException
An empty element.

Specified by:
emptyElement in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
element - The name of the element.
attributes - The element attributes.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

startGeneralEntity

public void startGeneralEntity(java.lang.String name,
                               org.apache.xerces.xni.XMLResourceIdentifier identifier,
                               java.lang.String encoding,
                               org.apache.xerces.xni.Augmentations augs)
                        throws org.apache.xerces.xni.XNIException
This method notifies the start of a general entity.

Note: This method is not called for entity references appearing as part of attribute values.

Specified by:
startGeneralEntity in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
name - The name of the general entity.
identifier - The resource identifier.
encoding - The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

textDecl

public void textDecl(java.lang.String version,
                     java.lang.String encoding,
                     org.apache.xerces.xni.Augmentations augs)
              throws org.apache.xerces.xni.XNIException
Notifies of the presence of a TextDecl line in an entity. If present, this method will be called immediately following the startEntity call.

Note: This method will never be called for the document entity; it is only called for external general entities referenced in document content.

Note: This method is not called for entity references appearing as part of attribute values.

Specified by:
textDecl in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
version - The XML version, or null if not specified.
encoding - The IANA encoding name of the entity.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

endGeneralEntity

public void endGeneralEntity(java.lang.String name,
                             org.apache.xerces.xni.Augmentations augs)
                      throws org.apache.xerces.xni.XNIException
This method notifies the end of a general entity.

Note: This method is not called for entity references appearing as part of attribute values.

Specified by:
endGeneralEntity in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
name - The name of the entity.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

characters

public void characters(org.apache.xerces.xni.XMLString text,
                       org.apache.xerces.xni.Augmentations augs)
                throws org.apache.xerces.xni.XNIException
Character content.

Specified by:
characters in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
text - The content.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

ignorableWhitespace

public void ignorableWhitespace(org.apache.xerces.xni.XMLString text,
                                org.apache.xerces.xni.Augmentations augs)
                         throws org.apache.xerces.xni.XNIException
Ignorable whitespace. For this method to be called, the document source must have some way of determining that the text containing only whitespace characters should be considered ignorable. For example, the validator can determine if a length of whitespace characters in the document are ignorable based on the element content model.

Specified by:
ignorableWhitespace in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
text - The ignorable whitespace.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

endElement

public void endElement(org.apache.xerces.xni.QName element,
                       org.apache.xerces.xni.Augmentations augs)
                throws org.apache.xerces.xni.XNIException
The end of an element.

Specified by:
endElement in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
element - The name of the element.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix,
                             org.apache.xerces.xni.Augmentations augs)
                      throws org.apache.xerces.xni.XNIException
The end of a namespace prefix mapping. This method will only be called when namespace processing is enabled.

Parameters:
prefix - The namespace prefix.
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

startCDATA

public void startCDATA(org.apache.xerces.xni.Augmentations augs)
                throws org.apache.xerces.xni.XNIException
The start of a CDATA section.

Specified by:
startCDATA in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

endCDATA

public void endCDATA(org.apache.xerces.xni.Augmentations augs)
              throws org.apache.xerces.xni.XNIException
The end of a CDATA section.

Specified by:
endCDATA in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

endDocument

public void endDocument(org.apache.xerces.xni.Augmentations augs)
                 throws org.apache.xerces.xni.XNIException
The end of the document.

Specified by:
endDocument in interface org.apache.xerces.xni.XMLDocumentHandler
Parameters:
augs - Additional information that may include infoset augmentations
Throws:
org.apache.xerces.xni.XNIException - Thrown by handler to signal an error.

setDocumentSource

public void setDocumentSource(org.apache.xerces.xni.parser.XMLDocumentSource source)
Sets the document source.

Specified by:
setDocumentSource in interface org.apache.xerces.xni.XMLDocumentHandler

getDocumentSource

public org.apache.xerces.xni.parser.XMLDocumentSource getDocumentSource()
Returns the document source.

Specified by:
getDocumentSource in interface org.apache.xerces.xni.XMLDocumentHandler

handleStartElement

protected void handleStartElement(org.apache.xerces.xni.QName element,
                                  org.apache.xerces.xni.XMLAttributes attributes,
                                  org.apache.xerces.xni.Augmentations augs,
                                  boolean empty)
Handles a start element by copying the necessary data.


handleEndElement

protected void handleEndElement(org.apache.xerces.xni.QName element,
                                org.apache.xerces.xni.Augmentations augs,
                                boolean empty)
Handles an end element by copying the necessary data.


augs

protected org.apache.xerces.xni.Augmentations augs(org.apache.xerces.xni.Augmentations augs)
Returns a copy of the specified args.


attrs

protected void attrs(org.apache.xerces.xni.XMLAttributes src,
                     org.apache.xerces.xni.XMLAttributes dest)
Copies the source attributes into the specified destination.


string

protected org.apache.xerces.xni.XMLString string(org.apache.xerces.xni.XMLString text,
                                                 boolean content)
Returns a copy of the specified string.


getEvent

protected XMLEvent getEvent(short type)
Returns an event object for the given type. If an un-used event object of this type is on the event cache, it is returned. Otherwise, a new event object is created.


dropEvent

protected void dropEvent(XMLEvent event)
Drops an event by putting it back on the event cache so that it can be re-used when needed.



(C) Copyright 2002-2004, Andy Clark. All rights reserved.