[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Sun Aug 7 06:30:24 UTC 2005


senger
Sun Aug  7 02:30:23 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv17247

Modified Files:
	CentralImpl.java 
Log Message:


moby-live/Java/src/main/org/biomoby/client CentralImpl.java,1.22,1.23
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2005/07/19 12:39:58	1.22
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2005/08/07 06:30:23	1.23
@@ -12,6 +12,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashMap;
@@ -38,6 +39,7 @@
 import org.biomoby.shared.NoSuccessException;
 import org.biomoby.shared.PendingCurationException;
 import org.biomoby.shared.Utils;
+import org.biomoby.shared.MobyResourceRef;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -1626,4 +1628,78 @@
 	return uri;
     }
 
+    /**************************************************************************
+     * Parses and imports the following XML.
+     * <pre>
+     * &lt;resourceURLs&gt;
+     *   &lt;Resource name="Service"         url="..." type="..."/&gt;
+     *   &lt;Resource name="Object"          url="..." type="..."/&gt;
+     *   &lt;Resource name="Namespace"       url="..." type="..."/&gt;
+     *   &lt;Resource name="ServiceInstance" url="..." type="..."/&gt;
+     *   &lt;Resource name="Full"            url="..." type="..."/&gt;
+     * &lt;/resourceURLs&gt;
+     * </pre>
+     *************************************************************************/
+    public MobyResourceRef[] getResourceRefs()
+	throws MobyException {
+
+	String cacheId = "retrieveResourceURLs";
+	MobyResourceRef[] cachedResults = (MobyResourceRef[])getContents (cacheId);
+	if (cachedResults != null)
+	    return cachedResults;
+
+	String result = (String)doCall ("retrieveResourceURLs",
+					new Object[] {});
+
+	// parse returned XML
+	Vector v = new Vector();
+	Document document = null;
+	try {
+	    document = docBuilder.parse (new ByteArrayInputStream (result.getBytes()));
+	} catch (Exception e) {
+	    throw new MobyException(e.toString());
+	}
+
+	NodeList list = document.getElementsByTagName ("Resource");
+	for (int i = 0; i < list.getLength(); i++) {
+	    Element elem = (Element)list.item (i);
+	    try {
+		v.addElement
+		    (new MobyResourceRef (elem.getAttribute ("name"),
+					  new URL ((String)elem.getAttribute ("url")),
+					  elem.getAttribute ("type")));
+	    } catch (MalformedURLException e2) {
+		if (debug)
+		    System.err.println ("Bad URL: " + elem.getAttribute ("url"));
+	    }
+	}
+
+	MobyResourceRef[] results = new MobyResourceRef [v.size()];
+	v.copyInto (results);
+
+	// Add this data to the cache in case we get called again
+	setContents (cacheId, results);
+
+	return results;
+    }
+
+    /**************************************************************************
+     *
+     *************************************************************************/
+    public InputStream getResource (String resourceName)
+	throws MobyException {
+
+	MobyResourceRef[] resourceRefs = getResourceRefs();
+	for (int i = 0; i < resourceRefs.length; i++) {
+	    if (resourceName.equalsIgnoreCase (resourceRefs[i].getResourceName())) {
+		URL url = resourceRefs[i].getResourceLocation();
+		try {
+		    return url.openStream();
+		} catch (java.io.IOException e2) {
+		    throw new MobyException (e2.toString());
+		}
+	    }
+	}
+	throw new MobyException ("No resource found for '" + resourceName + "'.");
+    }
 }




More information about the MOBY-guts mailing list