[MOBY-guts] biomoby commit

Martin Senger senger at dev.open-bio.org
Sun Mar 2 12:45:26 UTC 2008


senger
Sun Mar  2 07:45:26 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser
In directory dev.open-bio.org:/tmp/cvs-serv32345/src/main/org/biomoby/shared/parser

Modified Files:
	MobyParser.java 
Log Message:
Too Many Changes - see docs/ChangeLog

moby-live/Java/src/main/org/biomoby/shared/parser MobyParser.java,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/MobyParser.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/MobyParser.java	2008/02/28 05:21:48	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/MobyParser.java	2008/03/02 12:45:26	1.9
@@ -18,7 +18,6 @@
 
 import org.tulsoft.tools.loaders.ICreator;
 import org.tulsoft.shared.GException;
-import org.tulsoft.tools.debug.DGUtils;
 import org.tulsoft.tools.xml.XMLUtils2;
 import org.tulsoft.tools.xml.XMLErrorHandler;
 
@@ -55,22 +54,24 @@
  * href="http://biomoby.org/moby-live/Java/docs/APIservices/org/biomoby/shared/datatypes/package-summary.html"
  * target="_top"><tt>org.biomoby.shared.datatypes</tt></a>. <p>
  *
- * There is one situation when the parser tries to substitute an
- * unknown data type by a known one. If the parsing encoutered an XML
- * tag depicting a <em>top-level</em> data object (not a member object
- * of some other data object) and if there is no class available for
- * such object, the parser can be instructed (in its {@link
- * #MobyParser(String) non-default constructor} to create a substituted
- * object whose name was given in the parser constructor. This is to
- * prevent situation when a long-time running and deployed service
- * suddenly gets a request from a client that uses more up-to-date
- * list of data types. It would be bad to let such service die (or
- * minimally respond unproperly) just because its classes were
- * generated too long ago. <p>
+ * There is a situation when the parser tries to substitute an unknown
+ * data type by a known one. If the parsing encoutered an XML tag
+ * depicting a <em>top-level</em> data object, or a member object, and
+ * if there is no class available for such object, the parser can be
+ * instructed (in its {@link #MobyParser(String) non-default
+ * constructor} to create a substituted object whose name was given in
+ * the parser constructor (there is also a constructor where you can
+ * get more than one such substitution object, depicted by its article
+ * name). This is to prevent situation when a long-time running and
+ * deployed service suddenly gets a request from a client that uses
+ * more up-to-date list of data types. It would be bad to let such
+ * service die (or minimally respond unproperly) just because its
+ * classes were generated too long ago. <p>
  *
  * Because also skeletons for services can be generated, it is easy to
  * ensure that a service knows its "the most specialized" data type it
- * can still serve, and that it passes it to the parser constructor. <p>
+ * can still serve, and that it passes it to the parser
+ * constructor. <p>
  *
  * If the parser finds an unknown object/tag but no substitute was
  * passed in the parser constructor, it prints a warning and ignores
@@ -81,29 +82,14 @@
  * types should be generated, and services restarted. Fortunately, it
  * does not happen often at all. <p>
  *
- * Be aware, however, that this substitution may do a wrong thing if
- * there are more bad top-level objects - such as in case when a
- * result has more outputs. I think that this insufficiency should be
- * consider a bug in parser design - but make it properly would need
- * much more complicated interface... <p>
- *
  * If the parser finds another problem, usually related to the invalid
  * XML, it raises a {@link org.biomoby.shared.MobyException
  * MobyException} with error message containing line and column close
  * to place where the error happened. <p>
  *
  * One possible problem would be when article names of the member data
- * types in the parsed XML do not correspond what was registered in
- * the Biomoby registry. An example, I know about at the time of
- * writing this, is a service <tt>MIPSBlastXMLClickableImage</tt> that
- * returns object of type <tt>NCBI_Blast_XML_Gif_Map</tt> which has a
- * member object of type <tt>b64_encoded_gif</tt>. This member was
- * registered with the article name "hitGraph" but the service returns
- * an article name "image". Parser spots it and stops parsing (because
- * it does not know where to put this member object). However, if you
- * insist that you still want to get such XML parsed, even without one
- * part, you can set Java property "biomoby.parser.forgiving" to true,
- * and run it again. <p>
+ * types in the parsed XML do not correspond to what was registered in
+ * the Biomoby registry (or to its more specialized childern). <p>
  *
  * You can test parser by using a simple <tt>TestingMobyParser</tt>
  * client. This is how to invoke it and how to get its help:
@@ -153,6 +139,10 @@
  *                                               "GenericSequence");
  * </pre>
  *
+ * For a constructor with more fallbacks, check generated skeletons
+ * (for example the sample skeleton
+ * <tt>net.jmoby.samples.ConcatSequencesSkel</tt>). <p>
+
  * All XML tags and all attribute names that are recognized and
  * processed by this parser are stored as constants in class {@link
  * MobyTags}. <p>
@@ -171,12 +161,6 @@
     private static org.apache.commons.logging.Log log =
 	org.apache.commons.logging.LogFactory.getLog (MobyParser.class);
 
-    /**
-     * A Java property name. See its purpose in the main description
-     * above.
-     */
-    public static final String BIOMOBY_PARSER_FORGIVING = "biomoby.parser.forgiving";
-
     Locator locator;
     XMLReader parser = null;
     String lowestKnownDataType = null;
@@ -361,9 +345,9 @@
      * all its descendants (with a warning message).
      *
      *    The same mode is also entered when an unknown member object
-     * was found (a member object is never substituted). But here we
-     * issue a warning message only if we are NOT in substitution mode
-     * (in a substitution mode it is normal to found unknown objects).
+     * was found. But here we issue a warning message only if we are
+     * NOT in substitution mode (in a substitution mode it is normal
+     * to found unknown objects).
      *
      *    'inSubstitution' is a mode when a top-level object (not a
      * member object) was not found AND a substitutee was provided in
@@ -402,8 +386,7 @@
 
 	} catch (Error e) {
 	    throw new MobyException ("Serious or unexpected error!\n" +
-				     e.toString() + "\n" +
-				     DGUtils.stackTraceToString (e));
+				     e.toString(), e);
 	}
     }
 
@@ -554,6 +537,20 @@
 				    lowestKnownDataTypes.containsKey (articleName)) {
 				    theClass =
 					mapDataTypes.getClass (lowestKnownDataTypes.get (articleName));
+				} else {
+				    // ...if we are in a collection,
+				    // we need to use the article name
+				    // of that collection
+				    MobyCollection collObj = peekCollection();
+				    if (collObj != null) {
+					articleName = collObj.getName();
+					if (articleName != null &&
+					    lowestKnownDataTypes.containsKey (articleName)) {
+					    theClass =
+						mapDataTypes.getClass
+						(lowestKnownDataTypes.get (articleName));
+					}
+				    }
 				}
 			    }
 
@@ -916,6 +913,21 @@
     }
 
     /*********************************************************************
+     * Return the second last object from the 'objectStack' if it is a
+     * MobyCollectin, otherwise it returns null.
+     ********************************************************************/
+    protected MobyCollection peekCollection() {
+	if (objectStack.size() < 2)
+	    return null;
+	Object obj = objectStack.get (objectStack.size() - 2);
+	if (obj instanceof MobyCollection) {
+	    return (MobyCollection)obj;
+	} else {
+	    return null;
+	}
+    }
+
+    /*********************************************************************
      * Call a method (named 'methodName') on object 'actor', using
      * 'parameter'.
      ********************************************************************/




More information about the MOBY-guts mailing list