[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Oct 25 02:33:23 UTC 2006


gordonp
Tue Oct 24 22:33:23 EDT 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser
In directory dev.open-bio.org:/tmp/cvs-serv9957/src/main/org/biomoby/shared/parser

Modified Files:
	JDOMUtils.java ServiceException.java 
Log Message:
Added MobyServlet and Seahawk initial versions to the repository
moby-live/Java/src/main/org/biomoby/shared/parser JDOMUtils.java,1.1,1.2 ServiceException.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/JDOMUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/JDOMUtils.java	2006/07/07 04:12:40	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/JDOMUtils.java	2006/10/25 02:33:23	1.2
@@ -5,8 +5,87 @@
 import org.jdom.Element;
 import org.jdom.Namespace;
 
+import java.util.Iterator;
+import java.util.Vector;
+
 public class JDOMUtils{
     /**************************************************************************
+     *
+     *************************************************************************/
+    public static Element toXMLElement(ServiceException se) {
+	Element elem = MobyPackage.getXMLElement (MobyTags.MOBYEXCEPTION);
+	MobyPackage.setXMLAttribute (elem, MobyTags.SEVERITY, se.getSeverityAsString());
+	if (se.getJobId() != null)
+	    MobyPackage.setXMLAttribute (elem, MobyTags.REFQUERYID, se.getJobId());
+	if (se.getDataName() != null)
+	    MobyPackage.setXMLAttribute (elem, MobyTags.REFELEMENT, se.getDataName());
+	Element elemCode = MobyPackage.getXMLElement (MobyTags.EXCEPTIONCODE);
+	elemCode.setText (""+se.getErrorCode());
+	elem.addContent (elemCode);
+	String desc = se.getMessage();
+	if (desc != null) {
+	    Element elemDesc = MobyPackage.getXMLElement (MobyTags.EXCEPTIONMESSAGE);
+	    elemDesc.setText (desc);
+	    elem.addContent (elemDesc);
+	}
+	return elem;
+    }
+
+    /**************************************************************************
+     * Extract all exceptions from a <em>serviceNotes</em> XML
+     * element. This is a convenient method that can be used when
+     * dealing with an XML response from a service without parsing the
+     * whole response to a {@link MobyPackage}. <p>
+     *
+     * @param serviceNotes a piece of XML
+     * <tt>&lt;serviceNotes&gt;...&lt;/serviceNotes&gt;</tt>
+     *
+     * @return an array, potentially an empty array, of all exceptions
+     * extracted from the 'serviceNotes'
+     *************************************************************************/
+    public static ServiceException[] extractExceptions (Element serviceNotes) {
+	if (serviceNotes == null)
+	    return new ServiceException[] {};
+
+	Vector v = new Vector();
+	for (Iterator it =
+		 serviceNotes.getChildren (MobyTags.MOBYEXCEPTION).iterator();
+	     it.hasNext(); ) {
+	    ServiceException ex = extractException ((Element)it.next());
+	    if (ex != null)
+		v.addElement (ex);
+	}
+	for (Iterator it =
+		 serviceNotes.getChildren (MobyTags.MOBYEXCEPTION, JDOMUtils.MOBY_NS).iterator();
+	     it.hasNext(); ) {
+	    ServiceException ex = extractException ((Element)it.next());
+	    if (ex != null)
+		v.addElement (ex);
+	}
+	ServiceException[] result = new ServiceException [v.size()];
+	v.copyInto (result);
+	return result;
+    }
+
+    /**************************************************************************
+     * Extract one exception from an XML element 'mobyException'.
+     *************************************************************************/
+    protected static ServiceException extractException (Element elem) {
+	ServiceException ex = new ServiceException();
+	String severity = elem.getAttributeValue (MobyTags.SEVERITY);
+	if (severity == null)
+	    severity = elem.getAttributeValue (MobyTags.SEVERITY, JDOMUtils.MOBY_NS);
+	ex.setSeverity (severity);
+	String codeStr = JDOMUtils.getChildText (elem, MobyTags.EXCEPTIONCODE);
+	try {
+	    ex.setErrorCode (new Integer (codeStr).intValue());
+	} catch (Exception e) {
+	}
+	ex.setMessage (JDOMUtils.getChildText (elem, MobyTags.EXCEPTIONMESSAGE));
+	return ex;
+    }
+
+    /**************************************************************************
      * Turns a PIB Object into a JDOM representation.
      *************************************************************************/
     public static Element toXMLElement(MobyProvisionInfo mpi) {

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/ServiceException.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/ServiceException.java	2006/07/07 04:12:40	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/parser/ServiceException.java	2006/10/25 02:33:23	1.10
@@ -492,7 +492,7 @@
 	xml.append("<moby:"+ MobyTags.EXCEPTIONCODE + ">"+code+"</moby:"+MobyTags.EXCEPTIONCODE+">");
 
 	if(getMessage() != null){
-	    xml.append("            <moby:"+MobyTags.EXCEPTIONMESSAGE+">"+getMessage());
+	    xml.append("            <moby:"+MobyTags.EXCEPTIONMESSAGE+">"+getMessage()+"</moby:"+MobyTags.EXCEPTIONMESSAGE+">");
 	}
 
 	xml.append("          </moby:" + MobyTags.MOBYEXCEPTION + ">");




More information about the MOBY-guts mailing list