[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Fri Jul 22 05:23:00 UTC 2005
gordonp
Fri Jul 22 01:23:00 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv30907
Modified Files:
MobyRequest.java
Log Message:
Updated to use the new data instance classes
moby-live/Java/src/main/org/biomoby/client MobyRequest.java,1.13,1.14
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java 2005/07/19 13:16:53 1.13
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java 2005/07/22 05:23:00 1.14
@@ -23,10 +23,7 @@
import org.apache.xpath.objects.XObject;
import org.biomoby.shared.Central;
import org.biomoby.shared.MobyData;
-import org.biomoby.shared.data.MobyDataInstance;
-import org.biomoby.shared.data.MobyDataSecondaryInstance;
-import org.biomoby.shared.data.MobyDataObjectSet;
-import org.biomoby.shared.data.MobyDataObject;
+import org.biomoby.shared.data.*;
import org.biomoby.shared.MobyException;
import org.biomoby.shared.MobyPrefixResolver;
import org.biomoby.shared.MobyService;
@@ -58,7 +55,7 @@
protected MobyService mobyService = null;
protected MobyDataInstance[] inputData = null;
protected MobyDataSecondaryInstance[] secondaryData = null;
- protected Vector outputData = null;
+ protected MobyContentInstance outputData = null;
protected Central mobyCentral = null;
protected PrefixResolver mobyPrefixResolver = null;
@@ -76,7 +73,6 @@
private XPath stringEncodedXPath;
private XPath base64EncodedXPath;
- private XPath queryResponseXPath;
private XPath simpleChildXPath;
private XPath collectionChildXPath;
@@ -117,9 +113,8 @@
MobyPrefixResolver.XSI1999_PREFIX+
":type, ':')=\"string\" or substring-after(@"+
MobyPrefixResolver.XSI2001_PREFIX+
- ":type, ':')=\"string\"]", null,
- mobyPrefixResolver, XPath.SELECT);
- queryResponseXPath = new XPath("//moby:mobyData | //mobyData", null,
+ ":type, ':')=\"string\"] | //"+
+ MobyPrefixResolver.SOAP_ENC_PREFIX+":string", null,
mobyPrefixResolver, XPath.SELECT);
simpleChildXPath = new XPath("moby:Simple | Simple", null,
mobyPrefixResolver, XPath.SELECT);
@@ -233,7 +228,7 @@
*
* @throws MobyException if you try to get the results before calling InvokeService
*/
- public Vector getOutput() throws MobyException{
+ public MobyContentInstance getOutput() throws MobyException{
if(outputData == null){
throw new MobyException("Trying to access MOBY service results " +
"before the service is invoked");
@@ -255,7 +250,7 @@
* @throws MobyException i.e. there was something wrong with the input, output or remote service's logic
* @throws SOAPException i.e. there was a problem with the underlying transaction/transport layer
*/
- public Vector invokeService() throws MobyException, SOAPException, NoSuccessException{
+ public MobyContentInstance invokeService() throws Exception, MobyException, SOAPException, NoSuccessException{
if(mobyService == null){
throw new MobyException("Tries to invoke null service from MobyRequest (call setService first)");
}
@@ -264,7 +259,8 @@
verifyInput();
String mobyXML = convertMOBYDataToMOBYRequest(inputData, secondaryData);
Element mobyDOM = performSOAPRequest(mobyXML);
- outputData = convertMOBYResponseToMOBYData(mobyDOM);
+ // The following parses the DOM and extracts all the appropriate jMOBY objects to represent the XML in Java
+ outputData = MobyDataUtils.fromXMLDocument(mobyDOM);
return outputData;
}
@@ -418,8 +414,9 @@
XPath responseElementXPath = null;
try{
responseElementXPath = new XPath("//"+ MobyPrefixResolver.MOBY_TRANSPORT_PREFIX+
- ":"+mobyService.getName()+"Response",
- null, mobyPrefixResolver, XPath.SELECT);
+ ":"+mobyService.getName()+"Response | //" +
+ mobyService.getName()+"Response",
+ null, mobyPrefixResolver, XPath.SELECT);
}catch(TransformerException te){
throw new SOAPException("Cannot select SOAP nodes due to exception "+
"while compiling XPath statement (code bug?):" +te);
@@ -480,11 +477,11 @@
node_list = runXPath(stringEncodedXPath, responseNode);
}
catch(TransformerException te){
- throw new SOAPException("Cannot select base64 encoded SOAP nodes due to exception "+
+ throw new SOAPException("Cannot select string encoded SOAP nodes due to exception "+
"while executing XPath statement:" +te);
}
- // Do decoding for each base64 part found
+ // Do concatenation for each plain string part found
for(int i = 0; node_list != null && i < node_list.getLength(); i++){
org.w3c.dom.Node change = node_list.item(i);
/* Make sure the text data is all put into one contiguous piece for decoding*/
@@ -497,11 +494,12 @@
Node child = children.item(j);
if(child instanceof CDATASection || child instanceof Text){
plainString += child.getNodeValue();
+ System.err.println("Plain string is now " + plainString);
}
}
// Swap out this node for the decoded data
- change.getParentNode().replaceChild(n.getOwnerDocument().createTextNode(plainString), change);
+ change.getParentNode().replaceChild(n.getOwnerDocument().createCDATASection(plainString), change);
}
if(debug && node_list != null){
debugPS.println("There were " + node_list.getLength() +
@@ -523,7 +521,14 @@
for(int j = 0; j < children.getLength(); j++){
Node child = children.item(j);
if(child instanceof CDATASection || child instanceof Text){
- responseString += child.getNodeValue();
+ // Unescape XML special characters in the string, so we can later on
+ // parse the payload as regular XML.
+ // Ignore whitespace-only node
+ if(child.getNodeValue().matches("^\\s+$")){
+ continue;
+ }
+ System.err.println("Concatenating text in response " + child.getNodeValue());
+ responseString += child.getNodeValue();//.replaceAll("<", "<").replaceAll(">", ">").replaceAll("(&|F)", "&");
}
}
@@ -639,103 +644,6 @@
}
/**
- * This method takes the internally stored DOM, representing the MOBY response
- * from the service and converst it into the standard jMOBY API Data representation.
- *
- * @throws MobyException if the MOBY message does not conform to the API
- */
- public Vector convertMOBYResponseToMOBYData(Element n) throws MobyException{
- //
- Vector responsesOutput = new Vector();
-
- NodeList response_list = null;
- try{
- response_list = runXPath(queryResponseXPath, n);
- }catch(TransformerException te){
- throw new MobyException("Cannot select MOBY DOM mobyContent nodes due to exception "+
- "while executing XPath statement: " +te);
- }
-
- if(response_list == null || response_list.getLength() == 0){
- throw new MobyException("Could not find any mobyContent elements in the output");
- }
- if(debug){
- debugPS.println("Aha! Got " + response_list.getLength() + " mobyContent response elements");
- }
- // Do data decoding for each response's mobyData
- for(int i = 0; i < response_list.getLength(); i++){
- Node response = response_list.item(i);
-
- Vector out = new Vector();
- // Find all the collections in the response
- NodeList collections = null;
- try{
- collections = runXPath(collectionChildXPath, response);
- }catch(TransformerException te){
- throw new MobyException("Cannot select MOBY DOM mobyData/Collection nodes due to exception "+
- "while executing XPath statement: " +te);
- }
- for(int j = 0; collections != null && j < collections.getLength(); j++){
- if(debug & j == 0)
- debugPS.println("There are " + collections.getLength() +
- " collections in response #" +i);
- MobyDataObjectSet collection = new MobyDataObjectSet("");
-
- // For each collection, find the simple children
- NodeList subsimples = null;
- try{subsimples = runXPath(simpleChildXPath, collections.item(j));}
- catch(TransformerException te){
- throw new MobyException("Cannot select MOBY DOM mobyData/Collection/Simple " +
- "nodes due to exception "+
- "while executing XPath statement: " +te);
- }
-
- // And add their values to the collection
- MobyDataObject[] subout = new MobyDataObject[subsimples.getLength()];
- for(int k = 0; k < subsimples.getLength(); k++){
- if(debug && k == 0)
- debugPS.println("There are " + subsimples.getLength() +
- " simples in response #" + i +
- ", collection #" + j);
- subout[k] = (MobyDataObject) MobyDataObject.createInstanceFromDOM((Element) subsimples.item(k));
- }
- collection.setElements(subout);
- releaseXPath(collections.item(j));
- // Add completed collection to the output list
- out.add(collection);
- }
-
- // Take all the top level simples and add them to the list
- NodeList simples = null;
- try{
- simples = runXPath(simpleChildXPath, response);
- }catch(TransformerException te){
- throw new MobyException("Cannot select MOBY DOM mobyData/Collection nodes due to exception "+
- "while executing XPath statement: " +te);
- }
- if((collections == null || collections.getLength() == 0) &&
- (simples == null || simples.getLength() == 0)){
- debugPS.println("WARNING: There appears to be no output data in mobyData #" + i);
- }
- for(int j = 0; simples != null && j < simples.getLength(); j++){
- if(debug && j == 0)
- debugPS.println("There are " + simples.getLength() + " simples in response #" +i);
- out.add(MobyDataObject.createInstanceFromDOM((Element) simples.item(j)));
- }
-
- // What we're building is a Vector, where each element represents
- // a Response's DataInstance Output (i.e. Simple and Collection return values)
- MobyDataInstance[] mdis = new MobyDataInstance[out.size()];
- responsesOutput.add(out.toArray(mdis));
-
- releaseXPath(response);
- }
- // release resources related to the Xpath execution, since we won't be using this doc anymore
- releaseXPath(n);
- return responsesOutput;
- }
-
- /**
* A method that sets up the execution environm,ent for and runs a compiled XPath statement against a DOM node
* You should call releaseXPath when you're done with the results
* @return the list of Nodes that satisfy the XPath in this Node's context
More information about the MOBY-guts
mailing list