org.sbml.jsbml.xml.stax
public class SBMLWriter extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private char |
indentChar
The symbol for indentation.
|
private short |
indentCount
The number of indentation symbols.
|
private java.util.Map<java.lang.String,WritingParser> |
instantiatedSBMLParsers
contains the WritingParser instances of this class.
|
private java.util.List<java.lang.String> |
issuedWarnings
Remember already issued warnings to avoid having multiple lines, saying
the same thing (Warning: Skipping detailed parsing of name space 'XYZ'.
|
(package private) org.apache.log4j.Logger |
logger
A
Logger for this class. |
Constructor and Description |
---|
SBMLWriter()
|
SBMLWriter(char indentChar,
short indentCount)
Creates a new
SBMLWriter with the given configuration for the
indentChar and indentCount , i.e., the symbol to be used
to indent elements in the XML representation of SBML data objects and the
number of these symbols to be concatenated at the beginning of each new
line for a new element. |
Modifier and Type | Method and Description |
---|---|
private void |
addWritingParser(java.util.List<WritingParser> sbmlParsers,
WritingParser sbmlParser,
java.lang.String namespace)
Adds a
WritingParser to the given list of WritingParser |
private java.lang.String |
createIndentationString(int indent)
Creates the necessary number of white spaces at the beginning
of an entry in the SBML file.
|
static char |
getDefaultIndentChar()
Returns the default symbol to be used to indent new elements in the XML
representation of SBML data structures.
|
static short |
getDefaultIndentCount()
Returns the default number of indent symbols to be concatenated at the
beginning of a new block in an XML representation of SBML data
structures.
|
char |
getIndentationChar()
Gives the symbol that is used to indent the SBML output for a better
structure and to improve human-readability.
|
short |
getIndentationCount()
Gives the number of indent symbols that are inserted in a line to better structure the SBML output.
|
private java.util.List<WritingParser> |
getWritingParsers(java.lang.Object object,
java.lang.String parentNamespace)
Gets all the writing parsers necessary to write the given object.
|
private java.util.Map<java.lang.String,WritingParser> |
initializePackageParsers()
Creates the ReadingParser instances and stores them in a HashMap.
|
private boolean |
isEmptyListOf(java.lang.Object object)
|
static void |
main(java.lang.String[] args)
Tests this class
|
void |
setIndentationChar(char indentSymbol)
Sets other blank character(s) for indentation.
|
void |
setIndentationCount(int indentCount)
Sets the indent for this
SBMLWriter . |
void |
setIndentationCount(short indentCount)
Sets the indent for this
SBMLWriter . |
void |
write(SBMLDocument document,
java.io.File file)
Writes the
SBMLDocument into a File . |
void |
write(SBMLDocument document,
java.io.File file,
java.lang.String programName,
java.lang.String programVersion)
Writes the
SBMLDocument into a File . |
void |
write(SBMLDocument sbmlDocument,
java.io.OutputStream stream)
Writes the
SBMLDocument into an OutputStream . |
void |
write(SBMLDocument sbmlDocument,
java.io.OutputStream stream,
java.lang.String programName,
java.lang.String programVersion)
Writes the XML representation of an
SBMLDocument into an OutputStream . |
void |
write(SBMLDocument sbmlDocument,
java.lang.String fileName)
Writes the XML representation of an
SBMLDocument in a SBML file. |
void |
write(SBMLDocument sbmlDocument,
java.lang.String fileName,
java.lang.String programName,
java.lang.String programVersion)
Writes the XML representation of an
SBMLDocument in a SBML file. |
java.lang.String |
writeAnnotation(SBase sbase)
|
private void |
writeAnnotation(SBase sbase,
SMOutputContainer element,
javax.xml.stream.XMLStreamWriter writer,
int indent,
boolean xmlFragment)
Writes the
Annotation of an SBase element. |
private void |
writeMathML(MathContainer m,
SMOutputElement element,
javax.xml.stream.XMLStreamWriter writer,
int indent)
Writes the MathML expression of a
MathContainer element. |
private void |
writeMessage(Constraint sbase,
SMOutputElement element,
javax.xml.stream.XMLStreamWriter writer,
java.lang.String sbmlNamespace,
int indent)
Writes the message of a
Constraint to the given XMLStreamWriter . |
private void |
writeNotes(SBase sbase,
SMOutputElement element,
javax.xml.stream.XMLStreamWriter writer,
java.lang.String sbmlNamespace,
int indent)
Writes the notes of this
SBase element to the given XMLStreamWriter . |
private void |
writeSBMLElements(SBMLObjectForXML parentXmlObject,
SMOutputElement smOutputParentElement,
javax.xml.stream.XMLStreamWriter streamWriter,
java.lang.Object parentObject,
int indent)
Writes the SBML elements to an
XMLStreamWriter . |
java.lang.String |
writeSBMLToString(SBMLDocument doc)
Writes the given
SBMLDocument to an in-memory XML String . |
java.lang.String |
writeSBMLToString(SBMLDocument d,
java.lang.String programName,
java.lang.String programVersion)
Writes the given
SBMLDocument to an in-memory XML String . |
private char indentChar
private short indentCount
private java.util.Map<java.lang.String,WritingParser> instantiatedSBMLParsers
private transient java.util.List<java.lang.String> issuedWarnings
org.apache.log4j.Logger logger
Logger
for this class.public SBMLWriter()
public SBMLWriter(char indentChar, short indentCount)
SBMLWriter
with the given configuration for the
indentChar
and indentCount
, i.e., the symbol to be used
to indent elements in the XML representation of SBML data objects and the
number of these symbols to be concatenated at the beginning of each new
line for a new element.indentChar
- the symbol to be used to indent elements in the XML representationindentCount
- the number of these symbols to be concatenatedpublic static char getDefaultIndentChar()
public static short getDefaultIndentCount()
public static void main(java.lang.String[] args) throws SBMLException
args
- SBMLException
private void addWritingParser(java.util.List<WritingParser> sbmlParsers, WritingParser sbmlParser, java.lang.String namespace)
WritingParser
to the given list of WritingParser
sbmlParsers
- sbmlParser
- namespace
- private java.lang.String createIndentationString(int indent)
indent
- public char getIndentationChar()
public short getIndentationCount()
private java.util.List<WritingParser> getWritingParsers(java.lang.Object object, java.lang.String parentNamespace)
object
- parentNamespace
- private java.util.Map<java.lang.String,WritingParser> initializePackageParsers()
public void setIndentationChar(char indentSymbol)
Allowed are
only tabs and white spaces, i.e., '\t'
and ' '
.
indentSymbol
- the character to be used for indentationpublic void setIndentationCount(int indentCount)
SBMLWriter
.indentCount
- the indent count to setsetIndentationCount(short)
public void setIndentationCount(short indentCount)
SBMLWriter
.indentCount
- the indent count to setpublic void write(SBMLDocument document, java.io.File file) throws javax.xml.stream.XMLStreamException, SBMLException, java.io.IOException
SBMLDocument
into a File
.document
- the SBMLDocument
to write.file
- the File
to write to.SBMLException
- if any error is detected in the SBMLDocument
.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.java.io.IOException
- if it is not possible to write to the given file, e.g., due
to an invalid file name or missing permissions.public void write(SBMLDocument document, java.io.File file, java.lang.String programName, java.lang.String programVersion) throws javax.xml.stream.XMLStreamException, SBMLException, java.io.IOException
SBMLDocument
into a File
.document
- the SBMLDocument
to write.file
- the File
to write to.programName
- the program name.programVersion
- the program version.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.java.io.IOException
- if it is not possible to write to the given file, e.g., due
to an invalid file name or missing permissions.public void write(SBMLDocument sbmlDocument, java.io.OutputStream stream) throws javax.xml.stream.XMLStreamException, SBMLException
SBMLDocument
into an OutputStream
.sbmlDocument
- the SBMLDocument
to write.stream
- a OutputStream
where to write the content of the model to.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.public void write(SBMLDocument sbmlDocument, java.io.OutputStream stream, java.lang.String programName, java.lang.String programVersion) throws javax.xml.stream.XMLStreamException, SBMLException
SBMLDocument
into an OutputStream
.sbmlDocument
- the SBMLDocument
stream
- the OutputStream
to write to.programName
- the program name (can be null).programVersion
- the program version (can be null).javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.public void write(SBMLDocument sbmlDocument, java.lang.String fileName) throws javax.xml.stream.XMLStreamException, SBMLException, java.io.IOException
SBMLDocument
in a SBML file.sbmlDocument
- the SBMLDocument
to write.fileName
- the name of the file where to write the SBMLDocument
javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.java.io.IOException
- if an I/O error occurs.public void write(SBMLDocument sbmlDocument, java.lang.String fileName, java.lang.String programName, java.lang.String programVersion) throws javax.xml.stream.XMLStreamException, SBMLException, java.io.IOException
SBMLDocument
in a SBML file.sbmlDocument
- the SBMLDocument
to write.fileName
- the name of the file where to write the SBMLDocument
programName
- the program name that created the SBMLDocument
programVersion
- the program version that created the SBMLDocument
javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.java.io.IOException
- if an I/O error occurs.public java.lang.String writeAnnotation(SBase sbase) throws javax.xml.stream.XMLStreamException
sbase
- the SBase
element.Annotation
of the given SBase
element as an XML String
.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.private void writeAnnotation(SBase sbase, SMOutputContainer element, javax.xml.stream.XMLStreamWriter writer, int indent, boolean xmlFragment) throws javax.xml.stream.XMLStreamException
Annotation
of an SBase
element.sbase
- the SBase
element.element
- the matching SMOutputElement
writer
- the XMLStreamWriter
to write to.sbmlNamespace
- the SBML namespace.indent
- the number of indent white spaces of this annotation.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.private void writeMathML(MathContainer m, SMOutputElement element, javax.xml.stream.XMLStreamWriter writer, int indent) throws javax.xml.stream.XMLStreamException
MathContainer
element.m
- the MathContainer
element.element
- the matching SMOutputElement
.writer
- the XMLStreamWriter
to write to.indent
- the number of white spaces to indent this element.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.private void writeMessage(Constraint sbase, SMOutputElement element, javax.xml.stream.XMLStreamWriter writer, java.lang.String sbmlNamespace, int indent) throws javax.xml.stream.XMLStreamException
Constraint
to the given XMLStreamWriter
.sbase
- the Constraint
element.element
- the matching SMOutputElement
.writer
- the XMLStreamWriter
to write to.sbmlNamespace
- the SBML namespace.indent
- the number of white spaces to indent this element.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.private void writeNotes(SBase sbase, SMOutputElement element, javax.xml.stream.XMLStreamWriter writer, java.lang.String sbmlNamespace, int indent) throws javax.xml.stream.XMLStreamException
SBase
element to the given XMLStreamWriter
.sbase
- the SBase
element.element
- the matching SMOutputElement
writer
- the XMLStreamWriter
to write to.sbmlNamespace
- the SBML namespace.indent
- the number of white spaces to indent this element.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.private void writeSBMLElements(SBMLObjectForXML parentXmlObject, SMOutputElement smOutputParentElement, javax.xml.stream.XMLStreamWriter streamWriter, java.lang.Object parentObject, int indent) throws javax.xml.stream.XMLStreamException, SBMLException
XMLStreamWriter
.parentXmlObject
- contains the XML information of the parentElement.smOutputParentElement
- SMOutputElement
of the parentElement.streamWriter
- the XMLStreamWriter
to write to.parentObject
- the Object
to write.indent
- the number of white spaces to indent this element.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.private boolean isEmptyListOf(java.lang.Object object)
object
- the Object
to testtrue
if the given Object
is an empty ListOf
, false
otherwise.public java.lang.String writeSBMLToString(SBMLDocument doc) throws javax.xml.stream.XMLStreamException, SBMLException
SBMLDocument
to an in-memory XML String
.doc
- the SBMLdocument
SBMLdocument
as a
String.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.public java.lang.String writeSBMLToString(SBMLDocument d, java.lang.String programName, java.lang.String programVersion) throws javax.xml.stream.XMLStreamException, SBMLException
SBMLDocument
to an in-memory XML String
.d
- programName
- programVersion
- SBMLdocument
as a String
.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
- if any error is detected in the SBMLDocument
.