public abstract class AbstractOMDataSource extends Object implements OMDataSourceExt
OMDataSourceExt
implementations. This class should only be used by data
sources that can equally well produce an XMLStreamReader
and have a meaningful
implementation of OMDataSource.serialize(XMLStreamWriter)
. Most implementations should
actually use AbstractPullOMDataSource
or AbstractPushOMDataSource
.LOSSY_PREFIX
Constructor and Description |
---|
AbstractOMDataSource() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the DataSource and free its resources.
|
OMDataSourceExt |
copy()
Create a copy of the data source.
|
Object |
getObject()
Get the object that backs this data source.
|
Object |
getProperty(String key)
Query a property stored on the OMDataSource
|
byte[] |
getXMLBytes(String encoding)
Returns a byte[] representing the xml data
|
InputStream |
getXMLInputStream(String encoding)
Returns a InputStream representing the xml data
|
boolean |
hasProperty(String key)
Returns true if property is set
|
void |
serialize(OutputStream out,
OMOutputFormat format)
Serializes element data directly to stream.
|
void |
serialize(Writer writer,
OMOutputFormat format)
Serializes element data directly to writer.
|
Object |
setProperty(String key,
Object value)
Set a property on the OMDataSource
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isDestructiveRead, isDestructiveWrite
getReader, serialize
public final Object getProperty(String key)
OMDataSourceExt
getProperty
in interface OMDataSourceExt
public final boolean hasProperty(String key)
OMDataSourceExt
hasProperty
in interface OMDataSourceExt
public final Object setProperty(String key, Object value)
OMDataSourceExt
setProperty
in interface OMDataSourceExt
public final void serialize(OutputStream out, OMOutputFormat format) throws XMLStreamException
OMDataSource
It is assumed that this method consumes the content (i.e. destroys the backing object) unless
the data source also implements OMDataSourceExt
and
OMDataSourceExt.isDestructiveWrite()
returns false
.
serialize
in interface OMDataSource
out
- destination stream for element XML textformat
- Output format information. The implementation must use this information to choose
the correct character set encoding when writing to the output stream. This
parameter must not be null.XMLStreamException
public final void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException
OMDataSource
It is assumed that this method consumes the content (i.e. destroys the backing object) unless
the data source also implements OMDataSourceExt
and
OMDataSourceExt.isDestructiveWrite()
returns false
.
serialize
in interface OMDataSource
writer
- destination writer for element XML textformat
- output format information (null
if none; may be ignored if not
supported by data binding even if supplied)XMLStreamException
public final byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException
OMDataSourceExt
getXMLBytes
in interface OMDataSourceExt
encoding
- String encoding of InputStreamUnsupportedEncodingException
OMDataSourceExt.getXMLInputStream(String)
public final InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException
OMDataSourceExt
getXMLInputStream
in interface OMDataSourceExt
encoding
- String encoding of InputStreamUnsupportedEncodingException
public Object getObject()
OMDataSourceExt
OMSourcedElement.getObject(Class)
instead.
Data sources that support non destructive read/write should return the object from which the XML is produced. Data sources with destructive read/write should return a non null value only if the backing object has not been consumed yet (even partially).
getObject
in interface OMDataSourceExt
null
if the data source has no backing object or
if the backing object can't be accessed in a safe waypublic void close()
OMDataSourceExt
close
in interface OMDataSourceExt
public OMDataSourceExt copy()
OMDataSourceExt
OMInformationItem.clone(OMCloneOptions)
when the
OMCloneOptions.isCopyOMDataSources()
option is enabled. If the data source is
immutable and stateless, then it may return a reference to itself instead of creating a new
data source instance.copy
in interface OMDataSourceExt
null
if the data source can't be copied
(e.g. because it is destructive)Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.