[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Thu Aug 4 04:13:31 UTC 2005
gordonp
Thu Aug 4 00:13:31 EDT 2005
Update of /home/repository/moby/moby-live/Java/docs
In directory pub.open-bio.org:/tmp/cvs-serv6161
Modified Files:
SimpleClient.html
Log Message:
Incremental update
moby-live/Java/docs SimpleClient.html,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/docs/SimpleClient.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/04 02:50:31 1.4
+++ /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/04 04:13:31 1.5
@@ -200,18 +200,37 @@
</p>
<h3>Dissecting queries and responses</h3>
+<p>If we were a service provider who received a MobyDataInstance, we can check its type, then dissect it
+and extract the fields. Suppose we are a PSI-BLAST provider. We accept <em>AminoAcidSequence</em>:
+
+<blockquote><code><pre>
+//...receive data (see last section of this tutorial), a MobyDataInstance called "data"
+if(! data.getDataType().getName().equals("AminoAcidSequence")){
+ throw new MobyException("Expected an AminoAcidSequence, but instead found " + data.getDataType());
+}
+String aaSequence = ((MobyDataString) data.get("SequenceString")).toString();
+int aaLength = ((MobyDataInt) data.get("Length")).intValue(); // Like java.lang.Number.intValue()
+</pre></code></blockquote>
+
+Two notes about this example: 1. eventually we should have a method in <code>MobyDataType</code> with the signature <code>inheritsFrom(MobyDataType)</code>, as this would allow us to easily validate input that is a subclass of <em>AminoAcidSequence</em>, and 2. I have assumed that the length of the sequence is not greater than the maximum capacity of a Java integer. If the field I was dealing with may be larger than 2 to the 32nd power, I should call <code>longValue()</code> or even better <code>getObject()</code> which returns an infinite precision <code>BigInteger</code>.
<h3>Changing data objects</h3>
<p>The <code>getObject</code> method allows the user to retrieve the underlying internal
representation of the MOBY data in any <code>MobyDataInstance</code>. The returned <code>Object</code> can be safely
cast as listed <a href="#primitives">in the primitives table above</a>, <code>MobyDataComposite</code>
uses a <code>HashMap</code>, <code>MobyDataObjectSet</code> uses a <code>Vector</code>. Modifying mutable returned
-object modifies the MobyDataObject from which it came. For example:
+object modifies the MobyDataObject from which it came. For example, building on the previous example:
<blockquote><code><pre>
+StringBuffer mutableSequence = (StringBuffer) ((MobyDataString) data.get("SequenceString")).getObject();
+mutableSequence.replace(0, 2, "XXX");
+data.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+System.out.println(data.toXML());
</pre></code></blockquote>
+This would print the sequence XML, with the first three letters of the sequence string being "XXX". Note that you do have to do some casting to get all of these data right. When jMOBY requires Java 1.5, we can get rid of several of these cast annoyances by using the Generics construct.
+
</p>
<hr/>
@@ -250,7 +269,7 @@
<h3>Create a MOBY XML response or query envelope with multiple invocations</h3>
<p>
Use the default constructor for <code>MobyContentInstance</code>, then add at least one <code>MobyDataInstance</code>
-to it using the <code>java.lang.Map</code> interface or the convenient one-arg <code>put</code> method.
+to it using the <code>java.lang.Map</code> interface or the convenient one-arg <code>put</code> method. To clarify, sending the content block to a service provider is requesting that a service acting on a <code>gi</code> namespace object be invoked for two separate input data. We are not calling a service that takes two MOBY <em>Object</em>s as input.
<blockquote><code><pre>
MobyContentInstance queries = new MobyContentInstance();
data.put(new MobyDataObject("gi", "100089"));
@@ -261,10 +280,11 @@
<a name="parsingMOBYXML"/>
<h2>Parsing MOBY XML</h2>
-<p>As a counterpart to the utility above, jMOBY provides a method to deserialize a response/request envelope:
+<p>As a counterpart to the utility above, jMOBY provides a method to deserialize a response/request envelope, useful if you are rolling your own server:
<blockquote><code><pre>
MobyContentInstance queries = MobyDataUtils.fromXMLDocument(System.in);
System.out.println("The document contained " + ((queries.size() == 1) ? "1 query" : (query.size() + " queries")));
+//Use the HashMap functions to retrieve individual queries...
</pre></code></blockquote>
</p>
@@ -273,7 +293,7 @@
<address><a href="mailto:gordonp at ucalgary.ca">Paul Gordon</a></address>
<!-- Created: Wed Jul 20 11:44:30 MDT 2005 -->
<!-- hhmts start -->
-Last modified: Fri Jul 22 22:13:34 MDT 2005
+Last modified: Wed Aug 3 23:08:06 MDT 2005
<!-- hhmts end -->
</body>
</html>
More information about the MOBY-guts
mailing list