Top Description Fields Constructors Methods
com.ctc.wstx.evt

public Class DefaultEventAllocator

extends ElemCallback
implements XMLEventAllocator, XMLStreamConstants
Class Inheritance
All Implemented Interfaces
javax.xml.stream.XMLStreamConstants, javax.xml.stream.util.XMLEventAllocator
Imports
java.util.*, javax.xml.namespace.QName, .NamespaceContext, javax.xml.stream.*, javax.xml.stream.events.Attribute, .Namespace, .XMLEvent, javax.xml.stream.util.XMLEventAllocator, .XMLEventConsumer, org.codehaus.stax2.*, org.codehaus.stax2.ri.evt.*, com.ctc.wstx.cfg.ErrorConsts, com.ctc.wstx.dtd.DTDSubset, com.ctc.wstx.ent.EntityDecl, com.ctc.wstx.exc.WstxException, com.ctc.wstx.sr.ElemAttrs, .ElemCallback, .StreamReaderImpl, com.ctc.wstx.util.BaseNsContext

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

Modifier and TypeField and Description
protected final boolean
protected Location
mLastLocation

Last used location info; only relevant to non-accurate-location allocators.

pack-priv static final DefaultEventAllocator

Constructor Summary

AccessConstructor and Description
protected
DefaultEventAllocator(boolean
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.
accurateLocation
)

Method Summary

Modifier and TypeMethod and Description
public XMLEvent
allocate(XMLStreamReader
The XMLStreamReader to allocate from
r
)

Implements javax.xml.stream.util.XMLEventAllocator.allocate.

This method allocates an event given the current state of the XMLStreamReader.

public void
allocate(XMLStreamReader
The XMLStreamReader to allocate from
r
,
XMLEventConsumer
The XMLEventConsumer to add to.
consumer
)

Implements javax.xml.stream.util.XMLEventAllocator.allocate.

This method allocates an event or set of events given the current state of the XMLStreamReader and adds the event or set of events to the consumer that was passed in. This method can be used to expand or contract reader states into event states.

public static DefaultEventAllocator
public static DefaultEventAllocator
public XMLEventAllocator
newInstance()

Implements javax.xml.stream.util.XMLEventAllocator.newInstance.

This method creates an instance of the XMLEventAllocator.

public Object
withStartElement(Location loc, QName name, BaseNsContext nsCtxt, ElemAttrs attrs, boolean wasEmpty)

Implements abstract com.ctc.wstx.sr.ElemCallback.withStartElement.

Field Detail

mAccurateLocationback to summary
protected final boolean mAccurateLocation
mLastLocationback to summary
protected Location mLastLocation

Last used location info; only relevant to non-accurate-location allocators.

sStdInstanceback to summary
pack-priv static final DefaultEventAllocator sStdInstance

Constructor Detail

DefaultEventAllocatorback to summary
protected DefaultEventAllocator(boolean accurateLocation)
Parameters
accurateLocation:boolean

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

allocateback to summary
public XMLEvent allocate(XMLStreamReader r) throws XMLStreamException

Implements javax.xml.stream.util.XMLEventAllocator.allocate.

Doc from javax.xml.stream.util.XMLEventAllocator.allocate.

This method allocates an event given the current state of the XMLStreamReader. If this XMLEventAllocator does not have a one-to-one mapping between reader states and events this method will return null. This method must not modify the state of the XMLStreamReader.

Parameters
r:XMLStreamReader

The XMLStreamReader to allocate from

Returns:XMLEvent

the event corresponding to the current reader state

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
allocateback to summary
public void allocate(XMLStreamReader r, XMLEventConsumer consumer) throws XMLStreamException

Implements javax.xml.stream.util.XMLEventAllocator.allocate.

Doc from javax.xml.stream.util.XMLEventAllocator.allocate.

This method allocates an event or set of events given the current state of the XMLStreamReader and adds the event or set of events to the consumer that was passed in. This method can be used to expand or contract reader states into event states. This method may modify the state of the XMLStreamReader.

Parameters
r:XMLStreamReader

The XMLStreamReader to allocate from

consumer:XMLEventConsumer

The XMLEventConsumer to add to.

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
getDefaultInstanceback to summary
public static DefaultEventAllocator getDefaultInstance()
getFastInstanceback to summary
public static DefaultEventAllocator getFastInstance()
newInstanceback to summary
public XMLEventAllocator newInstance()

Implements javax.xml.stream.util.XMLEventAllocator.newInstance.

Doc from javax.xml.stream.util.XMLEventAllocator.newInstance.

This method creates an instance of the XMLEventAllocator. This allows the XMLInputFactory to allocate a new instance per reader.

Returns:XMLEventAllocator

an instance of the XMLEventAllocator

Annotations
@Override
withStartElementback to summary
public Object withStartElement(Location loc, QName name, BaseNsContext nsCtxt, ElemAttrs attrs, boolean wasEmpty)

Implements abstract com.ctc.wstx.sr.ElemCallback.withStartElement.

Annotations
@Override