[MOBY-l] MobyRequest or CentralImpl ?

Paul Gordon gordonp at cbr.nrc.ca
Fri May 21 14:12:48 UTC 2004


> In response to my own question regarding building a GenericSequence 
> query object, the following bit of code does the job but I feel like 
> I'm missing something. 
>        MobyDataType the_type = new MobyDataType("");
>        the_type = central.getDataType("GenericSequence");
>        String seq_object =    "<moby:GenericSequence namespace='' 
> id=''>"+
>            "<moby:String namespace='' id='' 
> articleName='SequenceString'>"+query+"</moby:String>"+
>            "</moby:GenericSequence>";
>        MobyDataSimpleInstance mobySimpleInstance = new 
> MobyDataSimpleInstance(the_type,"","");
>        mobySimpleInstance.setValue(seq_object);      
> It looks like the only alternative is to build the object as a DOM, 
> but not being familiar with DOM building this seems like more trouble 
> than its worth.  Please, show me the path to enlightenment and 
> intelligent creation of moby objects in Java.

This is indeed the way to build the object, as per the comments in my 
example class. I was hoping that by making direct string XML input 
inconvenient, people would pay more attention to making sure the 
declared data type and XML corresponded, and were correct.  The fact 
that you can't build an instance directly from a string is explicitly 
stated in the javadocs, you have to call setValue().  But if you really 
want to add a constructor with an extra argument you can, it's open 
source.  Even better, someone could make setValue() parse the XML string 
and check it against the Moby Object ontology for validity :-)

There is a error in your XML: according to 
http://mobycentral.cbr.nrc.ca/cgi-bin/types/Objects , GenericSequence is 
a subclass of VirtualSequence, which hasa Integer(Length).  So you 
should also have in the encapsulating GenericSequence a tag like

<moby:Integer moby:namespace="" moby:id="" ></moby:Integer>

This brings up a new issue though that requires a policy formulation on 
the part of the community:  Suppose VirtualSequence had two Integer 
members, how would these be distinguished in the XML (i..e the Length 
field vs. the foo field)?  There are no examples in the 0.7 API 
distinguishing object members by name.  Should we not make articleName a 
required attribute when there is more than one component to an object?

Once we've resolved this, I'll make the automatic creation of XML for 
primitives part of the MobyDataSimpleInstance (like base Object creation 
is now), so creating more complicated objects is just a question of 
collating other instance of the same class.  This should avoid a lot of 
the query formulation issues, as you'll never be inputting XML directly 
(unless of course your object is a subclass of the text-xml object).






More information about the moby-l mailing list