[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Fri Aug 26 06:27:04 UTC 2005


senger
Fri Aug 26 02:27:04 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory pub.open-bio.org:/tmp/cvs-serv2547/src/main/org/biomoby/shared

Modified Files:
	MobyData.java MobyDataType.java MobyResourceRef.java 
	MobyService.java Utils.java package.html 
Removed Files:
	MobyNativeService.java MobyObject.java 
Log Message:


moby-live/Java/src/main/org/biomoby/shared MobyData.java,1.3,1.4 MobyDataType.java,1.6,1.7 MobyResourceRef.java,1.1,1.2 MobyService.java,1.5,1.6 Utils.java,1.5,1.6 package.html,1.2,1.3 MobyNativeService.java,1.2,NONE MobyObject.java,1.1,NONE
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyData.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyData.java	2005/04/07 16:37:02	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyData.java	2005/08/26 06:27:04	1.4
@@ -56,7 +56,7 @@
     }
 
     /**************************************************************************
-     * Must be overwritten byte a subclass.
+     * Must be overwritten by a subclass.
      *************************************************************************/
     abstract public String toXML();
     abstract public boolean isPrimary();

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2005/04/07 16:37:02	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2005/08/26 06:27:04	1.7
@@ -32,6 +32,7 @@
     protected String[] parentNames = new String[] { };
     protected MobyRelationship[] children = new MobyRelationship[] { };
     protected String id = null;
+    protected String comment = null;
 
     /**************************************************************************
      * Default constructor.
@@ -268,4 +269,21 @@
 	return Utils.format (this, indent);
     }
 
+    /**
+     * Return a comment that is attached to this instance. A comment
+     * can be anything and it is not meant to be used by end-users
+     * (that's why it is not included in the {@link #toString}
+     * method). It is for developers doing various tricks with these
+     * instances. <p>
+     */
+    public String getComment() {
+	return comment;
+    }
+    /**
+     * @see #getComment
+     */
+    public void setComment (String value) {
+	comment = (value == null ? "" : value);
+    }
+
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyResourceRef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyResourceRef.java	2005/08/07 06:29:58	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyResourceRef.java	2005/08/26 06:27:04	1.2
@@ -30,11 +30,11 @@
      * Normal constructor. <p>
      *
      * @param resourceName is an ontology name (must be one of these:
-     * {@link Central.SERVICE_TYPES_RESOURCE_NAME}, {@link
-     * Central.DATA_TYPES_RESOURCE_NAME}, {@link
-     * Central.NAMESPACES_RESOURCE_NAME}, {@link
-     * Central.SERVICE_INSTANCES_RESOURCE_NAME}, {@link
-     * Central.FULL_RESOURCE_NAME})
+     * {@link Central#SERVICE_TYPES_RESOURCE_NAME}, {@link
+     * Central#DATA_TYPES_RESOURCE_NAME}, {@link
+     * Central#NAMESPACES_RESOURCE_NAME}, {@link
+     * Central#SERVICE_INSTANCES_RESOURCE_NAME}, {@link
+     * Central#FULL_RESOURCE_NAME})
      *
      * @param location where this resource can be fetched from
      *

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java	2005/04/07 16:37:02	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java	2005/08/26 06:27:04	1.6
@@ -24,6 +24,18 @@
 
 public class MobyService {
 
+    /**
+     * A dummy name used for MobyService instances that do not have
+     * (yet) a real name.
+     */
+    static public final String DUMMY_NAME = "_dummy_";
+
+    /**
+     * An immutable string representing URI (namespace) of all Biomoby
+     * services.
+     */
+    static public final String BIOMOBY_SERVICE_URI = "http://biomoby.org/";
+
     protected String name;
     protected String category = "moby";
     protected String authority = "";
@@ -46,7 +58,7 @@
      * Default constructor.
      *************************************************************************/
     public MobyService() {
-	this ("_dummy_");
+	this (DUMMY_NAME);
     }
 
     /**************************************************************************
@@ -312,4 +324,8 @@
 	return new String (buf);
     }
 
+    public String toShortString() {
+	return name + " (" + authority + ")";
+    }
+
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2005/04/07 16:37:02	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/Utils.java	2005/08/26 06:27:04	1.6
@@ -7,9 +7,19 @@
 
 package org.biomoby.shared;
 
+import org.apache.axis.AxisFault;
 import javax.xml.namespace.QName;
 
-import org.apache.axis.AxisFault;
+import java.util.HashSet;
+import java.io.PrintWriter;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+
 
 /**
  * This is a set of several utility methods which may be useful for
@@ -22,49 +32,6 @@
 
 public abstract class Utils {
 
-    /*************************************************************************
-     * Format an exception 'e' and return it back.
-     *<p>
-     * @param e an exception to e formatted
-     * @return a formatted exception
-     *************************************************************************/
-    public static String formatFault (AxisFault e) {
-	return formatFault (e, null, null);
-    }
-
-    /*************************************************************************
-     * Return a nicely formatted exception 'e' with few additional details
-     * taken from 'endpoint' (where is the called service) and 'method'
-     * (what method caused this exception).
-     *<p>
-     * @param e an exception to e formatted
-     * @param endpoint of a service that caused the exception
-     * @param method that caused the exception
-     * @return a formatted exception
-    *************************************************************************/
-    public static String formatFault (AxisFault e,
-				      String endpoint, QName method) {
-	StringBuffer buf = new StringBuffer();
-	buf.append ("===ERROR===\n");
-	buf.append ("Fault details:\n");
-	org.w3c.dom.Element[] details = e.getFaultDetails();
-	for (int i = 0; i < details.length; i++) {
-	    String s = replace (replace (details[i].toString(), "&lt;", "<"), "&gt;", ">");
-	    buf.append (s + "\n");
-	}
-	buf.append ("Fault string: " + e.getFaultString() + "\n");
-	buf.append ("Fault code:   " + e.getFaultCode() + "\n");
-	buf.append ("Fault actor:  " + e.getFaultActor() + "\n");
-	if (endpoint != null || method != null)
-	    buf.append ("When calling:\n");
-	if (endpoint != null)
-	    buf.append ("\t" + endpoint + "\n");
-	if (method != null)
-	    buf.append ("\t" + method + "\n");
-	buf.append ("===========\n");
-	return new String (buf);
-    }
-
     /** 
      * In 'string', replace all occurrences of
      * 'from' by 'to' and return the resulting string. 
@@ -110,6 +77,38 @@
     }
 
     /*************************************************************************
+     * Create a file and fill it with given contents. <p>
+     *
+     * @param file to be created
+     * @param contents what to put in the created file
+     * @throws MobyException if something goes wrong
+     *************************************************************************/
+    public static void createFile (File file, String contents)
+	throws MobyException {
+	createFile (file, new StringBuffer (contents));
+    }
+
+    /*************************************************************************
+     * Create a file and fill it with given contents. <p>
+     *
+     * @param file to be created
+     * @param contents what to put in the created file
+     * @throws MobyException if something goes wrong
+     *************************************************************************/
+    public static void createFile (File file, StringBuffer contents)
+	throws MobyException {
+ 	try {
+	    PrintWriter fileout = new PrintWriter
+		(new BufferedWriter (new FileWriter (file)));
+	    fileout.print (contents);
+	    fileout.close();
+ 	} catch (IOException e) {
+	    throw new MobyException
+		("Cannot create file '" + file.getAbsolutePath() + "'. " + e.toString());
+ 	}
+    }
+
+    /*************************************************************************
      * Return just the last part of the LSID identifier. An example of
      * an LSID identifier as used by and returned from the Moby
      * registry is <tt>urn:lsid:biomoby.org:objectclass:object</tt>.
@@ -127,5 +126,229 @@
 	return lsid.substring (pos + 1);
     }
 
+    /*************************************************************************
+     * Find the resource with the given 'filename', read it and return
+     * it. A resource is some data (images, audio, text, etc) that can be
+     * accessed by class code in a way that is independent of the location
+     * of the code, typicallt such resource file sits anywhere on the CLASSPATH. <p>
+     *
+     * @param filename of a resource is a '/'-separated path name that
+     * identifies the resource
+     * @param resourceOwner is any object whose class loader is used
+     * to find and get the resource; typically one would put here
+     * "this" when calling this method
+     * @return contents of the resource, or null if the resource could
+     * not be found
+     * @throws MobyException if resource was found but an error
+     * occured during its reading (IO problem, memory problem etc.)
+     *************************************************************************/
+    public static String readResource (String filename, Object resourceOwner)
+	throws MobyException {
+
+	InputStream ins =
+	    resourceOwner.getClass().getClassLoader().getResourceAsStream
+	    (filename);
+	if (ins != null) {
+	    BufferedReader data = null;
+	    try {
+		StringBuffer contents = new StringBuffer();
+		data = new BufferedReader (new InputStreamReader (ins));
+		String line;
+		while ((line = data.readLine()) != null) {
+		    contents.append (line);
+		    contents.append ("\n");
+		}
+		return new String (contents);
+	    } catch (IOException e) {
+		throw new MobyException ("Problem when reading resource '" + filename +
+					 "'. " + e.toString());
+	    } catch (Error e) {     // be prepare for "out-of-memory" error
+		throw new MobyException ("Problem when reading resource '" + filename +
+					 "'. " + e.toString(), e);
+	    } finally {
+		try {
+		    if (data != null)
+			data.close();
+		} catch (IOException e) {
+		}
+	    }
+	}
+	return null;
+    }
+
+    /*************************************************************************
+     * Return just the last part of a Java class name (after the last
+     * dot). It is useful for displaying purposes (and when data do
+     * not have article names). <p>
+     *
+     * @param className whose last part is being looked for
+     * @return the last part of 'className', or the whole 'className' if it does
+     * not contain any dots
+     *************************************************************************/
+    public static String simpleClassName (String className) {
+	int pos = className.lastIndexOf (".");
+	int len = className.length();
+	if (pos == -1)    return className;
+	if (pos == len-1) return className.substring (0, pos);
+	return className.substring (pos + 1);
+    }
+
+    /*********************************************************************
+     * Check or create an article name. Biomoby uses term "article
+     * name" for naming Biomoby objects by context where they
+     * appear. For example, article name must be used for Biomoby
+     * objects that are children (members) of other Biomoby objects. <p>
+     *
+     * This method checks if the given 'articleName' is not empty -
+     * and if it is then it replaces it with the given 'className'
+     * (each Biomoby object always has a class name). <p>
+     *
+     * It also trims the article name (removes starting and ending
+     * whitespaces). <p>
+     *
+     * @param articleName will be checked, or created if it is empty
+     * @param className will be used to create an article name (if
+     * necessary)
+     * @return original 'articleName' or a new (created) one
+     ********************************************************************/
+    static public String checkOrCreateArticleName (String articleName,
+						   String className) {
+
+	// triming whitespaces
+	if (articleName.length() != articleName.trim().length())
+	    articleName = articleName.trim();
+
+	// return back the original article name (if it was good)
+	if (articleName != null && ! "".equals (articleName.trim()))
+	    return articleName;
+
+	// if there is no article name, take the last part of the
+	// class name
+	return Utils.simpleClassName (className);
+    }
+
+    /*************************************************************************
+     * Make sure that an article name does not collide with the member
+     * names in the top-level MobyObject. The members in question are
+     * 'id', 'name', 'namespace' and 'value'. This does not mean that
+     * Biomoby data types are not allowed to have such article names,
+     * but that Java code generator must generate slightly different
+     * names for its methods in these cases. <p>
+     *
+     * I must admit that this replacement is not full-proof: if a data
+     * type will have both article names 'value' and 'the_value' then
+     * this arrangement breaks... <p>
+     *
+     * This method is used at least from two places now (an XML Moby
+     * Parser and a MoSeS code generator) - that's why it ended up
+     * here in general utilities. <p>
+     *
+     * @param value will be checked (already expected not to be empty)
+     * @return the same 'value' if nothing wrong with it was found, or
+     * a new string resembling the 'value' but having some characters
+     * replaced
+     *************************************************************************/
+    public static String mobyEscape (String value) {
+	if ( "value".equals (value) ||
+	     "name".equals (value) ||
+	     "namespace".equals (value) ||
+	     "id".equals (value) )
+	    return "the_" + value;
+	else
+	    return value;
+    }
+
+    /*************************************************************************
+     * Make 'value' a valid Java identifier by trimming it and by
+     * replacing "unwanted" characters by underscores. <p>
+     *
+     * @param value will be checked
+     * @return the same 'value' if nothing wrong with it was found, or
+     * a new string resembling the 'value' but having some characters
+     * replaced
+     *************************************************************************/
+    public static String javaEscape (String value) {
+	if (value == null || value.trim().equals (""))
+	    return "_";
+	boolean found = false;   // if it becomes true we need to return a new string
+	char[] s = value.trim().toCharArray();
+	if (s.length != value.length())
+	    found = true;   // can happen because of trimming
+	if (! Character.isJavaIdentifierStart (s[0])) {
+	    s[0] = '_';
+	    found = true;
+	}
+	for (int i = 1; i < s.length ; i++ ) {
+	    if (! Character.isJavaIdentifierPart (s[i])) {
+		s[i] = '_';
+		found = true;
+	    }
+	}
+	if (javaReserved.contains (value)) {
+	    value = "_" + value;
+	    found = true;
+	}
+	return (found ? new String (s) : value);
+    }
+
+    /*************************************************************************
+     *
+     *************************************************************************/
+    protected static HashSet javaReserved = new HashSet();
+    static {
+        javaReserved.add ("abstract");
+        javaReserved.add ("assert");
+        javaReserved.add ("boolean");
+        javaReserved.add ("break");
+        javaReserved.add ("byte");
+        javaReserved.add ("case");
+        javaReserved.add ("catch");
+        javaReserved.add ("char");
+        javaReserved.add ("class");
+        javaReserved.add ("const");
+        javaReserved.add ("continue");
+        javaReserved.add ("default");
+        javaReserved.add ("do");
+        javaReserved.add ("double");
+        javaReserved.add ("else");
+        javaReserved.add ("enum");
+        javaReserved.add ("extends");
+        javaReserved.add ("false");
+        javaReserved.add ("final");
+        javaReserved.add ("finally");
+        javaReserved.add ("float");
+        javaReserved.add ("for");
+        javaReserved.add ("goto");
+        javaReserved.add ("if");
+        javaReserved.add ("implements");
+        javaReserved.add ("import");
+        javaReserved.add ("instanceof");
+        javaReserved.add ("int");
+        javaReserved.add ("interface");
+        javaReserved.add ("long");
+        javaReserved.add ("native");
+        javaReserved.add ("new");
+        javaReserved.add ("null");
+        javaReserved.add ("package");
+        javaReserved.add ("private");
+        javaReserved.add ("protected");
+        javaReserved.add ("public");
+        javaReserved.add ("return");
+        javaReserved.add ("short");
+        javaReserved.add ("static");
+        javaReserved.add ("strictfp");
+        javaReserved.add ("super");
+        javaReserved.add ("switch");
+        javaReserved.add ("synchronized");
+        javaReserved.add ("this");
+        javaReserved.add ("throw");
+        javaReserved.add ("throws");
+        javaReserved.add ("transient");
+        javaReserved.add ("true");
+        javaReserved.add ("try");
+        javaReserved.add ("void");
+        javaReserved.add ("volatile");
+        javaReserved.add ("while");
+    }
 
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/package.html,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/shared/package.html	2005/05/19 15:57:26	1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/package.html	2005/08/26 06:27:04	1.3
@@ -18,7 +18,50 @@
 cornerstone piece is the interface {@link org.biomoby.shared.Central}
 that defines how to access Moby registry without any knowledge of the
 used transport protocol (SOAP, XML, etc.). This interface uses several
-<em>container</em> classes representing pieces of the Moby mosaic.
+<em>container</em> classes representing pieces of the Moby mosaic. <p>
 
+Talking about a mosaic, it looks sometimes confusing what data
+containers we have here (and in sub-packages). Let's try to briefly
+explain them:
+
+<ul>
+
+  <li> The data containers located directly here (in
+<tt>org.biomoby.shared</tt> package, for example {@link
+org.biomoby.shared.MobyService MobyService}) were designed to carry
+information to and from Biomoby registries. Their names are a bit
+misnomer because they can be easily confused with similar data
+containers carrying real data to the Biomoby <em>service
+providers</em>. <p>
+
+  <li> The {@link org.biomoby.shared.data} package deals with data
+containers travelling between clients and Biomoby service
+providers. They were designed by Paul Gordon and their usage is best
+explain in the <a
+href="http://biomoby.org/moby-live/Java/docs/SimpleClient.html"
+target="_top">Simple client</a> document. The main idea is that the
+same data types are used for all services because they are designed
+as general as possible (its is a <em>loosely-typed</em>
+concept). <p>
+
+  <li> The {@link org.biomoby.shared.datatypes} is similar to the
+previous one because it also contains containers for data exchange
+between the clients and Biomoby service providers. It was created by
+Martin Senger and its primary purpose is to be a part of code
+generators (see details in the <a
+href="http://biomoby.org/moby-live/Java/docs/Moses.html"
+target="_top">Moses</a> document. The package here has only primitive
+data types, but a data type generator is able to fill-in hundreds of
+data types from Biomoby registries - so developers can use
+<em>strongly-typed</em> approach. <p>
+
+  <li> The package {@link org.biomoby.shared.parser} is closely
+related to the previous one because it provides Biomoby envelopes for
+data types defined in {@link org.biomoby.shared.datatypes}. It has
+classes for Biomoby Simples and Collections - where inside can sit
+containers from the previous package. Additionally, it has a Biomoby
+parser that can fill these containers from an XML. <p>
+
+</ul>
 
 </body> </html>

rcsdiff: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/RCS/MobyNativeService.java,v: No such file or directory

rcsdiff: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/RCS/MobyObject.java,v: No such file or directory




More information about the MOBY-guts mailing list