|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.tm4j.topicmap.utils.HelperBase org.tm4j.topicmap.utils.TopicMapSerializer
A subclass of HelperBase
capable of serializing a TopicMap
to an OutputStream
.
A typical usage pattern for instances of this class is this:
setOutputStream(OutputStream)
.
Alternatively, you may also use setOutputFile(File)
or
setOutputFile(String)
to write directly to a file.setTopicMap(TopicMap)
.serialize()
to perform the actual serialization.
When serialization is complete, the output stream is flushed, but not closed.closeOutputStream()
.VetoableChangeListener
s:
TopicMap
, read/write). The topic map to be
serialized.OutputStream
, read/write). The output
stream to which the topic map is serialized.true
,
the result document will contain a <!DOCTYPE>
declaration,
if false
, that declaration is omitted.
If false
, no indentation is used. The default is true
.
String
, read/write). The System identifier
to be used in the document type declaration of the output document. The
default is the System ID for XTM 1.0. This property is ignored if
"includeDoctype" is false
.String
, read/write). The Public identifier
to be used in the document type declaration of the output document. The
default is the Public ID for XTM 1.0. This property is ignored if
"includeDoctype" is false
.String
, read/write). The output encoding
to be used during serialization. The default is UTF-8.null
, which will cause
any debugging output, except "fatal" messages, to be suppressed.
This property is inherited from the superclass.true
if the result has been properly serialized, false
otherwise. The default
(prior to serialization) is false
.
Field Summary | |
protected static java.lang.String |
DEFAULT_ENCODING
The default output encoding. |
protected static boolean |
DEFAULT_INCLUDE_DOCTYPE
The default setting for including a document type declaration in the output. |
protected static int |
DEFAULT_INDENT
The default setting for indenting the output. |
protected static java.io.OutputStream |
DEFAULT_OUTPUT_STREAM
The default serialization output stream. |
static java.lang.String |
XTM_PUBLIC_ID
The XTM 1.0 system ID. |
static java.lang.String |
XTM_SYSTEM_ID
The XTM 1.0 system ID. |
Constructor Summary | |
TopicMapSerializer()
Constructs a new instance. |
|
TopicMapSerializer(TopicMap topicMap)
Constructs a new instance, initializing it with an existing TopicMap . |
|
TopicMapSerializer(TopicMap topicMap,
java.io.File file)
Constructs a new instance, initializing it with an existing TopicMap and an output File to serialize to. |
|
TopicMapSerializer(TopicMap topicMap,
java.io.OutputStream stream)
Constructs a new instance, initializing it with an existing TopicMap and an OutputStream to serialize to. |
|
TopicMapSerializer(TopicMap topicMap,
java.lang.String path)
Constructs a new instance, initializing it with an existing TopicMap and the path to an output File
to serialize to. |
Method Summary | |
void |
closeOutputStream()
A convenience method that closes the output stream. |
java.lang.String |
getEncoding()
Retrieves the character encoding to be used when serializing. |
int |
getIndentation()
Returns the indentation level of the serialized output. |
java.io.OutputStream |
getOutputStream()
Retrieves the output stream to be used for serialization. |
java.lang.String |
getPublicId()
Retrieves the PUBLIC identifier to be included in the serialized document's <!DOCTYPE> declaration. |
java.lang.String |
getSystemId()
Retrieves the SYSTEM identifier to be included in the serialized document's <!DOCTYPE> declaration. |
TopicMap |
getTopicMap()
Retrieves the TopicMap to be serialized. |
boolean |
getWriteStubs()
|
protected void |
init()
Initializes the instance and sets appropriate default values for properties. |
boolean |
isIncludingDoctype()
Determines whether the serialized output will contain a <!DOCTYPE> declaration. |
boolean |
isSerialized()
Returns whether the instance has successfully completed the serialization process. |
void |
serialize()
Performs the serialization of the merged topic map. |
void |
setEncoding(java.lang.String newVal)
Sets the character encoding to be used when serializing. |
void |
setIncludeDoctype(boolean newVal)
Configures the instance to include a <!DOCTYPE> declaration in the serialized output. |
void |
setIndentation(int newVal)
Configures the instance to indent (pretty-print) the serialized output. |
void |
setOutputFile(java.io.File file)
Configures the instance to use the specified output file for serialization. |
void |
setOutputFile(java.lang.String path)
Configures the instance to use the file denoted by the specified path for serialization. |
void |
setOutputStream(java.io.OutputStream newStream)
Sets the output stream to which the merged result is serialized. |
void |
setPublicId(java.lang.String newVal)
Sets the PUBLIC identifier to be included in the serialized document's <!DOCTYPE> declaration. |
protected void |
setSerialized(boolean newVal)
Sets the state of serialization. |
void |
setSystemId(java.lang.String newVal)
Sets the SYSTEM identifier to be included in the serialized document's <!DOCTYPE> declaration. |
void |
setTopicMap(TopicMap newTopicMap)
Sets the TopicMap to be serialized. |
void |
setWriteStubs(boolean b)
Sets whether or not the serialization will include topics that have only a single subject indicator or only a subject address and no other properties. |
Methods inherited from class org.tm4j.topicmap.utils.HelperBase |
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, debug, error, error, fatal, fatal, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getLogger, hasLogger, info, logVetoedChange, removeLogger, setLogger, trace, warn, warn |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String DEFAULT_ENCODING
protected static final boolean DEFAULT_INCLUDE_DOCTYPE
protected static final int DEFAULT_INDENT
protected static final java.io.OutputStream DEFAULT_OUTPUT_STREAM
public static final java.lang.String XTM_PUBLIC_ID
public static final java.lang.String XTM_SYSTEM_ID
Constructor Detail |
public TopicMapSerializer()
public TopicMapSerializer(TopicMap topicMap)
TopicMap
.
Using this constructor will cause property change vetoing on the
"topicMap" property to be bypassed as the property is set before
any change listeners can be registered.
topicMap
- the topic map to be serialized.public TopicMapSerializer(TopicMap topicMap, java.io.File file) throws java.io.IOException
TopicMap
and an output File
to serialize to.
Using this constructor will cause property change vetoing on the
"topicMap" and "outputStream" properties to be bypassed as
the properties are set before any change listeners can be
registered.
topicMap
- the topic map to be serialized.file
- the file to which the output shall be serialized.
FileNotFoundException
- if the output file can't be accessed.
Kept for backwards compatiblity with JDK/JRE 1.2,
on later Java versions, this constructor will only throw
FileNotFoundException
.
java.io.IOException
public TopicMapSerializer(TopicMap topicMap, java.io.OutputStream stream)
TopicMap
and an OutputStream
to serialize to.
Using this constructor will cause property change vetoing on the
"topicMap" and "outputStream" properties to be bypassed as
the properties are set before any change listeners can be
registered.
topicMap
- the topic map to be serialized.stream
- the output stream to serialize topublic TopicMapSerializer(TopicMap topicMap, java.lang.String path) throws java.io.IOException
TopicMap
and the path to an output File
to serialize to.
Using this constructor will cause property change vetoing on the
"topicMap" and "outputStream" properties to be bypassed as
the properties are set before any change listeners can be
registered.
topicMap
- the topic map to be serialized.path
- the path of the file to which the output shall be serialized.
java.io.IOException
- if the output file denoted by the
path can't be accessed.
Kept for backwards compatibility with JDK/JRE 1.2,
on later Java versions, this constructor will only throw
FileNotFoundException
.Method Detail |
public void closeOutputStream() throws java.io.IOException
getOutputStream().close()
.
java.io.IOException
- if the stream could not be closed properly.public java.lang.String getEncoding()
public java.io.OutputStream getOutputStream()
public java.lang.String getPublicId()
<!DOCTYPE>
declaration.
public java.lang.String getSystemId()
<!DOCTYPE>
declaration.
public TopicMap getTopicMap()
TopicMap
to be serialized.
protected void init() throws java.lang.InstantiationException, java.lang.IllegalAccessException, TopicMapProviderException, LocatorFactoryException
init
in class HelperBase
java.lang.InstantiationException
java.lang.IllegalAccessException
TopicMapProviderException
LocatorFactoryException
public boolean isIncludingDoctype()
<!DOCTYPE>
declaration.
true
if the serialized output is to contain
a document type declaration, false
otherwise.public int getIndentation()
public boolean isSerialized()
true
if the instance has been properly serialized,
false
otherwise.public void serialize() throws TopicMapProcessingException, java.io.IOException
closeOutputStream()
.
TopicMapProcessingException
- if an unexpected condition
occurs while "walking" the topic map.
java.io.IOException
- if writing to the output stream fails.public void setEncoding(java.lang.String newVal)
VetoableChangeListener
may determine that the property change is inappropriate or invalid,
and ask for it to be rolled back. In that case, the property's
original value is restored, and a warning is issued to any registered
logger.
newVal
- the character encoding used during serialization.public void setIncludeDoctype(boolean newVal)
<!DOCTYPE>
declaration in the serialized output.
Since changes to this
property are vetoable, a registered VetoableChangeListener
may determine that the property change is inappropriate or invalid,
and ask for it to be rolled back. In that case, the property's
original value is restored, and a warning is issued to any registered
logger.
true
if the serialized output is to contain
a document type declaration, false
otherwise.public void setIndentation(int newVal)
VetoableChangeListener
may determine that the property change is inappropriate or invalid,
and ask for it to be rolled back. In that case, the property's
original value is restored, and a warning is issued to any registered
logger.
true
if the serialized output is to be indented,
false
otherwise.public void setOutputFile(java.io.File file) throws java.io.IOException
FileOutputStream
from file
, and then
invokes setOutputStream(OutputStream)
.
file
- the output file to use for serialization.
java.io.IOException
- if the specified output file can't be
accessed. Kept for backwards compatibility with JDK/JRE 1.2,
on later Java versions, this method will only throw
FileNotFoundException
.public void setOutputFile(java.lang.String path) throws java.io.IOException
File
from path
, and then
invokes setOutputFile(File)
.
path
- the (relative or absolute) path to the output file to
use for serialization.
java.io.IOException
- if the specified output file can't be
accessed. Kept for backwards compatibility with JDK/JRE 1.2,
on later Java versions, this method will only throw
FileNotFoundException
.public void setOutputStream(java.io.OutputStream newStream)
VetoableChangeListener
may determine that the property change is inappropriate or invalid,
and ask for it to be rolled back. In that case, the property's
original value is restored, and a warning is issued to any registered
logger.
newStream
- the output stream to be written to during
serialization.public void setPublicId(java.lang.String newVal)
<!DOCTYPE>
declaration.
newVal
- the public ID to be used while writing the output document.protected void setSerialized(boolean newVal)
newVal
- true
if the instance has been properly serialized,
false
otherwise.public void setSystemId(java.lang.String newVal)
<!DOCTYPE>
declaration.
newVal
- the system ID to be used while writing the output document.public void setTopicMap(TopicMap newTopicMap)
TopicMap
to be serialized.
Since changes to this
property are vetoable, a registered VetoableChangeListener
may determine that the property change is inappropriate or invalid,
and ask for it to be rolled back. In that case, the property's
original value is restored, and a warning is issued to any registered
logger.
newTopicMap
- the new topic map to be serialized.public boolean getWriteStubs()
public void setWriteStubs(boolean b)
b
- true to write the topics, false to skip them
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |