#44 Error in processing messages (2)

jsbml 1.2
open-accepted
5
2015-09-03
2011-03-03
Anonymous
No

Thank you for the quick fix of the bug "Error in processing messages - ID: 3196638". Unfortunately there is still a problem in the method processStartElement in the class StringParser. If you want to import a message it causes an error, because the method getMessage from the class constraint returns null if it isn't set. I would suggest the following code fragment for the method processStartElement :

if (typeOfNotes.equals("notes")) {
parentSBMLElement.getNotes().addChild(xmlNode);
} else if (typeOfNotes.equals("message") && parentSBMLElement instanceof Constraint) {
XMLNode message = ((Constraint) parentSBMLElement).getMessage();
if(message!=null)
message.addChild(xmlNode);
else
{
((Constraint) parentSBMLElement).setMessage(xmlNode);
}

With this change in the code you insure that a message wil be set even if there was no one before.

Discussion

    • assigned_to: nobody --> niko-rodrigue
    • labels: --> XML Reading/Writing
    • status: open --> pending-works-for-me
     
  • Did you get a NullPointerException ??

    The original XMLNode of the message is set in the SBMLCoreParser when an element message is encountered, the same way as the typeOfNotes is set earlier.
    It tried to create a model with a constraint that contain notes and message and the read/write seems to be working fine, I am not sure I tried the getMessageString() though.

    Also, I close the first bug report but it is open for comments so you could have put your comment there.

     
  • sebastian-f
    sebastian-f
    2011-03-04

    • status: pending-works-for-me --> open-works-for-me
     
  • sebastian-f
    sebastian-f
    2011-03-04

    Okay, I think I get it. The namespace used for messages is
    "http://www.w3.org/1999/xhtml".
    The parser for this namespace is StringParser (file PackageParserNamespaces.xml):
    line:
    <entry key="http://www.w3.org/1999/xhtml">
    org.sbml.jsbml.xml.parsers.StringParser
    </entry>

    The Code in SBMLCoreParser for a message tag in constraint is never executed.

     
  • Then this was your SBML file that was wrong ?
    Not sure how we could prevent that and send a nice error message or warning. May be we could test if an element named message or notes is sent to the StringParser and in this case sent a warning message to the user saying that there is probably something wrong with their model. In this case, the test to see if getMessage() or getNotes() return null make more sense so I will had them.

     
  • sebastian-f
    sebastian-f
    2011-03-13

    I think its a bit difficult. The specification L3V1 §4.10 says, that the content of the message-tag has the namespace xhtml.
    So I thought that the sbml-file could look like:
    ...
    <message xmlns:xhtml="http://www.w3.org/1999/xhtml">
    ...
    </message>
    ...

    the following fragment would be parsed by SBMLCoreParser:
    ...
    <message>
    ...
    </message>
    ...

    while the first fragment with namespace would be parsed by StringParser.
    I think both solutions are conform with L3V1 §4.10.

     
  • Yes, written like that, the first fragment should be valid and the message element should be processed by the SBMLCoreParser. I will have a look at it.

     
    • status: open-works-for-me --> open-accepted
     
  • I don't understand why it is necessary to access the parentSBMLElement? This might be null in some cases. What is it needed for? It seems the code fragment above should be placed in some child of Constraint, but where?

     
  • Andreas, this code is a part of the parsing, in StringParser.processStartElement and it is working fine.

    The problem is happening if you define the xhtml namespace in the message element instead of in the actual html code like it is done in general.

    Something like that :
    <message xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xhtml:p>Constraint message</xhtml:p>
    </message>

    For me, the parsing is working fine but the namespace is not written out again on the message element when writting back the sbml model, the problem is that in general we are not trying to check if there is any namespaces to write in standard element which we will nee to do anyway to support the SBML level 3 packages where a namespace declaration could happen more or less anywhere.

     
    • milestone: --> jsbml 1.0
     
    • Group: jsbml 1.0 --> jsbml 1.2