[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue Jun 9 19:31:24 UTC 2009


gordonp
Tue Jun  9 15:31:24 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv21209/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentGUI.java 
Log Message:
Cached calls suggestion, Daggoo functionality (xml linking for service output, URN tracking)
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentGUI.java,1.18,1.19
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java	2008/10/30 02:33:24	1.18
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java	2009/06/09 19:31:24	1.19
@@ -6,8 +6,7 @@
 import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.*;
 
 import javax.swing.*;
 import javax.swing.event.*;
@@ -16,14 +15,15 @@
 import javax.xml.transform.*;
 import javax.xml.parsers.*;
 
-import org.biomoby.client.MobyRequest;
-import org.biomoby.client.MobyRequestEvent;
-import org.biomoby.client.MobyRequestEventHandler;
+import org.w3c.dom.*;
+
+import org.biomoby.client.*;
 import org.biomoby.registry.meta.*;
 import org.biomoby.shared.*;
 import org.biomoby.shared.data.*;
 
 import ca.ucalgary.seahawk.util.*;
+import ca.ucalgary.seahawk.services.MobyClient;
 
 /**
  * Main interface component: textually displays the data in a MOBY content XML document.
@@ -62,6 +62,10 @@
     public final static String FILE_OPEN_OPTION = "Open File";
     public final static String WEB_OPEN_OPTION = "Open Web Page";
 
+    public final static String SEAHAWK_NS_URI = "http://moby.ucalgary.ca/seahawk";
+    public final static String SEAHAWK_NS_PREFIX = "seahawk";
+    public final static String SEAHAWK_XPATH_ATTR = "xpath";
+
     private int lastClickX = 0;
     private int lastClickY = 0;
     private JTabbedPane tabbedPane;
@@ -88,6 +92,8 @@
     
     private static int defaultCloseOperation = JFrame.EXIT_ON_CLOSE;
     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(MobyContentGUI.class);
+    private static Acme.Serve.Serve servletContainer;
+
     /**
      * Constructor for a standalone visual interface.
      */
@@ -215,6 +221,151 @@
 	settingsGUI = new SeahawkOptionsGUI(this);
     }
 
+    public Acme.Serve.Serve getServletContainer(){
+	return servletContainer;
+    }
+
+    /**
+     * A shared resource for proxying requests such as WSDL PBE wrapping
+     */
+    public void setServletContainer(Acme.Serve.Serve sc){
+	servletContainer = sc;
+    }
+
+    /**
+     * This method is called by the Programming-by-example (PBE) system when
+     * we have the response from a service that's being semantically wrapped.
+     * To help the user out with the wrapping, we'll see if the MOB rules
+     * pick up any MOBY objects in the data.  Otherwise they'll have to do extra
+     * steps to cast the returned data, etc..
+     *
+     * @return the number of Moby objects found in the data.
+     */
+    public int processServiceResults(Node responseDOM) throws Exception{
+
+	MobyClient client = servicesGUI.getMobyClient();
+	// recursively traverse the DOM and check if any of the text nodes matches text-based MOB rules
+	Vector<MobyDataObject> objectsFound = getMobyObjects(responseDOM, client, "", "");
+
+	// Sort the data into sublists based on using identical XPaths (name-based, not position based), 
+	// encoded in each object's articleName.  This allows us to generalize the xpath -> data type 
+	// mapping the user should pick.
+	Map<String,Vector<MobyDataObject>> xpath2objs = new HashMap<String,Vector<MobyDataObject>>();
+	for(MobyDataObject data: objectsFound){
+	    String dataXPath = data.getName().split("#")[0];
+	    if(!xpath2objs.containsKey(dataXPath)){
+		xpath2objs.put(dataXPath, new Vector<MobyDataObject>());
+	    }
+	    xpath2objs.get(dataXPath).add(data);
+	}
+	MobyContentInstance mci = new MobyContentInstance();
+	for(String xPath: xpath2objs.keySet()){
+	    MobyDataJob part = new MobyDataJob();
+	    int i = 1;
+	    MobyDataObjectSet set = new MobyDataObjectSet("all");
+	    for(MobyDataObject obj: xpath2objs.get(xPath)){ 
+		set.add(obj);
+	    }
+	    part.put("all", set);
+	    mci.put("of the form "+xPath, part);
+	}
+	
+	// Insert an instruction message for the user in the comments TODO
+	mci.setServiceNotes("<b>NOTE:</b> To create from this example a " +
+			    "<i><b>new Moby service</b></i> that can be called again later, " +
+			    "1) click any link in the detected data below and " +
+			    "select \""+MobyContentPane.SERVICE_CREATION_MSG+"\" from the " +
+			    "popup menu, or 2) click a link in the parsed Web browser results.");
+
+	// Now show the data in the Seahawk service-wrapping tab
+	// Delete temp file when program exits.
+	File resultFile = null;
+	try{
+	    resultFile = File.createTempFile(MobyContentPane.WSDL_RESULTFILE_PREFIX, ".xml");
+	}
+	catch(Exception e){
+	    logger.error("Cannot create temp file for Moby objects found in service results:" + e);
+	    return 0;
+	}
+	resultFile.deleteOnExit();
+
+	FileOutputStream fos = new FileOutputStream(resultFile);
+	MobyDataUtils.toXMLDocument(fos, mci);
+	fos.close();
+
+	for(int i = 0; i < tabbedPane.getTabCount(); i++){
+	    MobyContentPane pane = (MobyContentPane) tabbedPane.getComponentAt(i);
+	    if(pane.isWrappingService()){
+		pane.gotoURL(resultFile.toURI().toURL(), false); //false = don't put in history
+		tabbedPane.setSelectedIndex(i);
+		break;
+	    }
+	}
+
+	return objectsFound.size();
+    }
+
+    // xPointer is a bit of a misnomer, it's actualy a unique identifying xPath to give NS context for the xPath var's evaluation
+    private Vector<MobyDataObject> getMobyObjects(Node node, MobyClient client, String xPath, String xPointer) throws Exception{
+	Vector<MobyDataObject> results = new Vector<MobyDataObject>();
+
+	// get XPath-based answers
+	for(Map.Entry<String,MobyDataObject[]> generatedObjects: client.getMobyObjectsURNMap(node).entrySet()){
+	    for(MobyDataObject xmlObject: generatedObjects.getValue()){
+		xmlObject.setName(xPath+"#"+xPointer+"#"+generatedObjects.getKey());
+		results.add(xmlObject);
+	    }
+	}
+
+	// While we traverse the nodes looking for data, add an attr with the xpath of the element, 
+	// as it may be useful for the PBE system later...
+	NodeList childNodes = node.getChildNodes();
+	int elementCount = 0;
+	for(int i = 0; i < childNodes.getLength(); i++){
+	    Node childNode = childNodes.item(i);
+	    if(childNode instanceof Element){
+		elementCount++;
+		String newXPath = xPath+"/"+childNode.getNodeName();
+		String newXPointer = xPointer+"/"+elementCount+"";
+		((Element) childNode).setAttributeNS(SEAHAWK_NS_URI, SEAHAWK_NS_PREFIX+":"+SEAHAWK_XPATH_ATTR, 
+						     newXPath+"#"+newXPointer);
+		results.addAll(getMobyObjects(childNode, client, newXPath, newXPointer));
+	    }
+	    else if(childNode instanceof Attr){
+		// Map<ruleURN,mobyObjectsGenerated>
+		for(Map.Entry<String,MobyDataObject[]> generatedObjects: 
+			client.getMobyObjectsURNMap(((Attr) childNode).getValue()).entrySet()){
+		    for(MobyDataObject textObject: generatedObjects.getValue()){
+			// generatedObjects.getKey() is the generating rule's URN
+			textObject.setName(xPath+"/@"+childNode.getNodeName()+"#"+xPointer+"#"+generatedObjects.getKey());
+			results.add(textObject);
+		    }
+		}
+	    }
+	    else if(childNode instanceof CharacterData){
+		if(childNode instanceof Comment){
+		    continue;
+		}
+		for(Map.Entry<String,MobyDataObject[]> generatedObjects: 
+			client.getMobyObjectsURNMap(((CharacterData) childNode).getData()).entrySet()){
+		    for(MobyDataObject textObject: generatedObjects.getValue()){
+			textObject.setName(xPath+"/text()#"+xPointer+"#"+generatedObjects.getKey());
+			results.add(textObject);
+		    }
+		}
+	    }
+	}
+
+	return results;
+    }
+
+    /**
+     * Explicitly stop the servlet container, if running, that is used for WSDL service wrapping.
+     */
+    public void stopServletContainer() throws IOException{
+	servletContainer.notifyStop();
+    }
+
     public boolean allTabsVisible(){
 	if(tabbedPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT){
 	    return true;
@@ -486,6 +637,15 @@
 	}
     }
 
+    public CentralImpl getMobyCentralImpl(){
+	if(servicesGUI != null){
+	    return servicesGUI.getMobyCentralImpl();
+	}
+	else{
+	    return null;
+	}
+    }
+
     public void saveCurrentPane(){
 	MobySaveDialog.exportDocument((MobyContentPane) tabbedPane.getSelectedComponent());
     }
@@ -573,6 +733,40 @@
     }
 
     /**
+     * Called after a service has been created by the wrapping system, with the intention
+     * that the new service should be called and included in the browsing session.
+     */
+    public void serviceWrapped(String providerURI, String serviceName, MobyDataJob sampleData) throws Exception{
+	CentralImpl central = getMobyCentralImpl();
+	MobyService[] services = central.findService(new MobyService(serviceName, providerURI)); 
+	if(services == null || services.length == 0){
+	    throw new Exception("Could not find the new service ("+providerURI+","+serviceName+
+				") in the registry.");
+	}
+	else if(services.length > 1){
+	    throw new Exception("More than one service matching ("+providerURI+","+serviceName+
+				") was found in the registry, something is seriously wrong!");
+	}
+
+	MobyRequest request = new MobyRequest(central);
+	request.setService(services[0]);
+	MobyContentInstance inEnvelope = new MobyContentInstance();
+	inEnvelope.put("test", sampleData);
+	request.setInput(inEnvelope);
+	MobyContentInstance result = request.invokeService();
+
+	for(int i = 0; i < tabbedPane.getTabCount(); i++){
+	    MobyContentPane pane = (MobyContentPane) tabbedPane.getComponentAt(i);
+	    if(pane.isWrappingService()){
+		tabbedPane.setSelectedIndex(i);
+		loadPaneFromObject(result, true); //true = put in history
+		break;
+	    }
+	}	
+	
+    }
+
+    /**
      * Load a Seahawk browser tab with the data held in the given MobyContentInstance.
      * Note that this methods take a snapshot of the data when it is passed in.  Subsequent
      * changes to the MobyContentInstance will not be reflected in the Seahawk display.
@@ -599,6 +793,7 @@
 	    currentPane = createTab("File Loading");
 	}
 	currentPane.setWaitScreen();
+
 	currentPane.gotoURL(u, true);
 	if(u != null){
 	    currentPane.succeeded(urlToTitle(u));
@@ -844,6 +1039,12 @@
 	// etc. by forcing resource loading for the only supported locale, _en
 	java.util.Locale.setDefault(java.util.Locale.ENGLISH);
 
+	// Unless overridden on the command line, use the cached calls moby central impl
+ 	if(System.getProperty(CentralImpl.CENTRAL_IMPL_RESOURCE_NAME) == null){
+ 	    System.setProperty(CentralImpl.CENTRAL_IMPL_RESOURCE_NAME,
+ 			       "org.biomoby.client.CentralCachedCallsImpl");
+ 	}
+
 	// Unless overridden on the command line, use xalan
  	if(System.getProperty("javax.xml.transform.TransformerFactory") == null){
  	    System.setProperty("javax.xml.transform.TransformerFactory",
@@ -856,6 +1057,10 @@
  			       "org.apache.xerces.parsers.StandardParserConfiguration");
  	}
 
+	//includes socket-less client
+// 	System.setProperty("axis.ClientConfigFile",
+// 			   "ca/ucalgary/services/util/client-config.wsdd");  
+
 	// First, restore any user preferences (uses default settings file location)
 	try{
 	    SeahawkOptions.restoreSettings();
@@ -865,8 +1070,6 @@
 			       SeahawkOptions.getDefaultsFile()+": "+ e);
 	}
 	// Asynchronously load up ontology data so it's ready when the user needs it.
-	cacheOntologies();
-	try{Thread.sleep(5000);}catch(Exception e){System.err.println("Sleep interrupted");}
 	MobyContentGUI gui = MobyUtils.getMobyContentGUI(new JLabel());
 	gui.setDefaultCloseOperation(defaultCloseOperation);
 




More information about the MOBY-guts mailing list