// System.out.println("SBMLWriter : writeSBMLElements : listOfPackages = "
// + listOfPackages + '\n');
Iterator<WritingParser> iterator = listOfPackages.iterator();
while (iterator.hasNext()) {
WritingParser parser = iterator.next();
List<Object> sbmlElementsToWrite = parser
.getListOfSBMLElementsToWrite(objectToWrite);
// System.out.println("SBMLWriter : writeSBMLElements : parser = "
// + parser);
// System.out
// .println("SBMLWriter : writeSBMLElements : elementsToWrite = "
// + sbmlElementsToWrite);
if (sbmlElementsToWrite == null) {
// TODO : test if there are some characters to write ?
// to allow the XML parser to prune empty elements, this indent should not be added.
// streamWriter.writeCharacters(whiteSpaces.substring(0,
// indent - indentCount));
} else {
for (int i = 0; i < sbmlElementsToWrite.size(); i++) {
Object nextObjectToWrite = sbmlElementsToWrite.get(i);
boolean elementIsNested = false;
/*
* Skip predefined UnitDefinitions (check depending on Level
* 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;