* and Version).
*/
if (nextObjectToWrite instanceof ListOf<?>) {
ListOf<?> list = (ListOf<?>) nextObjectToWrite;
if (list.size() > 0) {
SBase sb = list.getFirst();
if ((sb instanceof UnitDefinition) && (parser
.getListOfSBMLElementsToWrite(nextObjectToWrite) == null)) {
streamWriter.writeCharacters(whiteSpaces.substring(0, indent - indentCount));
continue;
}
} else {
streamWriter.writeCharacters(whiteSpaces.substring(0, indent - indentCount));
continue;
}
}
parentXmlObject.clear();
/*
* The following containers are all optional in a
* <reaction>, but if any is present, it must not be empty:
* <listOfReactants>, <listOfProducts>, <listOfModifiers>,
* <kineticLaw>. (References: L2V2 Section 4.13; L2V3
* Section 4.13; L2V4 Section 4.13)
*/
if (nextObjectToWrite instanceof ListOf<?>) {
ListOf<?> toTest = (ListOf<?>) nextObjectToWrite;
if (toTest.size() > 0) {
elementIsNested = true;
}
Type listType = toTest.getSBaseListType();
if (listType == Type.none) {
// Prevent writing invalid SBML if list types are
// not set appropriately.
throw new SBMLException(String.format(
"Unknown ListOf type \"%s\".",
toTest.getElementName()));
}
if (listType.equals(ListOf.Type.listOfReactants)
|| listType.equals(ListOf.Type.listOfProducts)
|| listType.equals(ListOf.Type.listOfModifiers)) {
if (toTest.size() < 1) {
continue; // Skip these, see reference in
// comment above.
}
}
} else if (nextObjectToWrite instanceof KineticLaw) {
// TODO: Is there any chance, that an KineticLaw get's
// an empty XML entity?
}
// Writing the element, starting by the indent
streamWriter.writeCharacters(whiteSpaces);
parser.writeElement(parentXmlObject, nextObjectToWrite);
parser.writeNamespaces(parentXmlObject, nextObjectToWrite);
parser.writeAttributes(parentXmlObject, nextObjectToWrite);
SMOutputElement newOutPutElement = null;
if (parentXmlObject.isSetName()) {
boolean isClosedMathContainer = false, isClosedAnnotation = false;
if (parentXmlObject.isSetNamespace()) {
SMNamespace namespaceContext = smOutputParentElement
.getNamespace(
parentXmlObject.getNamespace(),
parentXmlObject.getPrefix());
newOutPutElement = smOutputParentElement
.addElement(namespaceContext,
parentXmlObject.getName());
} else {
newOutPutElement = smOutputParentElement
.addElement(smOutputParentElement
.getNamespace(), parentXmlObject
.getName());
}
Iterator<Entry<String, String>> it = parentXmlObject
.getAttributes().entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> entry = it.next();
newOutPutElement.addAttribute(entry.getKey(),
entry.getValue());
}
if (nextObjectToWrite instanceof SBase) {
SBase s = (SBase) nextObjectToWrite;
if (s.isSetNotes()) {
writeNotes(s, newOutPutElement, streamWriter,
newOutPutElement.getNamespace()
.getURI(), indent + indentCount);
elementIsNested = isClosedAnnotation = true;
}
if (s.isSetAnnotation()) {
writeAnnotation(s, newOutPutElement,
streamWriter,
indent + indentCount, false);
elementIsNested = true;
}
if (s.getChildCount() > 0) {
// make sure that we'll have line breaks if an element has any sub elements.
elementIsNested = true;
}
}
if (nextObjectToWrite instanceof Constraint) {