[MOBY-guts] biomoby commit
senger@ebi.ac.uk
senger at pub.open-bio.org
Wed Sep 22 21:11:17 UTC 2004
senger
Wed Sep 22 17:11:17 EDT 2004
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv15476/src/main/org/biomoby/client
Modified Files:
CentralImpl.java Graphviz.java
Log Message:
new registration procedure, etc.
moby-live/Java/src/main/org/biomoby/client CentralImpl.java,1.13,1.14 Graphviz.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2004/05/18 10:13:17 1.13
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2004/09/22 21:11:17 1.14
@@ -178,30 +178,37 @@
* Parse the given XML sniplet to find tag 'success'. If it has value '1'
* look further for tag 'id' and return it back (or return an empty string
* if ID is not there). Otherwise raise an exception with the 'culprit'
- * and with the message from the tag 'message'.
+ * and with the message from the tag 'message'. <p>
+ *
+ * The return value is a two-element long array. The first element
+ * is the ID (given by BioMobe registry), and the second element
+ * is RDF corresponding with the registered object (BioMoby
+ * returns this only for service instances, so for other objects
+ * this will be null). <p>
*
* This is how the XML is supposed to look:
* <MOBYRegistration>
* <success> <!-- 1 | 0 | -1 --> </success>
* <id> <!-- some id number for your registration --> </id>
* <message> <![CDATA[message here]]> </message>
+ * <RDF> <!-- RDF of your service instance here (if applicable) --> </RDF>
* </MOBYRegistration>
*
* Success takes the value "1" to indicate success, "0" to
* indicate failure, and "-1" to indicate "Pending Curation".
- *
- * I keep 'id' in but it does not seem to be used anymore by the current
- * Moby Central.
*************************************************************************/
- protected String checkRegistration (String xml, Object culprit)
+ protected String[] checkRegistration (String xml, Object culprit)
throws MobyException, NoSuccessException, PendingCurationException {
- String id = "", success = "0", message = "";
+ String id = "", success = "0", message = "", rdf = "";
// parse returned XML
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(xml));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document=docBuilder.parse(new StringBufferInputStream(xml));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
Element root = document.getDocumentElement();
NodeList children = root.getChildNodes();
@@ -212,12 +219,23 @@
if (elem.getNodeName().equals ("id")) {
if (elem.getFirstChild() != null)
id = elem.getFirstChild().getNodeValue();
- } else if (elem.getNodeName().equals ("success")) {
+ } else if (elem.getNodeName().equals("success")) {
if (elem.getFirstChild() != null)
success = elem.getFirstChild().getNodeValue();
} else if (elem.getNodeName().equals ("message")) {
if (elem.getFirstChild() != null)
message = elem.getFirstChild().getNodeValue();
+ } else if (elem.getNodeName().equals ("RDF")) {
+ // well, this is a simple, but most time working,
+ // hack... I actually do not know how to extract the
+ // whole subtree from a Document (without using XPath,
+ // XSLT or similar) ... let me know please if you know
+ int fromPos = xml.indexOf ("<RDF>");
+ int toPos = xml.indexOf ("</RDF>");
+ if (fromPos > -1 && toPos > fromPos)
+ rdf = xml.substring (fromPos, toPos + 6);
+// if (elem.getFirstChild() != null)
+// rdf = elem.getFirstChild().getNodeValue();
}
}
@@ -225,7 +243,7 @@
throw new NoSuccessException (message, culprit);
else if (success.equals ("-1"))
throw new PendingCurationException();
- return id;
+ return new String[] { id, rdf };
}
/**************************************************************************
@@ -414,8 +432,11 @@
throws MobyException {
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(xml));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(xml));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getElementsByTagName ("Service");
MobyService[] results = new MobyService [list.getLength()];
@@ -506,7 +527,7 @@
// First, check to se if we have the values cached from a previous call
// in this instance
- if(useCache && cache.containsKey("retrieveServiceNames"))
+ if (useCache && cache.containsKey("retrieveServiceNames"))
return (Map) cache.get("retrieveServiceNames");
String result = (String)doCall ("retrieveServiceNames",
@@ -515,8 +536,11 @@
// parse returned XML
Map results = new HashMap();
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getElementsByTagName ("serviceName");
for (int i = 0; i < list.getLength(); i++) {
@@ -526,7 +550,7 @@
}
// Add this data to the cache in case we get called again
- if(useCache)
+ if (useCache)
cache.put("retrieveServiceNames", results);
return results;
}
@@ -543,16 +567,19 @@
throws MobyException {
// First, see if we have the values cached from a previous call in this instance
- if(useCache && cache.containsKey("retrieveServiceProviders"))
- return (String[]) cache.get("retrieveServiceProviders");
+ if (useCache && cache.containsKey ("retrieveServiceProviders"))
+ return (String[]) cache.get ("retrieveServiceProviders");
String result = (String)doCall ("retrieveServiceProviders",
new Object[] {});
// parse returned XML
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getElementsByTagName ("serviceProvider");
String[] results = new String [list.getLength()];
@@ -560,7 +587,7 @@
results[i] = ((Element)list.item (i)).getAttribute ("name");
// Add this data to the cache in case we get called again
- if(useCache)
+ if (useCache)
cache.put("retrieveServiceProviders", results);
return results;
}
@@ -579,7 +606,7 @@
public Map getServiceTypes()
throws MobyException {
// First, see if we have the values cached from a previous call in this instance
- if(useCache && cache.containsKey("retrieveServiceTypes"))
+ if (useCache && cache.containsKey ("retrieveServiceTypes"))
return (Map) cache.get("retrieveServiceTypes");
String result = (String)doCall ("retrieveServiceTypes",
@@ -588,7 +615,8 @@
// parse returned XML
Map results = new HashMap();
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));}
catch(Exception e){throw new MobyException(e.toString());}
NodeList list = document.getElementsByTagName ("serviceType");
@@ -634,31 +662,33 @@
// parse returned XML
Map results = new HashMap();
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getDocumentElement().getElementsByTagName ("Namespace");
- if(list == null || list.getLength() == 0){
- throw new MobyException("Could not find Namespace children of response root node " +
- document.getDocumentElement());
+ if (list == null || list.getLength() == 0) {
+ throw new MobyException ("Could not find Namespace children of response root node " +
+ document.getDocumentElement());
}
int length = list.getLength();
for (int i = 0; i < length; i++) {
Element elem = (Element)list.item (i);
NodeList children = elem.getElementsByTagName("Description");
- if(children.item(0).hasChildNodes()){
+ if (children.item(0).hasChildNodes()) {
children.item(0).normalize();
results.put (elem.getAttribute ("name"),
children.item(0).getFirstChild().getNodeValue());
- }
- else{
+ } else {
// No description provided
results.put (elem.getAttribute ("name"), "");
}
}
-
+
// Add this data to the cache in case we get called again
- if(useCache)
+ if (useCache)
cache.put("retrieveNamespaces", results);
return results;
}
@@ -677,7 +707,7 @@
public Map getDataTypeNames()
throws MobyException {
// First, see if we have the values cached from a previous call in this instance
- if(useCache && cache.containsKey("retrieveObjectNames"))
+ if (useCache && cache.containsKey("retrieveObjectNames"))
return (Map) cache.get("retrieveObjectNames");
String result = (String)doCall ("retrieveObjectNames",
@@ -686,8 +716,11 @@
// parse returned XML
Map results = new HashMap();
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getElementsByTagName ("Object");
for (int i = 0; i < list.getLength(); i++) {
@@ -702,7 +735,7 @@
}
}
- if(useCache)
+ if (useCache)
cache.put("retrieveObjectNames", results);
return results;
}
@@ -723,6 +756,10 @@
* <objectType articleName='Term'>urn:lsid:biomoby.org:objectclass:string</objectType>
* <objectType articleName='Definition'>urn:lsid:biomoby.org:objectclass:string</objectType>
* </Relationship>
+ * <Relationship relationshipType='urn:lsid:biomoby.org:objectrelation:has'>
+ * <objectType articleName='Problems'>urn:lsid:biomoby.org:objectclass:string</objectType>
+ * <objectType articleName='Issues'>urn:lsid:biomoby.org:objectclass:string</objectType>
+ * </Relationship>
* </retrieveObjectDefinition>
*
*************************************************************************/
@@ -730,9 +767,9 @@
throws MobyException, NoSuccessException {
// See if we've already retrieved the DataType and cached it
- if(cache.containsKey("retrieveObjectDefinition"+dataTypeName))
- return (MobyDataType) cache.get("retrieveObjectDefinition"+dataTypeName);
-
+ if (cache.containsKey("retrieveObjectDefinition" + dataTypeName))
+ return (MobyDataType) cache.get("retrieveObjectDefinition" + dataTypeName);
+
String result =
(String)doCall ("retrieveObjectDefinition",
new Object[] {
@@ -743,18 +780,21 @@
// parse returned XML
Document document = null;
- try{document=docBuilder.parse(new StringBufferInputStream(result));}
- catch(Exception e){throw new MobyException(e.toString());}
+ try {
+ document = docBuilder.parse(new StringBufferInputStream(result));
+ } catch (Exception e) {
+ throw new MobyException(e.toString());
+ }
NodeList list = document.getElementsByTagName ("retrieveObjectDefinition");
if (list == null || list.getLength() == 0)
- throw new NoSuccessException ("Data Type name was not founnd.",
+ throw new NoSuccessException ("Data Type name was not found.",
dataTypeName);
MobyDataType data = null;
Element elem = (Element)list.item (0);
NodeList children = elem.getChildNodes();
- // first find the "real" data type name
+ // first find the "real" (LSID-ized) data type name
for (int j = 0; j < children.getLength(); j++) {
String nodeName = children.item (j).getNodeName();
if (nodeName.equals ("objectType")) {
@@ -792,7 +832,18 @@
for (int k = 0; k < belows.getLength(); k++) {
if (belows.item (k).getNodeName().equals ("objectType")) {
data.addChild ( ((Element)belows.item (k)).getAttribute ("articleName"),
- belows.item (k).getFirstChild().getNodeValue() );
+ belows.item (k).getFirstChild().getNodeValue(),
+ MobyRelationship.HASA );
+ }
+ }
+ } else if (relationshipType.endsWith ("has")) {
+
+ NodeList belows = children.item (j).getChildNodes();
+ for (int k = 0; k < belows.getLength(); k++) {
+ if (belows.item (k).getNodeName().equals ("objectType")) {
+ data.addChild ( ((Element)belows.item (k)).getAttribute ("articleName"),
+ belows.item (k).getFirstChild().getNodeValue(),
+ MobyRelationship.HAS );
}
}
}
@@ -804,42 +855,6 @@
/**************************************************************************
* B
- * <Objects>
- * <Object name="ObjectOntologyTerm">
- * <Schema><![CDATA[
- * <XSD schema here>]]>
- * </Schema>
- * </Object>
- * ...
- * ...
- * </Objects>
- *
- *************************************************************************/
-// public String getDataType (String dataTypeName)
-// throws MobyException, NoSuccessException {
-// String result =
-// (String)doCall ("retrieveObjectSchema",
-// new Object[] {
-// "<retrieveObjectSchema>" +
-// "<objectType>" + dataTypeName + "</objectType>" +
-// "</retrieveObjectSchema>"
-// });
-
-// // parse returned XML (hack: taking blindly everything in the Schema tag)
-// String xsd = "";
-// int pos = result.indexOf ("<Schema>");
-// if (pos == 1)
-// throw new NoSuccessException ("Data Type name was not founnd.",
-// dataTypeName);
-// int pos2 = result.indexOf ("</Schema>");
-// if (pos2 < pos)
-// throw new NoSuccessException ("Something wrong with the returned XML.",
-// result);
-// return result.substring (pos + 8, pos2);
-// }
-
- /**************************************************************************
- * B
*************************************************************************/
public String getServiceWSDL (String serviceName)
throws MobyException, NoSuccessException {
@@ -889,7 +904,7 @@
}
/*************************************************************************
- * B
+ *
*************************************************************************/
public void registerDataType (MobyDataType dataType)
throws MobyException, NoSuccessException, PendingCurationException {
@@ -904,16 +919,24 @@
buf.append ("\n");
}
- // build the HASA tag (expressing containment of data types)
- Hashtable children = dataType.getChildren();
- StringBuffer buf2 = new StringBuffer();
- for (Enumeration en = children.keys(); en.hasMoreElements(); ) {
- String name = (String)en.nextElement();
- buf2.append ("<objectType articleName=\"");
- buf2.append (name);
- buf2.append ("\">");
- buf2.append (children.get (name));
- buf2.append ("</objectType>");
+ // build the HASA/HAS tags (expressing containments of data types)
+ MobyRelationship[] children = dataType.getChildren();
+ StringBuffer buf2 = new StringBuffer(); // for HASA
+ StringBuffer buf3 = new StringBuffer(); // for HAS
+ for (int i = 0; i < children.length; i++) {
+ if (children[i].getRelationshipType() == MobyRelationship.HASA) {
+ buf2.append ("<objectType articleName=\"");
+ buf2.append (children[i].getName());
+ buf2.append ("\">");
+ buf2.append (children[i].getDataTypeName());
+ buf2.append ("</objectType>");
+ } else if (children[i].getRelationshipType() == MobyRelationship.HAS) {
+ buf3.append ("<objectType articleName=\"");
+ buf3.append (children[i].getName());
+ buf3.append ("\">");
+ buf3.append (children[i].getDataTypeName());
+ buf3.append ("</objectType>");
+ }
}
String result =
@@ -927,30 +950,15 @@
"</Relationship>" +
"<Relationship relationshipType=\"HASA\">" + new String (buf2) +
"</Relationship>" +
+ "<Relationship relationshipType=\"HAS\">" + new String (buf3) +
+ "</Relationship>" +
"<authURI>" + dataType.getAuthority() + "</authURI>" +
"<contactEmail>" + dataType.getEmailContact() + "</contactEmail>" +
"</registerObjectClass>"
});
- dataType.setId (checkRegistration (result, dataType));
+ dataType.setId (checkRegistration (result, dataType)[0]);
}
-// <registerObjectClass>
-// <objectType>NewObjectType</objectType>
-// <Description><![CDATA[
-// human readable description
-// of data type]]>
-// </Description>
-// <Relationship relationshipType="RelationshipOntologyTerm">
-// <objectType articleName="SomeName">ExistingObjectType</objectType>
-// ...
-// ...
-// </Relationship>
-// ...
-// ...
-// <authURI>Your.URI.here</authURI>
-// <contactEmail>You at your.address.com</contactEmail>
-// </registerObjectClass>
-
/*************************************************************************
* B
*************************************************************************/
@@ -995,7 +1003,7 @@
"</Relationship>" +
"</registerServiceType>"
});
- serviceType.setId (checkRegistration (result, serviceType));
+ serviceType.setId (checkRegistration (result, serviceType)[0]);
}
// <registerServiceType>
@@ -1042,7 +1050,7 @@
"</Description>" +
"</registerNamespace>"
});
- namespace.setId (checkRegistration (result, namespace));
+ namespace.setId (checkRegistration (result, namespace)[0]);
}
/*************************************************************************
@@ -1074,6 +1082,7 @@
"<serviceName>" + service.getName() + "</serviceName>" +
"<serviceType>" + service.getType() + "</serviceType>" +
"<authURI>" + service.getAuthority() + "</authURI>" +
+ "<signatureURL>" + service.getSignatureURL() + "</signatureURL>" +
"<URL>" + service.getURL() + "</URL>" +
"<contactEmail>" + service.getEmailContact() + "</contactEmail>" +
"<authoritativeService>" + (service.isAuthoritative() ? "1" : "0") + "</authoritativeService>" +
@@ -1084,7 +1093,22 @@
buildOutputTag (service) +
"</registerService>"
});
- service.setId (checkRegistration (result, service));
+ String[] registered = checkRegistration (result, service);
+ service.setId (registered [0]);
+ service.setRDF (registered [1]);
+ String pathToRDF = service.getPathToRDF();
+ if ( ! pathToRDF.equals ("") ) {
+ File fileRDF = new File (pathToRDF);
+ try {
+ PrintStream fileout = new PrintStream (new FileOutputStream (fileRDF));
+ fileout.println (registered [1]);
+ fileout.close();
+ } catch (IOException e) {
+ throw new MobyException ("Failed to save RDF in '" + fileRDF.getAbsolutePath() + "'. " +
+ e.toString() +
+ "\nReturned RDF:\n" + registered [1]);
+ }
+ }
}
/*************************************************************************
@@ -1390,11 +1414,13 @@
}
/**
- * By default, caching is enabled to reduce network traffic and XML parsing. Setting
- * this to false will clear the cache, and not cache any further calls unless it is
- * set to true again.
- *
- * @param shouldCache whether retrieveXXX call results should be cached in case they are called again (i.e. don't requery MobyCentral every time)
+ * By default, caching is enabled to reduce network traffic.
+ * Setting this to false will clear the cache, and not cache any
+ * further calls unless it is set to true again. <p>
+ *
+ * @param shouldCache whether retrieveXXX call results should be
+ * cached in case they are called again (i.e. don't requery
+ * MobyCentral every time)
*/
public void setCacheMode(boolean shouldCache){
useCache = shouldCache;
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java 2003/11/25 13:18:10 1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java 2004/09/22 21:11:17 1.3
@@ -6,11 +6,14 @@
package org.biomoby.client;
-import org.biomoby.shared.*;
-
-import java.net.*;
-import java.util.*;
-import java.io.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyRelationship;
+import org.biomoby.shared.MobyServiceType;
+import org.biomoby.shared.Utils;
/**
* A utility class that understands how to create
@@ -134,15 +137,15 @@
buf.append (trName (name));
buf.append (";\n");
}
- Hashtable children = type.getChildren();
- if (children.size() > 0) {
+ MobyRelationship[] children = type.getChildren();
+ if (children.length > 0) {
String dummyName = trName (name) + "_HASA";
buf.append ("\t" + trName (name) + " -> " + dummyName);
buf.append (" [style=dotted,dir=forward,arrowhead=none,arrowtail=ediamond];\n");
StringBuffer hasaBuf = new StringBuffer();
- for (Enumeration en = children.keys(); en.hasMoreElements(); ) {
- String childName = (String)en.nextElement();
- String childType = Utils.pureName ((String)children.get (childName));
+ for (int i = 0; i < children.length; i++) {
+ String childName = Utils.pureName (children[i].getName());
+ String childType = Utils.pureName (children[i].getDataTypeName());
if (childType == null)
childType = "n/a"; // should not happen I guess
hasaBuf.append (" | {" + childType + "|" + childName + "}");
More information about the MOBY-guts
mailing list