javanet.staxutils
Class BaseXMLEventWriter

java.lang.Object
  extended by javanet.staxutils.BaseXMLEventWriter
All Implemented Interfaces:
javax.xml.stream.util.XMLEventConsumer, javax.xml.stream.XMLEventWriter
Direct Known Subclasses:
StreamEventWriter, XMLStreamEventWriter

public abstract class BaseXMLEventWriter
extends java.lang.Object
implements javax.xml.stream.XMLEventWriter

Base class for XMLEventWriter implementations. This implemenation buffers Attribute and Namespace events as specified in the specification, maintains a stack of NamespaceContext instances based on the events it receives, and repairs any missing namespaces. Subclasses should implement the sendEvent(XMLEvent) method to receive the processed events and perform additional processing.

Version:
$Revision: 1.9 $
Author:
Christian Niles

Field Summary
protected  java.util.Map attrBuff
          LinkedHashMap of attribute events sent surrounding the last StartElement.
protected  boolean closed
          Whether this writer has been closed or not.
protected  javax.xml.stream.XMLEventFactory factory
          XMLEventFactory used to construct XMLEvent instances.
protected  javax.xml.stream.events.StartElement lastStart
          Reference to the last StartElement sent.
protected  java.util.Map nsBuff
          LinkedHashMap of namespace events sent surrounding the last StartElement.
protected  java.util.List nsStack
          list of SimpleNamespaceContexts.
 
Constructor Summary
protected BaseXMLEventWriter()
           
protected BaseXMLEventWriter(javax.xml.stream.XMLEventFactory eventFactory, javax.xml.namespace.NamespaceContext nsCtx)
           
 
Method Summary
 void add(javax.xml.stream.events.XMLEvent event)
           
 void add(javax.xml.stream.XMLEventReader reader)
           
protected  void cacheAttribute(javax.xml.stream.events.Attribute attr)
          Adds the specified Attribute to the attribute cache.
protected  void cacheNamespace(javax.xml.stream.events.Namespace ns)
          Adds the provided Namespace event to the namespace cache.
 void close()
           
 void flush()
           
 javax.xml.namespace.NamespaceContext getNamespaceContext()
           
 java.lang.String getPrefix(java.lang.String nsURI)
           
protected  SimpleNamespaceContext peekNamespaceStack()
          Returns the active SimpleNamespaceContext from the top of the stack.
protected  SimpleNamespaceContext popNamespaceStack()
          Removes the active SimpleNamespaceContext from the top of the stack.
protected  SimpleNamespaceContext pushNamespaceStack()
          Creates a new SimpleNamespaceContext and adds it to the top of the stack.
protected abstract  void sendEvent(javax.xml.stream.events.XMLEvent event)
          Called by the methods of this class to write the event to the stream.
 void setDefaultNamespace(java.lang.String nsURI)
           
 void setNamespaceContext(javax.xml.namespace.NamespaceContext root)
           
 void setPrefix(java.lang.String prefix, java.lang.String nsURI)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

protected javax.xml.stream.XMLEventFactory factory
XMLEventFactory used to construct XMLEvent instances.


nsStack

protected java.util.List nsStack
list of SimpleNamespaceContexts.


lastStart

protected javax.xml.stream.events.StartElement lastStart
Reference to the last StartElement sent. This will be null if no StartElement has been sent, or after a non Attribute/Namespace event is received.


attrBuff

protected java.util.Map attrBuff
LinkedHashMap of attribute events sent surrounding the last StartElement. By using LinkedHashMap, the attributes will stay in the order they were defined.


nsBuff

protected java.util.Map nsBuff
LinkedHashMap of namespace events sent surrounding the last StartElement. By using LinkedHashMap, the namespaces will stay in the order they were defined.


closed

protected boolean closed
Whether this writer has been closed or not.

Constructor Detail

BaseXMLEventWriter

protected BaseXMLEventWriter()

BaseXMLEventWriter

protected BaseXMLEventWriter(javax.xml.stream.XMLEventFactory eventFactory,
                             javax.xml.namespace.NamespaceContext nsCtx)
Method Detail

flush

public void flush()
           throws javax.xml.stream.XMLStreamException
Specified by:
flush in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

close

public void close()
           throws javax.xml.stream.XMLStreamException
Specified by:
close in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

add

public void add(javax.xml.stream.events.XMLEvent event)
         throws javax.xml.stream.XMLStreamException
Specified by:
add in interface javax.xml.stream.util.XMLEventConsumer
Specified by:
add in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

add

public void add(javax.xml.stream.XMLEventReader reader)
         throws javax.xml.stream.XMLStreamException
Specified by:
add in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

getPrefix

public java.lang.String getPrefix(java.lang.String nsURI)
                           throws javax.xml.stream.XMLStreamException
Specified by:
getPrefix in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

setPrefix

public void setPrefix(java.lang.String prefix,
                      java.lang.String nsURI)
               throws javax.xml.stream.XMLStreamException
Specified by:
setPrefix in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

setDefaultNamespace

public void setDefaultNamespace(java.lang.String nsURI)
                         throws javax.xml.stream.XMLStreamException
Specified by:
setDefaultNamespace in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

setNamespaceContext

public void setNamespaceContext(javax.xml.namespace.NamespaceContext root)
                         throws javax.xml.stream.XMLStreamException
Specified by:
setNamespaceContext in interface javax.xml.stream.XMLEventWriter
Throws:
javax.xml.stream.XMLStreamException

getNamespaceContext

public javax.xml.namespace.NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface javax.xml.stream.XMLEventWriter

popNamespaceStack

protected SimpleNamespaceContext popNamespaceStack()
Removes the active SimpleNamespaceContext from the top of the stack.

Returns:
The SimpleNamespaceContext removed from the namespace stack.

peekNamespaceStack

protected SimpleNamespaceContext peekNamespaceStack()
Returns the active SimpleNamespaceContext from the top of the stack.

Returns:
The active SimpleNamespaceContext from the top of the stack.

pushNamespaceStack

protected SimpleNamespaceContext pushNamespaceStack()
Creates a new SimpleNamespaceContext and adds it to the top of the stack.

Returns:
The new SimpleNamespaceContext.

cacheAttribute

protected void cacheAttribute(javax.xml.stream.events.Attribute attr)
Adds the specified Attribute to the attribute cache.

Parameters:
attr - The attribute to cache.

cacheNamespace

protected void cacheNamespace(javax.xml.stream.events.Namespace ns)
Adds the provided Namespace event to the namespace cache. The current namespace context will not be affected.

Parameters:
ns - The namespace to add to the cache.

sendEvent

protected abstract void sendEvent(javax.xml.stream.events.XMLEvent event)
                           throws javax.xml.stream.XMLStreamException
Called by the methods of this class to write the event to the stream.

Parameters:
event - The event to write.
Throws:
javax.xml.stream.XMLStreamException - If an error occurs processing the event.


Copyright © 2013. All Rights Reserved.