com.ctc.wstx.evt
Class DefaultEventAllocator

java.lang.Object
  extended by com.ctc.wstx.sr.ElemCallback
      extended by com.ctc.wstx.evt.DefaultEventAllocator
All Implemented Interfaces:
javax.xml.stream.util.XMLEventAllocator, javax.xml.stream.XMLStreamConstants

public class DefaultEventAllocator
extends ElemCallback
implements javax.xml.stream.util.XMLEventAllocator, javax.xml.stream.XMLStreamConstants

Straight-forward implementation of XMLEventAllocator, to be used with Woodstox' event reader.

One of few complications here is the way start elements are constructed. The pattern used is double-indirection, needed to get a callback from the stream reader, with data we need for constructing even Object... but without stream reader having any understanding of event Objects per se.

03-Dec-2004, TSa: One additional twist is that it's now possible to create slightly faster event handling, by indicating that the fully accurate Location information is not necessary. If so, allocator will just use one shared Location object passed to all event objects constructed.


Field Summary
protected  boolean mAccurateLocation
           
protected  javax.xml.stream.Location mLastLocation
          Last used location info; only relevant to non-accurate-location allocators.
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Constructor Summary
protected DefaultEventAllocator(boolean accurateLocation)
           
 
Method Summary
 javax.xml.stream.events.XMLEvent allocate(javax.xml.stream.XMLStreamReader r)
           
 void allocate(javax.xml.stream.XMLStreamReader r, javax.xml.stream.util.XMLEventConsumer consumer)
           
static DefaultEventAllocator getDefaultInstance()
           
static DefaultEventAllocator getFastInstance()
           
 javax.xml.stream.util.XMLEventAllocator newInstance()
          Default implementation assumes that the caller knows how to share instances, and so need not create new copies.
 java.lang.Object withStartElement(javax.xml.stream.Location loc, javax.xml.namespace.QName name, BaseNsContext nsCtxt, ElemAttrs attrs, boolean wasEmpty)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mAccurateLocation

protected final boolean mAccurateLocation

mLastLocation

protected javax.xml.stream.Location mLastLocation
Last used location info; only relevant to non-accurate-location allocators.

Constructor Detail

DefaultEventAllocator

protected DefaultEventAllocator(boolean accurateLocation)
Parameters:
accurateLocation - If true, allocator will construct instances that have accurate location information; if false, instances will only have some generic shared Location info. Latter option will reduce memory usage/thrashing a bit, and may improve speed.
Method Detail

getDefaultInstance

public static DefaultEventAllocator getDefaultInstance()

getFastInstance

public static DefaultEventAllocator getFastInstance()

allocate

public javax.xml.stream.events.XMLEvent allocate(javax.xml.stream.XMLStreamReader r)
                                          throws javax.xml.stream.XMLStreamException
Specified by:
allocate in interface javax.xml.stream.util.XMLEventAllocator
Throws:
javax.xml.stream.XMLStreamException

allocate

public void allocate(javax.xml.stream.XMLStreamReader r,
                     javax.xml.stream.util.XMLEventConsumer consumer)
              throws javax.xml.stream.XMLStreamException
Specified by:
allocate in interface javax.xml.stream.util.XMLEventAllocator
Throws:
javax.xml.stream.XMLStreamException

newInstance

public javax.xml.stream.util.XMLEventAllocator newInstance()
Default implementation assumes that the caller knows how to share instances, and so need not create new copies.

Note: if this class is sub-classes, this method should be redefined if assumptions about shareability do not hold.

Specified by:
newInstance in interface javax.xml.stream.util.XMLEventAllocator

withStartElement

public java.lang.Object withStartElement(javax.xml.stream.Location loc,
                                         javax.xml.namespace.QName name,
                                         BaseNsContext nsCtxt,
                                         ElemAttrs attrs,
                                         boolean wasEmpty)
Specified by:
withStartElement in class ElemCallback