[MOBY-guts] biomoby commit

Paul Gordon gordonp at pub.open-bio.org
Fri Jul 22 05:32:49 UTC 2005


gordonp
Fri Jul 22 01:32:49 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory pub.open-bio.org:/tmp/cvs-serv31034

Modified Files:
	MobyPrefixResolver.java 
Log Message:
Utility methods added that are used by data instance classes for ease of parsing

moby-live/Java/src/main/org/biomoby/shared MobyPrefixResolver.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyPrefixResolver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyPrefixResolver.java	2005/02/09 17:39:17	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyPrefixResolver.java	2005/07/22 05:32:49	1.4
@@ -1,6 +1,8 @@
 package org.biomoby.shared;
 
 import org.apache.xml.utils.PrefixResolver;
+import org.w3c.dom.*;
+import java.util.Vector;
 
 /**
  * The main purpose of this class is to provide default mapping from 
@@ -28,6 +30,8 @@
     public static final String XSI_PREFIX = "xsi";
     public static final String XSI1999_PREFIX = "xsi1999";
     public static final String XSI2001_PREFIX = "xsi2001";
+    public static final String SOAP_ENC_NAMESPACE ="http://schemas.xmlsoap.org/soap/encoding/";
+    public static final String SOAP_ENC_PREFIX ="soap-enc";
 
     /**
      * We don't really implement this as it can be extremely complicated.
@@ -52,6 +56,45 @@
     }
 
     /**
+     * Convenience method that matches attributes in the MOBY namespace or, for now
+     * at least, with no declared namespace.
+     * @return the value of the attribute, or null if the attribute does not exist
+     */
+    public static NodeList getChildElements(org.w3c.dom.Element e, String elementName){
+	MobyNodeList matches = new MobyNodeList();
+
+	NodeList children = e.getChildNodes();
+	for(int j = 0; children != null && j < children.getLength(); j++){
+	    // Make sure it's an element, not a processing instruction, text, etc.
+	    if(!(children.item(j) instanceof Element)){
+		continue;
+	    }
+	    Element child = (Element) children.item(j);
+	    // Make sure it has the right name
+	    if(!elementName.equals(child.getLocalName())){
+		continue;
+	    }
+	    // Make sure it's in the MOBY namespace, or no namespace at all
+	    String uri = child.getNamespaceURI();
+	    if(uri != null && uri.length() != 0 && !uri.equals(MOBY_XML_NAMESPACE)){
+		continue;
+	    }
+
+	    // Everything looks good
+	    matches.add(child);
+	}
+	return matches;
+    }
+
+    static class MobyNodeList implements NodeList{
+	private Vector nodes;
+	public MobyNodeList(){nodes = new Vector();}
+	public int getLength(){return nodes.size();}
+	public Node item(int index){return (Node) nodes.elementAt(index);}
+	public void add(Node n){nodes.add(n);}
+    };
+
+    /**
      * @return For now, default MOBY and XML Schema Instance (1999) prefices as defined in the class static variables
      */
     public String getNamespaceForPrefix(java.lang.String prefix){
@@ -73,6 +116,9 @@
 	else if(XSI2001_PREFIX.equals(prefix)){
 	    return XSI_NAMESPACE2001;  //Used by Axis
 	}
+	else if(SOAP_ENC_PREFIX.equals(prefix)){
+	    return SOAP_ENC_NAMESPACE;
+	}
 	else{
 	    return "";  // Indicates that we don't have a mapping for this prefix
 	}
@@ -81,7 +127,7 @@
     /**
      * Don't use this class if this method will be used.  We are not returning a 
      * valid XML namespace mapping, but a convenience method for XPath, therefore
-     * we will not given context sensitive mapping.
+     * we will not give context sensitive mapping.
      */
     public String getNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node context){
 	return getNamespaceForPrefix(prefix);




More information about the MOBY-guts mailing list