From: <nik...@us...> - 2015-05-08 15:42:24
|
Revision: 2284 http://sourceforge.net/p/jsbml/code/2284 Author: niko-rodrigue Date: 2015-05-08 15:42:22 +0000 (Fri, 08 May 2015) Log Message: ----------- corrected the hack to set the type of 'cn' element directly in SBMLReader. Now it should work in all cases, even if the parent is a MathContainer element. Modified Paths: -------------- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/xml/stax/SBMLReader.java Modified: branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/xml/stax/SBMLReader.java =================================================================== --- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/xml/stax/SBMLReader.java 2015-05-08 14:46:57 UTC (rev 2283) +++ branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/xml/stax/SBMLReader.java 2015-05-08 15:42:22 UTC (rev 2284) @@ -928,22 +928,35 @@ ASTNode astNode = (ASTNode) processedElement; if (currentNode.getLocalPart().equals("cn") && hasAttributes) { Object object = sbmlElements.peek(); - if (object != null && object instanceof ASTNode) { - ASTNode parent = (ASTNode) object; - if (att.next().getValue().equals("integer")) { - astNode.setType(Type.INTEGER); - } else if(att.next().getValue().equals("e-notation")) { - astNode.setType(Type.REAL_E); - } else if(att.next().getValue().equals("rational")) { - astNode.setType(Type.RATIONAL); - } - // we need to remove the last child as the hierarchy of children are stored in the ASTNode2 and not directly in the ASTNode - parent.removeChild(parent.getChildCount() - 1); - parent.addChild(astNode); - } - } + + while (att.hasNext()) { + + Attribute attribute = att.next(); + String attributeName = attribute.getName().getLocalPart(); + + if (attributeName.equals("type")) { + String type = attribute.getValue(); + + if (type.equalsIgnoreCase("integer")) { + System.out.println("SBMLReader - encountered an integer in MathML !"); + astNode.setType(Type.INTEGER); + } else if(type.equalsIgnoreCase("e-notation")) { + astNode.setType(Type.REAL_E); + } else if(type.equalsIgnoreCase("rational")) { + astNode.setType(Type.RATIONAL); + } + + if (object != null && object instanceof ASTNode) { + ASTNode parent = (ASTNode) object; + + // we need to remove the last child as the hierarchy of children are stored in the ASTNode2 and not directly in the ASTNode + parent.removeChild(parent.getChildCount() - 1); + parent.addChild(astNode); + } // else the parent can be directly a MathContainer - nothing to do in this case. + } + } + } } - sbmlElements.push(processedElement); } else { // It is normal to have sometimes null returned as some of the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |