Package com.boomi.connector.util.xml
Class XMLEventUtilBase
- java.lang.Object
-
- com.boomi.connector.util.xml.XMLEventUtilBase
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
XMLJoiner
,XMLSplitter
public abstract class XMLEventUtilBase extends Object implements Closeable
Common functionality for XMLJoiner/XMLSplitter, generally related to handling xml event streams.
-
-
Field Summary
Fields Modifier and Type Field Description protected static Logger
logger
static String
NAMESPACE_AWARE_PROP
XMLInputFactory key for configuring namespace awarenessstatic String
REPAIR_NAMESPACE_PROP
XMLOutputFactory key for configuring namespace repairing
-
Constructor Summary
Constructors Modifier Constructor Description protected
XMLEventUtilBase(XMLEventReader reader, XMLEventWriter writer, XMLInputFactory inFactory, XMLOutputFactory outFactory)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addObjectEvent(XMLEvent objEvent)
Called to add the given event to the given writer for the current object.void
close()
protected abstract void
closeImpl()
Does the actual close work for this instance, will only be called once.static void
closeQuietly(XMLEventReader reader)
Closes an XMLEventReader, swallowing any exceptions that are thrown.protected void
closeReader()
protected void
closeWriter()
protected XMLEventFactory
createEventFactory()
Constructs a new XMLEventFactory, called bygetEventFactory
the first time an XMLEventFactory is needed.static XMLInputFactory
createInputFactory()
Creates an XMLInputFactory which is namespace aware.static XMLInputFactory
createInputFactory(boolean namespaceAware)
Creates an XMLInputFactory which is optionally namespace aware.static XMLOutputFactory
createOutputFactory()
Creates an XMLOutputFactory which will repair namespaces.static XMLOutputFactory
createOutputFactory(boolean repairNamespaces)
Creates an XMLOutputFactory which will optionally repair namespaces.static StartElement
findNextElementStart(XMLEventReader reader)
Returns the next XMLEvent which is a start element, ornull
if none found.protected void
finishObject()
Called when an current object is finished.protected XMLEventFactory
getEventFactory()
Returns a valid XMLEventFactory.protected XMLInputFactory
getInputFactory()
protected XMLOutputFactory
getOutputFactory()
protected XMLEventReader
getReader()
protected XMLEventWriter
getWriter()
protected XMLEventReader
openReader(InputStream in)
protected XMLEventWriter
openWriter(OutputStream in)
protected void
setReader(XMLEventReader reader)
protected void
setWriter(XMLEventWriter writer)
protected void
startObject(XMLEvent objStartEvent)
Called when a new object is about to be processed.
-
-
-
Field Detail
-
logger
protected static final Logger logger
-
NAMESPACE_AWARE_PROP
public static final String NAMESPACE_AWARE_PROP
XMLInputFactory key for configuring namespace awareness- See Also:
- Constant Field Values
-
REPAIR_NAMESPACE_PROP
public static final String REPAIR_NAMESPACE_PROP
XMLOutputFactory key for configuring namespace repairing- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLEventUtilBase
protected XMLEventUtilBase(XMLEventReader reader, XMLEventWriter writer, XMLInputFactory inFactory, XMLOutputFactory outFactory)
-
-
Method Detail
-
getReader
protected XMLEventReader getReader()
-
getWriter
protected XMLEventWriter getWriter()
-
setReader
protected void setReader(XMLEventReader reader)
-
setWriter
protected void setWriter(XMLEventWriter writer)
-
getInputFactory
protected XMLInputFactory getInputFactory()
-
getOutputFactory
protected XMLOutputFactory getOutputFactory()
-
openReader
protected XMLEventReader openReader(InputStream in) throws XMLStreamException
- Throws:
XMLStreamException
-
closeReader
protected void closeReader()
-
openWriter
protected XMLEventWriter openWriter(OutputStream in) throws XMLStreamException
- Throws:
XMLStreamException
-
closeWriter
protected void closeWriter() throws XMLStreamException
- Throws:
XMLStreamException
-
getEventFactory
protected XMLEventFactory getEventFactory()
Returns a valid XMLEventFactory. CallscreateEventFactory()
on first invocation to actully create the XMLEventFactory, which is then cached for subsequent reuse.
-
createEventFactory
protected XMLEventFactory createEventFactory()
Constructs a new XMLEventFactory, called bygetEventFactory
the first time an XMLEventFactory is needed.- Returns:
- a new XMLEventFactory instance
-
startObject
protected void startObject(XMLEvent objStartEvent) throws XMLStreamException
Called when a new object is about to be processed. Subclasses may override this to add additional per-object prologue events to the writer.Base class does nothing.
- Parameters:
objStartEvent
- the first event for this object, should not be written to the writer at this point, merely provided for context (will be written by first call toaddObjectEvent(javax.xml.stream.events.XMLEvent)
)- Throws:
XMLStreamException
-
addObjectEvent
protected void addObjectEvent(XMLEvent objEvent) throws XMLStreamException
Called to add the given event to the given writer for the current object. Subclasses may override this to alter which events from the input get passed to the output (or to add additional events, manipulate data, read data, etc.).Base class calls
XMLEventWriter.add(javax.xml.stream.events.XMLEvent)
with the given event.- Parameters:
objEvent
- the next input event to be processed- Throws:
XMLStreamException
-
finishObject
protected void finishObject() throws XMLStreamException
Called when an current object is finished. Subclasses may override this to add additional per-object epilogue events to the writer.Base class does nothing.
- Throws:
XMLStreamException
-
close
public final void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
closeImpl
protected abstract void closeImpl()
Does the actual close work for this instance, will only be called once.
-
closeQuietly
public static void closeQuietly(XMLEventReader reader)
Closes an XMLEventReader, swallowing any exceptions that are thrown.- Parameters:
reader
- XMLEventReader to close, may benull
-
findNextElementStart
public static StartElement findNextElementStart(XMLEventReader reader) throws XMLStreamException
Returns the next XMLEvent which is a start element, ornull
if none found.- Throws:
XMLStreamException
-
createInputFactory
public static XMLInputFactory createInputFactory()
Creates an XMLInputFactory which is namespace aware.- Returns:
- a new XMLOutputFactory
-
createInputFactory
public static XMLInputFactory createInputFactory(boolean namespaceAware)
Creates an XMLInputFactory which is optionally namespace aware.- Parameters:
namespaceAware
- whether or not the factory is namespace aware- Returns:
- a new XMLOutputFactory
-
createOutputFactory
public static XMLOutputFactory createOutputFactory()
Creates an XMLOutputFactory which will repair namespaces.- Returns:
- a new XMLOutputFactory
-
createOutputFactory
public static XMLOutputFactory createOutputFactory(boolean repairNamespaces)
Creates an XMLOutputFactory which will optionally repair namespaces.- Parameters:
repairNamespaces
- whether or not the factory will repair namespaces- Returns:
- a new XMLOutputFactory
-
-