[MOBY-guts] biomoby commit

Martin Senger senger at dev.open-bio.org
Thu Feb 28 05:21:48 UTC 2008


senger
Thu Feb 28 00:21:48 EST 2008
Update of /home/repository/moby/moby-live/Java/src/Clients
In directory dev.open-bio.org:/tmp/cvs-serv20124/src/Clients

Modified Files:
	TestingMobyParser.java 
Log Message:
* the jMoby XML message parser can accept now more specialized types of members than the ones its parent was registered with
* added junit tests for the parser

moby-live/Java/src/Clients TestingMobyParser.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/Clients/TestingMobyParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/Clients/TestingMobyParser.java	2005/09/04 13:45:37	1.2
+++ /home/repository/moby/moby-live/Java/src/Clients/TestingMobyParser.java	2008/02/28 05:21:48	1.3
@@ -6,24 +6,25 @@
 // Copyright Martin Senger (martin.senger at gmail.com).
 //
 
+import org.biomoby.client.CmdLineHelper;
 import org.biomoby.shared.parser.MobyPackage;
-import org.biomoby.shared.MobyException;
-import org.biomoby.shared.Utils;
 
 import org.tulsoft.tools.BaseCmdLine;
 import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * A command-line client with the only purpose - to test parser of the
  * Biomoby XML data. It takes an XML file, parses it and prints all
  * its component as hierarchical strings. <p>
  *
- * Or it recreates back the same XML and prints it. The XML result in
+ * Or, it re-creates back the same XML and prints it. The XML result in
  * this case is not identical as the original - it may have different
  * formatting, it probably has more XML namespace prefixes (they are
  * everywhere), but more importantly, it may not reflect all data that
  * was in the original input. This is because it ignores all values
- * that are not carried by and only by the Biomoby primitives types
+ * that are not carried by, and only by, the Biomoby primitives types
  * (as it was allowed before big change in the summer 2005). <p>
  *
  * Start it with <tt>-h</tt> option. <p>
@@ -31,20 +32,8 @@
  * @author <A HREF="mailto:martin.senger at gmail.com">Martin Senger</A>
  * @version $Id$
  */
-public class TestingMobyParser {
-
-    /*************************************************************************
-     * Return a help text about this this client.
-     *************************************************************************/
-    public String getUsage() {
-	String helpFile = "help/TestingMobyParser_usage.txt";
-	try {
-	    String help = Utils.readResource (helpFile, this);
-	    return (help == null ? "" : help);
-	} catch (MobyException e) {
-	    return e.getMessage();
-	}
-    }
+public class TestingMobyParser
+    extends CmdLineHelper {
 
     /*************************************************************************
      *
@@ -54,38 +43,47 @@
     public static void main (String [] args) {
 	try {
 
-	    BaseCmdLine cmd = new BaseCmdLine (args, true);
-	    if (cmd.hasParam ("-help") || cmd.hasParam ("-h")) {
-		System.out.print (new TestingMobyParser().getUsage());
-		System.exit (0);
-	    }
+	    BaseCmdLine cmd = getCmdLine (args, TestingMobyParser.class);
 
 	    boolean reverse = cmd.hasOption ("-r");
 	    boolean noprint = cmd.hasOption ("-n");
 	    String backup = cmd.getParam ("-b");
 
-	    if (cmd.params.length == 0) return;
+	    String infile = null;
+	    Map<String,String> backups = new HashMap<String,String>();
+	    int i = 0;
+	    while (i < cmd.params.length) {
+		if (cmd.params[i].startsWith ("-") && i < cmd.params.length - 1) {
+		    backups.put (cmd.params[i].substring (1),
+				 cmd.params[i+1]);
+		    i += 2;
+		    continue;
+		} else {
+		    infile = cmd.params[i];
+		    i++;
+		    continue;
+		}
+	    }
 
-	    MobyPackage moby =
-		MobyPackage.createFromXML (new File (cmd.params[0]), backup);
+	    if (infile == null) return;
+
+	    MobyPackage moby = null;
+	    if (backups.isEmpty()) {
+		moby = MobyPackage.createFromXML (new File (cmd.params[0]), backup);
+	    } else {
+		moby = MobyPackage.createFromXML (new File (cmd.params[0]), backups);
+	    }
 
 	    if (! noprint)
-		System.out.println (moby.toString());
+		msgln (moby.toString());
 
 	    if (reverse)
-		System.out.println (moby.toXML());
+		msg (moby.toXML());
 
-	    System.exit (0);
+	    exit (0);
 
-	} catch (MobyException e) {
-	    System.err.println ("===ERROR===");
-	    System.err.println (e.getMessage());
-	    System.err.println ("===========");
-
-	} catch (Exception e) {
-	    System.err.println ("===ERROR===");
-	    e.printStackTrace();
-	    System.err.println ("===========");
+	} catch (Throwable e) {
+	    processErrorAndExit (e);
 	}
     }
 }




More information about the MOBY-guts mailing list