[MOBY-dev] Moby Java JAXB API

Dmitry Repchevsky dmitry.repchevski at bsc.es
Tue Nov 27 19:59:44 UTC 2007


Hello everybody,

I would like to get your opinion about the demo I made.
The demo is actually a simple Moby client which is connected to our 
repository
(http://moby-dev.inab.org/cgi-bin/MOBY-Central.pl) obtain the list of 
"simple" services (those that accepts MobyObject as input) from our url 
(inb.bsc.es) and give a possibility to call them.

The interesting thing is that the client uses its own API based on JAXB.

There are four jars you can download:

http://inb.bsc.es/java/MobyCore.jar
http://inb.bsc.es/java/MobyRegistry.jar
http://inb.bsc.es/java/MobyGenerator.jar
http://inb.bsc.es/java/MobyDemoClient.jar

with source code in:

http://inb.bsc.es/java/MobyCore-src.zip
http://inb.bsc.es/java/MobyRegistry-src.zip
http://inb.bsc.es/java/MobyGenerator-src.zip
http://inb.bsc.es/java/MobyDemoClient-src.zip

MobyCore.jar contains the API to marshall/unmarshall moby messages as 
well as call moby services.
Actually there is almost no API at all, because most of the classes are 
JAXB annotated java classes with get/set methods.

MobyCore can work without any pregenerated datatypes in this case all 
moby objects are converted to AnyMobyObject class by unmarshaller.

There is also a simple ontology generator - MobyGenerator. It connects 
to moby-central and generates JAXB annotated datatype classes with 
proper get/set methods using java inheritance for "IS" and java 
properties for HASA/HAS (in latter case List<>)

As I mentioned before there is no need to generate the ontology to work 
with API so one can use

AnyMobyObject o = AnyMobyObject("PDB-Text");
o.setMobyId("");
o.setNamespace("");
o.setArticleName("");
o.putAttribute("context", new MobyString("some text"));

or

PDB_Text o = new PDB_Text();
o.setMobyId("");
o.setNamespace("");
o.setArticleName("");
o.setContent(new MobyString("some text");

MobyRegistry is as you can guess JAXB classes to work with Registry API.
The package is still clumsy even with help from Edward Kawas, there are 
just too many classes may times duplicated...

So what it the typical use case?

Something like:

********************************************************************************
        MobyData mobyData = new MobyData("sip_1");
       
        AminoAcidSequence sequence = new AminoAcidSequence();
        sequence.setSequenceString(new 
MobyString("MKELNDLEKKYNAHIGVYALDTKSGKEVKFNSDKRFAYASTSKAINSAILLEQVPYNKLNKKVHINKDDIVAYSPILEKY" 
+
                                                  
"VGKDITLKALIEASMTYSDNTANNKIIKEIGGIKKVKQRLKELGDKVTNPVRYEIELNYYSPKSKKDTSTPAAFGKTLNK" 
+
                                                  
"LIANGKLSKENKKFLLDLMLNNKSGDTLIKDGVPKDYKVADKSGQSTYASRNDVAFVYPKGQSEPIVLVIFTNKDNKSDK" 
+
                                                  "PNDKLISETAKSVMKEF"));
        sequence.setLength(new MobyInteger(257));
       
        mobyData.addMobyDataElement(new MobySimple(sequence, "sequence"));
       
        mobyData.addParameter(new MobyParameter("scores", "25"));
        mobyData.addParameter(new MobyParameter("alignments", "2"));

        MobyMessage message = new MobyMessage(mobyData);

        MobyServiceEndpoint service = new 
MobyServiceEndpoint("http://inb.bsc.es/cgi-bin/mobyServices/dispatchers/asyncDispatcher.cgi", 
"runNCBITBlastn");
       
        MobyMessage m = service.call(message);
       
        if (m.hasExceptions())
        {
            List<MobyException> exceptions = m.getExceptions();
           
            for (MobyException ex : exceptions)
            {
                System.out.print(ex.getSeverity().name());
                System.out.print(" ");
                System.out.print(ex.getRefQueryID());
                System.out.print(" ");
                System.out.println(ex.getRefElement());
                System.out.print("---- code = ");
                System.out.print(ex.getExceptionCode());
                System.out.println("---->");
                System.out.println(ex.getExceptionMessage());
            }
        }
        else
        {
            List<MobyData> mobyDataList = m.getMobyDataList();

            for (MobyData md : mobyDataList)
            {
                MobySimple simple = md.getData(""); // article name
                BLAST_Text blast = simple.getObject();
                System.out.println("=============>\n" + 
blast.getContent().getString());  
            }
        }
********************************************************************************

Finally I would like to notice that API NEED JAX-WS 2.1. AND (at least 
MobyGenerator) Java6.
So to test it someone has to install jax-ws into endorsed directory (in 
jre/lib/ create a directory named "endorsed" and put all jax-ws packages 
into it).
JAX-WS you can download from https://jax-ws.dev.java.net/ri-download.html

Again this is the version of JAX-WS which is included in next Java 6 
update (in a few months) and what is important with update N 
(https://jdk6.dev.java.net/6uNea.html)

The demo itself is pretty simple, but I hope you will like it :-)
Just forgot - both Demo and MobyGenerator need MobyCore and MobyRegistry 
jars :-)
MobyGenerator needs JDK 6 to be able to compile generated classes 
(otherwise it creates zipped sources).

Cheers,

Dmitry









More information about the MOBY-dev mailing list