[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Aug 26 22:02:18 UTC 2009


gordonp
Wed Aug 26 18:02:18 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services
In directory dev.open-bio.org:/tmp/cvs-serv32472/src/main/ca/ucalgary/services

Modified Files:
	SoapServlet.java 
Log Message:
Fix to avoid namespace collision between XML scehma elements and XML schema types in the WSDL doc
moby-live/Java/src/main/ca/ucalgary/services SoapServlet.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/20 19:52:09	1.5
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/26 22:02:18	1.6
@@ -20,6 +20,11 @@
 import java.util.*;
 import java.io.*;
 
+/**
+ * Provides an HTML interface for invoking SOAP-based Web Services. The appearance and functionality of the class
+ * can be extended using stylesheets and registering a DataRecorder (e.g. Daggoo registers PBERecorder to get 
+ * its functionality), please see the documentation at http://biomoby.open-bio.org/CVS_CONTENT/moby-live/Java/docs/soapServlet.html
+ */
 public class SoapServlet extends HttpServlet{
 
     public static final String DATARECORDER_CONTEXTPARAM = "dataRecorder"; // how users spec a DataRecorder in the web.xml
@@ -842,6 +847,8 @@
 									    "types");  
 			    Map<QName,Map<String,QName>> element2Members = 
 				new LinkedHashMap<QName,Map<String,QName>>();	   
+			    Map<QName,Map<String,QName>> type2Members = 
+				new LinkedHashMap<QName,Map<String,QName>>();	   
 			    for(int m = 0; m < types.getLength(); m++){
 				Element typeTag = (Element) types.item(m);
 				MyNodeList typeDefs = new MyNodeList();
@@ -870,8 +877,17 @@
 				    // It could either be a basic type (handled right here), or a complex one with subfields
 				    String elementType = element.getAttribute("type");
 				    if(elementType != null && elementType.trim().length() != 0){
-					memberMap.put(BASIC_TYPE_SENTINEL, getQName(elementType, element));
-					memberMap.put(BASIC_NAME_SENTINEL, new QName(null, elementName));
+					QName eT = getQName(elementType, element);
+					if(eT.getNamespaceURI() == null ||
+					   eT.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")){
+					    memberMap.put(BASIC_TYPE_SENTINEL, eT);
+					    memberMap.put(BASIC_NAME_SENTINEL, new QName(null, elementName));
+					}
+					else{
+					    // pointer to complex type elsewhere in the schema tag
+					    memberMap.put(BASIC_TYPE_SENTINEL, getQName(getRef(eT), element));
+					    memberMap.put(BASIC_NAME_SENTINEL, new QName(null, elementName));
+					}
 				    }
 
 				    NodeList subelements = element.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
@@ -884,22 +900,20 @@
 					if(restrictions.getLength() == 0){
 					    restrictions = element.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
 											  "extension");
-					    if(restrictions.getLength() == 0){
-						//out.print("Error: Could not find the restriction or extension " +
-						//	  "attribute for a simple type " +
-						//	  " schema element " + elementName);
+					    if(restrictions.getLength() != 0){
+						String baseAttr = restrictions.getLength() == 0 ? "xs:string" : 
+						    ((Element) restrictions.item(0)).getAttribute("base");
+						QName baseType = getQName(baseAttr, element);
+						QName anonQName = getQName(baseAttr+"SubType"+anonCount++, element);
+						memberMap.put(BASIC_TYPE_SENTINEL, anonQName);
+						memberMap.put(BASIC_NAME_SENTINEL, new QName(null, elementName));
 					    }
+					    // else, some time you just get a blank type...
 					}
 					else{
+					    // TODO handle extension properly
 					    
 					}
-					String baseAttr = restrictions.getLength() == 0 ? "xs:string" : 
-					    ((Element) restrictions.item(0)).getAttribute("base");
-					QName baseType = getQName(baseAttr, element);
-					QName anonQName = getQName(baseAttr+"SubType"+anonCount++, element);
-					// TODO handle extension properly
-					memberMap.put(BASIC_TYPE_SENTINEL, anonQName);
-					memberMap.put(BASIC_NAME_SENTINEL, new QName(null, elementName));
 				    }
 				    for(int p = 0; p < subelements.getLength(); p++){
 					Element subelement = (Element) subelements.item(p);
@@ -973,7 +987,12 @@
 					}
 				    }
 
-				    element2Members.put(getQName(elementName, element), memberMap);
+				    if(element.getLocalName().equals("element")){					
+					element2Members.put(getQName(elementName, element), memberMap);
+				    }
+				    else{ //probably complexType def
+					type2Members.put(getQName(elementName, element), memberMap);
+				    }
 				}  //end for <schema><element|complexType>...
 			    }  //for wsdl:types
 			    
@@ -1013,21 +1032,31 @@
 					Map<String,QName> subpartsMap = element2Members.get(dataType);
 					if(subpartsMap == null){
 					    if(dataType.getNamespaceURI().equals("http://schemas.xmlsoap.org/soap/encoding/")){
-						writeDataType(out, part.getKey(), part.getValue(), element2Members, "");
+						writeDataType(out, part.getKey(),
+							      part.getValue(), element2Members, type2Members, "");
+					    }
+					    else{
+						out.print("Error: cannot find definition for data type " + 
+							  dataType + "\nValid types are:");
+						for(QName key: element2Members.keySet()){
+						    out.print(" "+key);
+						}
 					    }
-					    out.print("Error: cannot find definition for data type " + 
-						      dataType + "\nValid types are:");
-					    for(QName key: element2Members.keySet()){
- 						out.print(" "+key);
- 					    }
 					    continue;
 					}
-					for(Map.Entry<String,QName> subpart: subpartsMap.entrySet()){
-					    writeDataType(out, subpart.getKey(), subpart.getValue(), element2Members, "");
+					if(subpartsMap.containsKey(BASIC_TYPE_SENTINEL)){
+					    writeDataType(out, messageQName.getLocalPart(),
+							  subpartsMap.get(BASIC_TYPE_SENTINEL), 
+							  type2Members, type2Members, "");
+					}
+					else{
+					    for(Map.Entry<String,QName> subpart: subpartsMap.entrySet()){
+						writeDataType(out, subpart.getKey(), subpart.getValue(), type2Members, type2Members, "");
+					    }
 					}
 				    }
 				    else{ // rpc style
-					writeDataType(out, part.getKey(), part.getValue(), element2Members, "");
+					writeDataType(out, part.getKey(), part.getValue(), element2Members, type2Members, "");
 				    }
 				}  // for parts
 				// special condition for rpc calls, still need to give the op ns & name
@@ -1154,7 +1183,8 @@
     }
 
     private void writeDataType(java.io.PrintStream out, String memberName, QName dataType, 
-			       Map<QName,Map<String,QName>> msg2Parts, String prefix){
+			       Map<QName,Map<String,QName>> msg2Parts, 
+			       Map<QName,Map<String,QName>> type2Parts, String prefix){
 
 	String datatype = dataType.getLocalPart();
 
@@ -1268,11 +1298,14 @@
 	else{  // doc/lit or complex rpc type
 	    Map<String,QName> subparts = msg2Parts.get(dataType);
 	    if(subparts == null){
-		out.print("Error: cannot find definition for data type " + dataType); //+"\nValid types are:");
-	// 	for(QName key: msg2Parts.keySet()){
-// 		    out.print(" "+key);
-// 		}
-		return;
+		subparts = type2Parts.get(dataType);
+		if(subparts == null){
+		    out.print("Error: cannot find definition for data type " + dataType); //+"\nValid types are:");
+		    // 	for(QName key: msg2Parts.keySet()){
+		    // 		    out.print(" "+key);
+		    // 		}
+		    return;
+		}
 	    }
 	    else if(subparts.containsKey(BASIC_TYPE_SENTINEL)){
 		QName typeName = subparts.get(BASIC_TYPE_SENTINEL);
@@ -1282,14 +1315,14 @@
 		if(isOptional){
 		    typeName = new QName(typeName.getNamespaceURI(), typeName.getLocalPart()+"~");
 		}
-		writeDataType(out, memberName, typeName, msg2Parts, prefix);
+		writeDataType(out, memberName, typeName, type2Parts, type2Parts, prefix);
 	    }
 	    else{
 		// currently we don't handle arrays of composites in the form...
-		out.print("<table border=\"1\"><tr bgcolor=\"#DDDDDD\"><td>Composite "+memberName+
+		out.print("<table border=\"1\"><tr bgcolor=\"#DDDDDD\"><td>Composite "+ memberName +
 			  " ("+(isOptional?"optional, ":"")+ datatype + "):</td></tr><tr><td>");
 		for(Map.Entry<String,QName> subpart: subparts.entrySet()){
-		    writeDataType(out, subpart.getKey(), subpart.getValue(), msg2Parts, prefix+memberName+":");
+		    writeDataType(out, subpart.getKey(), subpart.getValue(), type2Parts, type2Parts, prefix+memberName+":");
 		}
 		out.print("</td></tr></table>\n");
 	    }




More information about the MOBY-guts mailing list