[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/service/generator
In directory dev.open-bio.org:/tmp/cvs-serv32345/src/main/org/biomoby/service/generator

Modified Files:
	DataTypesGenerator.java Generator.java ServicesGenerator.java 
Log Message:
Too Many Changes - see docs/ChangeLog

moby-live/Java/src/main/org/biomoby/service/generator DataTypesGenerator.java,1.5,1.6 Generator.java,1.4,1.5 ServicesGenerator.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/DataTypesGenerator.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/service/generator/DataTypesGenerator.java	2008/02/23 13:58:32	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/DataTypesGenerator.java	2008/03/02 12:45:26	1.6
@@ -19,6 +19,7 @@
 import org.biomoby.client.Graphviz;
 
 import java.util.Properties;
+import java.util.Map;
 import java.util.HashMap;
 import java.util.Date;
 import java.util.regex.Pattern;
@@ -105,8 +106,8 @@
     /*************************************************************************
      *
      *************************************************************************/
-    public HashMap getTemplateNames() {
-	HashMap tNames = new HashMap();
+    public Map<String,File> getTemplateNames() {
+	Map<String,File> tNames = new HashMap<String,File>();
 	File dir = new File ("templates");
 	tNames.put (TN_DATA_TYPE,            new File (dir, "DataTypeTemplate.java"));
 	tNames.put (TN_MEMBERS_HAS,          new File (dir, "MembersHASTemplate.java"));
@@ -178,7 +179,7 @@
 	    pattern = Pattern.compile (filter);
 
 	// load all templates (from files)
-	HashMap templates = getTemplateNames();
+	Map<String,File> templates = getTemplateNames();
 	dataTypeTemplate     = loadTemplate (templates.get (TN_DATA_TYPE));
 	membersHASTemplate   = loadTemplate (templates.get (TN_MEMBERS_HAS));
 	membersHASATemplate  = loadTemplate (templates.get (TN_MEMBERS_HASA));

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/Generator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/Generator.java	2008/02/23 13:58:32	1.4
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/Generator.java	2008/03/02 12:45:26	1.5
@@ -18,7 +18,7 @@
 import org.biomoby.client.CentralDigestCachedImpl;
 
 import java.util.Properties;
-import java.util.HashMap;
+import java.util.Map;
 import java.util.regex.Pattern;
 import java.io.File;
 
@@ -415,14 +415,14 @@
      * patterns as the original template - so it is not too flexible,
      * anyway). <p>
      *
-     * The values of returned HashMap are filenames. It their names
-     * are relative (which is the best way) then they are looked for
-     * in the CLASSPATH (including all jar files there). <p>
+     * The values of returned Map are files. It their names are
+     * relative (which is the best way) then they are looked for in
+     * the CLASSPATH (including all jar files there). <p>
      *
      * Make sure that the returned path is correct for the system
      * where JVM is running.
      *************************************************************************/
-    abstract public HashMap getTemplateNames();
+    abstract public Map<String,File> getTemplateNames();
 
     /**************************************************************************
      * Generate "things" from a given Biomoby registry. This is the

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/ServicesGenerator.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/service/generator/ServicesGenerator.java	2008/02/28 05:21:48	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/generator/ServicesGenerator.java	2008/03/02 12:45:26	1.7
@@ -26,10 +26,13 @@
 import org.biomoby.client.Graphviz;
 
 import org.tulsoft.tools.servlets.Html;
+import org.apache.commons.lang.StringUtils;
 
 import java.util.Properties;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.HashMap;
+import java.util.Set;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Vector;
@@ -130,8 +133,8 @@
     /*************************************************************************
      *
      *************************************************************************/
-    public HashMap getTemplateNames() {
-	HashMap tNames = new HashMap();
+    public Map<String,File> getTemplateNames() {
+	Map<String,File> tNames = new HashMap<String,File>();
 	File dir = new File ("templates");
 	tNames.put (TN_SERVICE, new File (dir, "ServiceSkeletonTemplate.java"));
 	tNames.put (TN_PARAMETER, new File (dir, "ServiceParameterTemplate.java"));
@@ -162,7 +165,7 @@
     static final Pattern P_SERVICE_URL   = Pattern.compile ("@SERVICE_URL@");
     static final Pattern P_SERVICE_RDF   = Pattern.compile ("@SERVICE_RDF@");
     static final Pattern P_IOTABLE       = Pattern.compile ("@IOTABLE@");
-    static final Pattern P_FALLBACK_TYPE = Pattern.compile ("@FALLBACK_TYPE@");
+    static final Pattern P_FALLBACK_CODE = Pattern.compile ("@FALLBACK_CODE@");
 
     // dynamically created (org.biomoby.shared.datatypes.MapDataTypes)
     // (we need it for generating set/get methods for input/output
@@ -194,15 +197,15 @@
 	// compile patterns for filtering by service and authority names
 	Pattern wantedService = null;
 	String filter = props.getProperty (GPROP_SERVICE);
-	if (filter != null && ! "".equals (filter))
+	if (StringUtils.isNotBlank (filter))
 	    wantedService = Pattern.compile (filter);
 	Pattern wantedAuthority = null;
 	filter = props.getProperty (GPROP_AUTH);
-	if (filter != null && ! "".equals (filter))
+	if (StringUtils.isNotBlank (filter))
 	    wantedAuthority = Pattern.compile (filter);
 
 	// load all templates (from files)
-	HashMap templates = getTemplateNames();
+	Map<String,File> templates = getTemplateNames();
 	serviceTemplate          = loadTemplate (templates.get (TN_SERVICE));
 	serviceParameterTemplate = loadTemplate (templates.get (TN_PARAMETER));
 	servicePISetTemplate     = loadTemplate (templates.get (TN_PISET));
@@ -291,14 +294,38 @@
 	// graphs?
 	boolean graphCreated = createGraph (serviceName, outputDir, props, allServices, allDataTypes);
 
-	// fallback type - just for services with a single primary input
-	String fallbackType = "";
+	// fallback type - its type depends on the number of primary inputs
+	StringBuilder fallbackCode = new StringBuilder();
 	MobyData[] pis = service.getPrimaryInputs();
-	if (pis.length == 1) {
+	if (pis.length == 0) {
+	    fallbackCode.append ("String fallback = null;");
+	} else if (pis.length == 1) {
 	    String dataTypeName = mapDataType2class (pis[0]);
-	    if (dataTypeName != null)
-		fallbackType = dataTypeName;
+	    if (dataTypeName != null) {
+		fallbackCode.append ("String fallback = \"");
+		fallbackCode.append (dataTypeName);
+		fallbackCode.append ("\";");
+	    } else {
+		fallbackCode.append ("String fallback = null;");
+	    }
+	} else if (pis.length > 1) {
+	    fallbackCode.append
+		("java.util.Map<String,String> fallback = new java.util.HashMap<String,String>(); ");
+	    for (MobyData p: pis) {
+		String dataTypeName = mapDataType2class (p);
+		if (dataTypeName != null) {
+		    String articleName = p.getName();
+		    if (StringUtils.isNotBlank (articleName)) {
+			fallbackCode.append ("fallback.put (\"");
+			fallbackCode.append (articleName);
+			fallbackCode.append ("\",\"");
+			fallbackCode.append (dataTypeName);
+			fallbackCode.append ("\"); ");
+		    }
+		}
+	    }
 	}
+	fallbackCode.append ("\n");
 
 	// replace tokens in templates
 	String result = P_SERVICE_NAME.matcher (serviceTemplate).replaceAll (serviceName);
@@ -313,7 +340,7 @@
 	result = P_EMAIL_CONTACT.matcher (result).replaceAll (htmlEscape (service.getEmailContact()));
 	result = P_IMAGESTART.matcher (result).replaceAll (graphCreated ? "" : "<!-- ");
 	result = P_IMAGEEND.matcher (result).replaceAll (graphCreated ? "" : " -->");
-	result = P_FALLBACK_TYPE.matcher (result).replaceAll (fallbackType);
+	result = P_FALLBACK_CODE.matcher (result).replaceAll (fallbackCode.toString());
 
 	// 
  	// now apply templates for set/get methods (put the result in
@@ -359,7 +386,7 @@
 	    String methods = serviceParameterTemplate;
 
 	    String articleName = sis[i].getName();
-	    if (articleName == null || "".equals (articleName.trim())) {
+	    if (StringUtils.isBlank (articleName)) {
 		System.err.println (MSG_SECONDARY_PBL (serviceName, sis[i]));
 		continue;
 	    }
@@ -437,7 +464,7 @@
      * (that's why it gets a 'serviceName') and returns false.
      *************************************************************************/
     protected boolean verifyNames (MobyData[] data, String serviceName) {
-	HashSet names = new HashSet();
+	Set<String> names = new HashSet<String>();
 	for (int i = 0; i < data.length; i++) {
 	    String name = getOrCreateArticleName (data[i]);
 
@@ -468,7 +495,7 @@
      * ignore them or replace them.
      *************************************************************************/
     protected String authority2package (String authority) {
-	if (authority == null || "".equals (authority.trim()))
+	if (StringUtils.isBlank (authority))
 	    return DEFAULT_PACKAGE;
  	StringBuffer buf = new StringBuffer (100);
 	String[] parts = authority.split ("\\.");
@@ -515,7 +542,7 @@
      *************************************************************************/
     protected String getOrCreateArticleName (MobyData data) {
 	String name = data.getName();
-	if (name != null && ! "".equals (name.trim()))
+	if (StringUtils.isNotBlank (name))
 	    return name;
 	return mapDataType2class (data);
     }
@@ -556,7 +583,7 @@
 	throws MobyException {
 	if (allServices == null)
 	    return worker.findService (patternService);
-	Vector v = new Vector();
+	Vector<MobyService> v = new Vector<MobyService>();
 	String name = patternService.getName();
 	String auth = patternService.getAuthority();
 	for (int i = 0; i < allServices.length; i++) {
@@ -641,7 +668,7 @@
 
 	static final String NBSP = "&nbsp;";
 	String nbsp (String value) {
-	    if (value == null || "".equals (value.trim())) return NBSP;
+	    if (StringUtils.isBlank (value)) return NBSP;
 	    else return value;
 	}
 	MobyPrimaryDataSimple getOneSimple (MobyData data) {




More information about the MOBY-guts mailing list