[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Mar 17 20:21:55 UTC 2010


gordonp
Wed Mar 17 16:21:55 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services
In directory dev.open-bio.org:/tmp/cvs-serv11511/src/main/ca/ucalgary/seahawk/services

Modified Files:
	DaggooClient.java MobyClient.java 
Log Message:
Interface updates related to new search/filter and workflow generation/preview functions
moby-live/Java/src/main/ca/ucalgary/seahawk/services DaggooClient.java,1.1,1.2 MobyClient.java,1.24,1.25
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/DaggooClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/DaggooClient.java	2009/06/09 19:52:02	1.1
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/DaggooClient.java	2010/03/17 20:21:55	1.2
@@ -21,57 +21,109 @@
 public class DaggooClient{
     private static Logger logger = Logger.getLogger(DaggooClient.class.getName());
 
+    /**
+     * The three outcomes possible from asking the user about the URL dropped on Seahawk.
+     */
+    public enum Action {WRAP, CALL, VIEW, NOTHING}
+	
     public static boolean acceptAnExistingWrapper(URL u, MobyContentPane dropTargetPane){
+	// by default, do not provide view vs. wrap option
+	return acceptAnExistingWrapper(u, dropTargetPane, false) != Action.WRAP;
+	// all actions except wrap are handled by this method
+    }
+
+    /**
+     * Presents the user with a dialog showing all Moby services (wrappers) that exist for the provided URL.
+     * This method will handle calling of existing services and viewing the form.  Only a return of Action.WRAP
+     * is actionable for the caller.
+     *
+     * @param u the URL containing the form/wsdl doc to wrap
+     * @param dropTargetPane the Seahawk GUI element onto which the URL was dropped
+     * @param giveViewOption provide extra option to just view the page in Seahawk, rather than wrap the service
+     */
+    public static Action acceptAnExistingWrapper(URL u, MobyContentPane dropTargetPane, boolean giveViewOption){
 	// Before wrapping the WSDL, see if there are already services wrapping it (in Daggoo).
 	// If so, ask the user if they want to use one of those instead.
 	try{
 	    String existingServices = HTMLUtils.getURLContents(new URL(PBERecorder.getProxyBaseUrl()+
 								       "lookup/"+Registration.OP_SPEC_DOC_PARAM+
 								       "/"+u));
-	    if(existingServices == null || existingServices.length() == 0){
-		return false; // no existing wrappers
-	    }
-	    String registryURL = SeahawkOptions.getRegistry() == null ? 
-		CentralImpl.getDefaultURL() :
-		SeahawkOptions.getRegistry().getEndpoint();
 	    Vector<String> choices = new Vector<String>();
-	    for(String line: existingServices.split("\n")){
-		String[] fields = line.split("\t");
-		if(fields.length != 4){
-		    throw new Exception("Did not get lines with 4 tab-delimited fields " +
-					"from Daggoo lookup service.  The offending line is " + line);
-		}
-		if(!fields[1].equals(registryURL)){
-		    logger.log(Level.INFO, 
-			       "Skipping service in different registry (" + 
-			       fields[1] + ") than the current one in Seahawk (" +
-			       registryURL + ")");
-		    continue;
+	    if(existingServices != null && existingServices.length() != 0){
+		String registryURL = SeahawkOptions.getRegistry() == null ? 
+		    CentralImpl.getDefaultURL() :
+		    SeahawkOptions.getRegistry().getEndpoint();
+		for(String line: existingServices.split("\n")){
+		    String[] fields = line.split("\t");
+		    if(fields.length != 4){
+			throw new Exception("Did not get lines with 4 tab-delimited fields " +
+					    "from Daggoo lookup service.  The offending line is " + line);
+		    }
+		    if(!fields[1].equals(registryURL)){
+			logger.log(Level.INFO, 
+				   "Skipping service in different registry (" + 
+				   fields[1] + ") than the current one in Seahawk (" +
+				   registryURL + ")");
+			continue;
+		    }
+		    choices.add(fields[3]+" ("+fields[2]+")");
 		}
-		choices.add(fields[3]+" ("+fields[2]+")");
-	    }
-	    if(choices.isEmpty()){
-		return false; // none in the registry we need
 	    }
 	    //todo: add "Don't show me this dialog again" option?
-	    Object selectedValue = JOptionPane.showInputDialog(dropTargetPane,
-							       "The services below wrap the same page as " +
-							       "you just dragged into Seahawk.\n  Would you like to " +
-							       "call one instead of wrapping the page again?",
-							       "Existing Wrapper Services",
-							       JOptionPane.INFORMATION_MESSAGE, null,
-							       choices.toArray(), choices.get(0));
-	    if(selectedValue == null){
-		// cancel
-		return false;
+	    Object selectedValue = null;
+	    if(!giveViewOption){
+		if(choices.isEmpty()){
+		    return Action.WRAP; // none in the registry we need
+		}
+		selectedValue = JOptionPane.showInputDialog(dropTargetPane,
+							    "The services below wrap the same page as " +
+							    "you just dragged into Seahawk.\n  Would you like to " +
+							    "call one instead of wrapping the page again?",
+							    "Existing Wrapper Services",
+							    JOptionPane.INFORMATION_MESSAGE, null,
+							    choices.toArray(), choices.get(0));
+		if(selectedValue == null){
+		    // cancel = wrap it yourself instead of using one of the service options presented
+		    return Action.WRAP;
+		}
+	    }
+	    else{ // give user three options: call service, wrap service or view URL contents in Seahawk
+		Action action = Action.NOTHING;
+		if(choices.isEmpty()){ // still give option to wrap or view contents if no services exist
+		    int choice = JOptionPane.showOptionDialog(dropTargetPane, 
+							      "What would you like to do with this Web page?", "Wrap or View?",
+							      JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
+							      null, new String[]{"Create a service", "View page contents"}, 
+							      "Create a service");
+		    if(choice == JOptionPane.CLOSED_OPTION){
+			return Action.NOTHING;
+		    }
+		    else if(choice == 0){
+			return Action.WRAP;
+		    }
+		    else{ 
+			action = Action.VIEW;
+		    }
+		}
+		else{
+		    
+		}
+		if(action == Action.VIEW){
+		    // load the page for viewing.  Normally gotoURL would cause recursion on this method, so
+		    // we disable wrapping temporarily to avoid this.
+		    dropTargetPane.setWrappingEnabled(false);
+		    dropTargetPane.gotoURL(u, true);
+		    dropTargetPane.setWrappingEnabled(true);
+		    return Action.VIEW;
+		}
 	    }
 	    // todo: actually call service
 	    System.err.println("Running the existing wrapper " + selectedValue);
 	}
 	catch(Exception e){
 	    logger.log(Level.WARNING, "Cannot show the user existing service options", e);
-	    return false;
+	    return Action.VIEW;
 	}
-	return true;  //if we got here, the user accepted an existing service
+	return Action.CALL;  //if we got here, the user accepted an existing service
     }
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java	2009/08/18 18:22:07	1.24
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java	2010/03/17 20:21:55	1.25
@@ -17,6 +17,7 @@
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.*;
+import java.util.logging.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.xml.parsers.*;
@@ -36,6 +37,7 @@
     public static final String PREFIX_ATTR = "value";
     public static final String ARTICLENAME_RULE_TAG = "articlename";
     public static final String NAMESPACE_RULE_TAG = "namespace";
+    public static final String NAMESPACE_MODEL_ATTR = "model";
     public static final String NAMESPACE_VALUE_TAG = "ns";
     public static final String NAMESPACE_VALUE_ATTR = "value";
     public static final String DATATYPE_RULE_TAG = "datatype";
@@ -71,7 +73,7 @@
     private Registry registry;
     private URL dataMappingXMLURL;
     private DocumentBuilder docBuilder;
-    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(MobyClient.class);
+    private static Logger logger = Logger.getLogger(MobyClient.class.getName());
 
     private int serviceLevel = MobyService.UNCHECKED;
 
@@ -272,7 +274,8 @@
 	    Vector<String> regexStrings = new Vector<String>();
 	    Vector<String> urlRegexStrings = new Vector<String>();
 	    Vector<String> xpathStrings = new Vector<String>();
-	    Map<String,String> namespaceMap = new HashMap<String,String>();
+	    Map<String,String> namespaceMap = new HashMap<String,String>();  // moby nanmespaces -> production rules
+	    Map<String,String> modelMap = new HashMap<String,String>();  // Semantic Web URIs -> production rules
 	    Map<String,String[]> memberMap = new HashMap<String,String[]>();
 	    String dataTypeString = null;
 	    String articleNameString = null;
@@ -297,7 +300,7 @@
 		    addXPathString(ruleMember, xpathStrings);
 		}
 		else if(isNamespaceRule(ruleMember)){
-		    addNamespaceMapping(ruleMember, namespaceMap);
+		    addNamespaceMapping(ruleMember, namespaceMap, modelMap);
 		}
 		else if(isArticleNameRule(ruleMember)){
 		    if(articleNameString != null && articleNameString.length() != 0){
@@ -607,13 +610,14 @@
 	                                           memberRuleName});
     }
 
-    protected void addNamespaceMapping(Element nsTag, Map<String,String> namespaceStrings) throws Exception{
+    protected void addNamespaceMapping(Element nsTag, Map<String,String> namespaceStrings, Map<String,String> modelStrings) throws Exception{
 	if(!isNamespaceRule(nsTag)){
 	    throw new Exception("Element provided to createNamespaceMapping (" +
 				(nsTag == null ? null : nsTag.getLocalName()) + 
 				") was not a namespace rule element");
 	}
 	
+
 	NodeList ruleSpecs = nsTag.getChildNodes();
 	for(int i = 0; i < ruleSpecs.getLength(); i++){
 	    Node specNode = ruleSpecs.item(i);
@@ -625,7 +629,8 @@
 	    Element ruleSpec = (Element) specNode;
 	    String specName = ruleSpec.getLocalName();
 	    if(NAMESPACE_VALUE_TAG.equals(specName)){
-		String keyName = ruleSpec.getAttribute(NAMESPACE_VALUE_ATTR);
+		String keyName = ruleSpec.getAttribute(NAMESPACE_VALUE_ATTR); // moby namespace
+		String modelURI = ruleSpec.getAttribute(NAMESPACE_MODEL_ATTR); // Semantic Web URI
 		String valueRule = ruleSpec.getTextContent();
 		if(valueRule == null || valueRule.length() == 0){
 		    throw new Exception("Element " + NAMESPACE_VALUE_TAG + 
@@ -636,7 +641,12 @@
 				       "namespace '" + keyName + "'");
 		    continue;
 		}
-		namespaceStrings.put(keyName, valueRule);
+		if(keyName != null && keyName.length() != 0){
+		    namespaceStrings.put(keyName, valueRule);
+		}
+		if(modelURI != null && modelURI.length() != 0){
+		    modelStrings.put(modelURI, valueRule);
+		}
 	    }
 	    else{
 		System.err.println("Skipping unexpected "+NAMESPACE_RULE_TAG+" child node " + specName);
@@ -1336,7 +1346,7 @@
 		mobyDataServiceAssocInstances[i] = new MobyDataObjectSetSAI((MobyDataObjectSet) mdos[i], mService);
 	    }
 	    else{
-		logger.warn("MobyClient could not handle service-associating an instance of " + mdos[i].getClass());
+		logger.log(Level.WARNING, "MobyClient could not handle service-associating an instance of " + mdos[i].getClass());
 		System.err.println("MobyClient could not handle service-associating an instance of " + mdos[i].getClass());
 	    }
 	}
@@ -1694,7 +1704,8 @@
 		builderNameMap.put(urn, mcb);
 	    }
 	}catch(Exception e){
-	    logger.warn("Could not create XPath select statement from '" +
+	    logger.log(Level.WARNING, 
+		       "Could not create XPath select statement from '" +
 			xpath_exp + "': " + e.getMessage());
 	    System.err.println("Could not create XPath select statement from '" +
 			       xpath_exp + "': " + e);




More information about the MOBY-guts mailing list