[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Thu Oct 27 04:15:23 UTC 2005


senger
Thu Oct 27 00:15:23 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv2749/src/main/org/biomoby/client

Modified Files:
	CentralDigestCachedImpl.java CentralDigestImpl.java 
	CentralImpl.java GraphsServlet.java 
Log Message:


moby-live/Java/src/main/org/biomoby/client CentralDigestCachedImpl.java,1.10,1.11 CentralDigestImpl.java,1.7,1.8 CentralImpl.java,1.29,1.30 GraphsServlet.java,1.12,1.13
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2005/10/22 01:38:04	1.10
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2005/10/27 04:15:23	1.11
@@ -6,6 +6,14 @@
 
 package org.biomoby.client;
 
+import org.biomoby.shared.CentralAll;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyService;
+import org.biomoby.shared.MobyServiceType;
+import org.biomoby.shared.NoSuccessException;
+
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.File;
@@ -20,13 +28,6 @@
 import java.util.Arrays;
 import java.util.Comparator;
 
-import org.biomoby.shared.CentralAll;
-import org.biomoby.shared.MobyDataType;
-import org.biomoby.shared.MobyException;
-import org.biomoby.shared.MobyService;
-import org.biomoby.shared.MobyServiceType;
-import org.biomoby.shared.NoSuccessException;
-
 /**
  * An implementation of {@link org.biomoby.shared.CentralAll},
  * allowing to cache locally results of the cumulative methods so it
@@ -325,7 +326,7 @@
 	if (list == null || list.length == 0)
 	    return true;
 	for (int i = 0; i < list.length; i++) {
-	    if ( ! ignored (new File (list[i])) )
+	    if ( ! ignoredForEmptiness (new File (list[i])) )
 		return false;
 	}
 	return true;
@@ -403,11 +404,10 @@
 	    fireEvent (SERVICE_TYPES_START);
 	    String typesAsXML = getServiceTypesAsXML();
 	    store (serviceTypesCache, LIST_FILE, typesAsXML);
-	    Map types = createServiceTypesFromXML (typesAsXML);
-	    fireEvent (SERVICE_TYPES_COUNT, new Integer (types.size()));
-	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
-		Map.Entry entry = (Map.Entry)it.next();
-		String name = (String)entry.getKey();
+	    MobyServiceType[] types = createServiceTypesFromXML (typesAsXML);
+	    fireEvent (SERVICE_TYPES_COUNT, new Integer (types.length));
+	    for (int i = 0 ; i < types.length; i++) {
+		String name = types[i].getName();
 		fireEvent (SERVICE_TYPE_LOADING, name);
 		String xml = getServiceTypeRelationshipsAsXML (name, false);
 		store (serviceTypesCache, name, xml);
@@ -556,11 +556,10 @@
     /*************************************************************************
      *
      *************************************************************************/
-//     public MobyNamespace[] getNamespaces()   //TBD: later, when API allows it
-    public Map getNamespaces()
+    public MobyNamespace[] getFullNamespaces()
 	throws MobyException {
 	if (namespacesCache == null)
-	    return super.getNamespaces();
+	    return super.getFullNamespaces();
 	synchronized (namespacesCache) {
 	    if (isCacheEmpty (namespacesCache)) {
 		initCache();
@@ -590,26 +589,19 @@
 
 	    // get a list file (with all service type names)
 	    String xmlList = getListFile (serviceTypesCache);
-	    Map types = createServiceTypesFromXML (xmlList);
+	    MobyServiceType[] types = createServiceTypesFromXML (xmlList);
 
-	    // get individual (almost) full service types
-	    Vector v = new Vector();
-	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
-		Map.Entry entry = (Map.Entry)it.next();
-		String name = (String)entry.getKey();
+	    // add details about relationship to get full service types
+	    for (int i = 0; i < types.length; i++) {
+		String name = types[i].getName();
 		File file = new File (serviceTypesCache, name);
 		try {
-		    MobyServiceType serviceType = new MobyServiceType (name);
-		    serviceType.setParentNames (createServiceTypeRelationshipsFromXML (load (file)));
-		    serviceType.setDescription ((String)entry.getValue());
-		    v.addElement (serviceType);
+		    types[i].setParentNames (createServiceTypeRelationshipsFromXML (load (file)));
 		} catch (MobyException e) {
 		    System.err.println (MSG_CACHE_BAD_FILE (file, e));
 		}
 	    }
-	    MobyServiceType[] result = new MobyServiceType [v.size()];
-	    v.copyInto (result);
-	    return result;
+	    return types;
 	}
     }
 
@@ -646,6 +638,15 @@
     }
 
     /**************************************************************************
+     * Some file (when a cache is being tested fir emptyness) are ignored.
+     *************************************************************************/
+    protected static boolean ignoredForEmptiness (File file) {
+	String path = file.getPath();
+	return
+	    path.endsWith ("~");
+    }
+
+    /**************************************************************************
      *
      *************************************************************************/
     protected static String MSG_CACHE_NOT_DIR (File cache) {

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java	2005/10/22 01:38:04	1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java	2005/10/27 04:15:23	1.8
@@ -145,33 +145,13 @@
     /*************************************************************************
      * Physically gather together all namespaces. It is not that hard
      * (comparing to other Biomoby entities) because all namespaces
-     * are delivered by a single call to Biomoby. This method differs
-     * form the Central.getNamespaces() in the type of returned
-     * result, and - hopefully in the future - also in the amount of
-     * information stored in the returned value (but at the monent,
-     * because of a limitation of the Biomoby API, both result types
-     * contain the same information).
+     * are delivered by a single call to Biomoby.
      *************************************************************************/
     protected MobyNamespace[] readNamespaces()
 	throws MobyException {
 	try {
 	    fireEvent (NAMESPACES_START);
-	    Map names = getNamespaces();
-	    fireEvent (NAMESPACES_COUNT, new Integer (names.size()));
-	    MobyNamespace[] result = new MobyNamespace [ names.size() ];
-	    int i = 0;
-	    for (Iterator it = names.entrySet().iterator(); it.hasNext(); ) {
-		Map.Entry entry = (Map.Entry)it.next();
-		String name = (String)entry.getKey();
-		MobyNamespace ns = new MobyNamespace (name);
-		ns.setDescription ((String)entry.getValue());
-		result[i++] = ns;
-		fireEvent (NAMESPACE_LOADED, name, ns);
-	    }
-	    return result;
-
-	} catch (Exception e) {
-	    throw new MobyException (formatException (e));
+	    return super.getFullNamespaces();
 	} finally {
 	    fireEvent (NAMESPACES_END);
 	}

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2005/10/12 11:36:59	1.29
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2005/10/27 04:15:23	1.30
@@ -560,6 +560,14 @@
 	return value;
     }
 
+    protected String getFirstValue (NodeList children) {
+	if (children.item(0) != null && children.item(0).hasChildNodes()) {
+	    children.item(0).normalize();
+	    return getFirstValue (children.item(0));
+	}
+	return "";
+    }
+
     /**************************************************************************
      * 
      * Implementing SimpleCache interface.
@@ -784,8 +792,10 @@
      * Parses and imports the following XML.
      * <pre>
      *  &lt;serviceTypes&gt;
-     *     &lt;serviceType name="serviceName"&gt;
+     *     &lt;serviceType name="serviceName" lsid="..."&gt;
      *            &lt;Description&gt;&lt;![CDATA[free text description here]]&gt;&lt;/Description&gt;
+     *            &lt;contactEmail&gt;...&lt;/contactEmail&gt;
+     *            &lt;authURI&gt;...&lt;/authURI&gt;
      *     &lt;/serviceType&gt;
      *          ...
      *          ...
@@ -795,7 +805,13 @@
     public Map getServiceTypes()
 	throws MobyException {
 	String result = getServiceTypesAsXML();
-	return createServiceTypesFromXML (result);
+ 	Map results = new TreeMap (getStringComparator());
+	MobyServiceType[] types = createServiceTypesFromXML (result);
+	for (int i = 0; i < types.length; i++) {
+	    results.put (types[i].getName(),
+			 types[i].getDescription());
+	}
+	return results;
     }
 
     //
@@ -805,29 +821,33 @@
 			       new Object[] {});
     }
 
-    //
-    protected Map createServiceTypesFromXML (String result)
+    // but be aware that the created MobyServiceTypes are not complete
+    // - they do not have the relationship information; that's why
+    // this method is not public; the full service types are available
+    // from CentralDigest implementations
+    protected MobyServiceType[] createServiceTypesFromXML (String result)
 	throws MobyException {
 
 	// parse returned XML
-	Map results = new TreeMap (getStringComparator());
 	Document document = null;
 	try {
 	    document = docBuilder.parse(new ByteArrayInputStream(result.getBytes()));}
 	catch(Exception e){throw new MobyException(e.toString());}
 
 	NodeList list = document.getElementsByTagName ("serviceType");
+	if (list == null || list.getLength() == 0)
+	    return new MobyServiceType[] {};
+	MobyServiceType[] results = new MobyServiceType [list.getLength()];
 	for (int i = 0; i < list.getLength(); i++) {
 	    Element elem = (Element)list.item (i);
-	    NodeList children = elem.getChildNodes();
-	    for (int j = 0; j < children.getLength(); j++) {
-		if (children.item (j).getNodeName().equals ("Description")) {
-		    results.put (elem.getAttribute ("name"),
-				 getFirstValue (children.item (j)));
-		    break;
-		}
-	    }
+	    MobyServiceType st = new MobyServiceType (elem.getAttribute ("name"));
+	    st.setLSID (elem.getAttribute ("lsid"));
+	    st.setDescription (getFirstValue (elem.getElementsByTagName ("Description")));
+	    st.setEmailContact (getFirstValue (elem.getElementsByTagName ("contactEmail")));
+	    st.setAuthority (getFirstValue (elem.getElementsByTagName ("authURI")));
+	    results[i] = st;
 	}
+ 	java.util.Arrays.sort (results);
 	return results;
     }
 
@@ -835,15 +855,17 @@
      * Parses and imports the following XML.
      * <pre>
      *  &lt;Namespaces&gt;
-     *     &lt;Namespace name="namespace"&gt;
+     *     &lt;Namespace name="namespace" lsid="..."&gt;
      *            &lt;Description&gt;&lt;![CDATA[free text description here]]&gt;&lt;/Description&gt;
+     *            &lt;contactEmail&gt;...&lt;/contactEmail&gt;
+     *            &lt;authURI&gt;...&lt;/authURI&gt;
      *     &lt;/Namespace&gt;
      *          ...
      *          ...
      *  &lt;/Namespaces&gt;
      * </pre>
      *************************************************************************/
-    public Map getNamespaces()
+    public MobyNamespace[] getFullNamespaces()
 	throws MobyException {
 
 	String result = getNamespacesAsXML();
@@ -858,11 +880,10 @@
     }
 
     //
-    protected Map createNamespacesFromXML (String result)
+    protected MobyNamespace[] createNamespacesFromXML (String result)
 	throws MobyException {
 
 	// parse returned XML
-	Map results = new TreeMap (getStringComparator());
 	Document document = null;
 	try {
 	    document = docBuilder.parse(new ByteArrayInputStream(result.getBytes()));
@@ -872,25 +893,35 @@
 
 	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());
+	    return new MobyNamespace[] {};
 	}
-	int length = list.getLength();
-	for (int i = 0; i < length; i++) {
+	MobyNamespace[] results = new MobyNamespace [list.getLength()];
+	for (int i = 0; i < list.getLength(); i++) {
 	    Element elem = (Element)list.item (i);
-	    NodeList children = elem.getElementsByTagName("Description");
-	    if (children.item(0).hasChildNodes()) {
-		children.item(0).normalize();
-		results.put (elem.getAttribute ("name"),
-			     getFirstValue (children.item(0)));
+	    MobyNamespace nm = new MobyNamespace (elem.getAttribute ("name"));
+	    nm.setLSID (elem.getAttribute ("lsid"));
+	    nm.setDescription (getFirstValue (elem.getElementsByTagName ("Description")));
+	    nm.setEmailContact (getFirstValue (elem.getElementsByTagName ("contactEmail")));
+	    nm.setAuthority (getFirstValue (elem.getElementsByTagName ("authURI")));
+	    results[i] = nm;
+	}
 
+ 	java.util.Arrays.sort (results);
+	return results;
+    }
 
-	    } else {
-		// No description provided
-		results.put (elem.getAttribute ("name"), "");
-	    }
-	}
+    /**************************************************************************
+     *
+     *************************************************************************/
+    public Map getNamespaces()
+	throws MobyException {
 
+ 	Map results = new TreeMap (getStringComparator());
+	MobyNamespace[] namespaces = getFullNamespaces();
+	for (int i = 0; i < namespaces.length; i++) {
+	    results.put (namespaces[i].getName(),
+			 namespaces[i].getDescription());
+	}
 	return results;
     }
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java	2005/09/22 16:07:09	1.12
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java	2005/10/27 04:15:23	1.13
@@ -423,12 +423,13 @@
 
 	MobyService[] services = null;
 	MobyDataType[] dataTypes = null;
-	Map namespaces = null;
+// 	Map namespaces = null;
+	MobyNamespace[] namespaces = null;
 	try {
 	    readRegistryIfNeeded();
 	    services = registry.getServices();
 	    dataTypes = registry.getDataTypes();
-	    namespaces  = registry.getNamespaces();
+	    namespaces  = registry.getFullNamespaces();
 	    lastRead = getLastRead();
 	} catch (MobyException e) {
  	    error (res, HttpServletResponse.SC_SERVICE_UNAVAILABLE, e);
@@ -570,10 +571,13 @@
 	String selectData2 = h.list (attrs, dataLabels, null, selected);
 
 	Vector v = new Vector();
-	for (Iterator it = namespaces.entrySet().iterator(); it.hasNext(); ) {
-	    Map.Entry entry = (Map.Entry)it.next();
-	    v.addElement (entry.getKey());
+	for (int i = 0; i < namespaces.length; i++) {
+	    v.addElement (namespaces[i].getName());
 	}
+// 	for (Iterator it = namespaces.entrySet().iterator(); it.hasNext(); ) {
+// 	    Map.Entry entry = (Map.Entry)it.next();
+// 	    v.addElement (entry.getKey());
+// 	}
 	new Sorter().sort (v);
 	v.insertElementAt (WITHOUT_NAMESPACE, 0);
 	String[] nsLabels = new String [v.size()];




More information about the MOBY-guts mailing list