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 Loggerloggerstatic StringNAMESPACE_AWARE_PROPXMLInputFactory key for configuring namespace awarenessstatic StringREPAIR_NAMESPACE_PROPXMLOutputFactory key for configuring namespace repairing
-
Constructor Summary
Constructors Modifier Constructor Description protectedXMLEventUtilBase(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 voidaddObjectEvent(XMLEvent objEvent)Called to add the given event to the given writer for the current object.voidclose()protected abstract voidcloseImpl()Does the actual close work for this instance, will only be called once.static voidcloseQuietly(XMLEventReader reader)Closes an XMLEventReader, swallowing any exceptions that are thrown.protected voidcloseReader()protected voidcloseWriter()protected XMLEventFactorycreateEventFactory()Constructs a new XMLEventFactory, called bygetEventFactorythe first time an XMLEventFactory is needed.static XMLInputFactorycreateInputFactory()Creates an XMLInputFactory which is namespace aware.static XMLInputFactorycreateInputFactory(boolean namespaceAware)Creates an XMLInputFactory which is optionally namespace aware.static XMLOutputFactorycreateOutputFactory()Creates an XMLOutputFactory which will repair namespaces.static XMLOutputFactorycreateOutputFactory(boolean repairNamespaces)Creates an XMLOutputFactory which will optionally repair namespaces.static StartElementfindNextElementStart(XMLEventReader reader)Returns the next XMLEvent which is a start element, ornullif none found.protected voidfinishObject()Called when an current object is finished.protected XMLEventFactorygetEventFactory()Returns a valid XMLEventFactory.protected XMLInputFactorygetInputFactory()protected XMLOutputFactorygetOutputFactory()protected XMLEventReadergetReader()protected XMLEventWritergetWriter()protected XMLEventReaderopenReader(InputStream in)protected XMLEventWriteropenWriter(OutputStream in)protected voidsetReader(XMLEventReader reader)protected voidsetWriter(XMLEventWriter writer)protected voidstartObject(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 bygetEventFactorythe 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 XMLStreamExceptionCalled 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:
closein interfaceAutoCloseable- Specified by:
closein 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, ornullif 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
-
-