MoSeS - Moby XML Parser

The Biomoby XML parser has an obvious task: to read a Biomoby XML stream and convert it into Java objects that can be easily handled. Its job is usually hidden, a Biomoby service developer rarely calls the parser directly. But here is an example how to get parsed Biomoby XML data into a MobyPackage (note that the input XML - the parameter data in the example - can be given as a String, byte[], or a File which conveniently corresponds with the requirement from the Biomoby API):
try {
  MobyPackage mobyInput = MobyPackage.createFromXML (data);

  // here do something with 'mobyInput'

} catch (MobyException e) {
  System.out.println (e.getMessage());
}
To bring data back into XML is again simple:
try {
  // fill response data into a mobyOutput...
  MobyPackage mobyOutput = new MobyPackage();
  ...

  // and convert it into XML
  String xml = mobyOutput.toXML();

} catch (MobyException e) {
  System.out.println (e.getMessage());
}
On the other hand, what is visible to the service developers, and what they are working with often, are the Java objects created by the parser. This is a high-level overview of them, and how they correspond to the Biomoby XML tags:

Biomoby XML tag Java object
MOBY, mobyContent org.biomoby.shared.parser.MobyPackage
mobyData org.biomoby.shared.parser.MobyJob
Simple org.biomoby.shared.parser.MobySimple
Collection org.biomoby.shared.parser.MobyCollection
Parameter org.biomoby.shared.parser.MobyParameter
Object and its children org.biomoby.shared.datatypes.MobyObject
org.biomoby.shared.datatypes.MobyString
org.biomoby.shared.datatypes.MobyInteger
org.biomoby.shared.datatypes.MobyFloat
org.biomoby.shared.datatypes.MobyBoolean
org.biomoby.shared.datatypes.MobyDateTime
and all generated data types in org.biomoby.shared.datatypes.*
CrossReference org.biomoby.shared.datatypes.MobyXref
ProvisionInformation org.biomoby.shared.data.MobyProvisionInfo
A MobyPackage contains one or more MobyJobs each of them containing one "execution" (or a "query" in a Biomoby speak). Note that a Biomoby service must be able to accept more invocations (jobs, queries) from one network request. A MobyJob also carries a response from a service.

A MobyJob has the data themselves - they are either stored in MobySimples or in MobyCollections. The number and types of these MobyDataElements are defined for each Biomoby service in a Biomoby registry.

The MobySimples have data stored in various data objects - their classes are in the package org.biomoby.shared.datatypes. The primitive data types are there available directly, the other types are to be generated - see details in a separate document.

Here is a picture showing how the entities are relates:

Command-line client for the parser

As said above, a developer rarely needs to invoke the parser directly. But because the life is not perfect (yet, but with Biomoby growing it will be, of course), there are moments when we need to test either parser itself or check some XML data the users are claiming that they do not work for them. For these moments, there is a command-line client TestingMobyParser.

The program can be invoked using a script:

build/run/run-moby-parser [<options>] <filename> 
At the moment, there is no Ant's target to invoke this program.

The program takes the following options, specific for generating data types:

Option/Parameter Ant's property Meaning
<filename>   XML file to be parsed (a mandatory parameter)
-n   it does not print the parsed result (by default it does)
-r   convert back (reverse) the parsed result into XML and print it

The reverse converting (with the -r option) has an interesting usage. The resulting XML is not usually identical with the original - it may have different formatting, it probably has more XML namespace prefixes (they are everywhere), but more importantly, it may not reflect all data that was in the original input. This is because the parser ignores all values that are not carried by (and only by) the Biomoby primitives types (as it was allowed before big change in summer 2005). So you can use this option to see if your XML data are up-to-date with the Biomoby API.

Here is a typical examples of invoking the script - the input file contains an example taken from the Biomoby API documentation:

build/run/run-moby-parser -r example.xml
Authority: http://www.tempcalculator.org/meltyman
Jobs (invocations):
(1)    Query ID: a1
   Data elements:
      (Simple) Article name:
         MobyFloat, Id: 163483, Namespace: NCBI_gi
            Value: 69.8
(2)    Query ID: a2
   Data elements:
      (Simple) Article name:
         MobyFloat, Id: 635543, Namespace: NCBI_gi
            Value: 72.1

<?xml version="1.0" encoding="UTF-8"?>
<moby:MOBY xmlns:moby="http://www.biomoby.org/moby">
  <moby:mobyContent moby:authority="http://www.tempcalculator.org/meltyman">
    <moby:mobyData moby:queryID="a1">
      <moby:Simple>
        <moby:Float moby:id="163483" moby:namespace="NCBI_gi">69.8</moby:Float>
      </moby:Simple>
    </moby:mobyData>
    <moby:mobyData moby:queryID="a2">
      <moby:Simple>
        <moby:Float moby:id="635543" moby:namespace="NCBI_gi">72.1</moby:Float>
      </moby:Simple>
    </moby:mobyData>
  </moby:mobyContent>
</moby:MOBY>


Martin Senger
Last modified: Mon Aug 29 10:43:33 2005