[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Mar 12 00:02:46 UTC 2009


gordonp
Wed Mar 11 20:02:46 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv7952/src/main/org/biomoby/shared

Modified Files:
	NamespaceContextImpl.java 
Log Message:
Added c-tor that creates a context based on a given DOM node, to be used in the Seahawk PBE system
moby-live/Java/src/main/org/biomoby/shared NamespaceContextImpl.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java	2008/03/12 17:47:18	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java	2009/03/12 00:02:46	1.6
@@ -1,6 +1,8 @@
 
 package org.biomoby.shared;
 
+import org.w3c.dom.*;
+
 import javax.xml.namespace.NamespaceContext;
 
 import java.util.HashMap;
@@ -16,6 +18,51 @@
     private Map<String, String> prefixes;
     private Map<String, String> nsURIs;
 
+    /**
+     * Traverses up the DOM from the given element to enumerate all of the prefix <-> namespace mappings
+     * valid for this node.  Note that the DOM does not explicitly contain the xmlns attributes
+     * therefore we glean this info from the qualified elements and attributes.
+     */
+    public NamespaceContextImpl(Node contextNode, String defaultNSPrefix){
+	prefixes = new HashMap<String, String>();
+	nsURIs = new HashMap<String, String>();
+
+	for(Node currentNode = contextNode; currentNode != null; currentNode = currentNode.getParentNode()){
+	    if(currentNode instanceof Element){
+		Element el = (Element) currentNode; 
+		String uri = el.getNamespaceURI();
+		String prefix = el.getPrefix();
+		if(uri != null && uri.length() != 0){
+		    if(prefix == null){
+			prefix = defaultNSPrefix;
+		    }
+		    if(!nsURIs.containsKey(prefix)){
+			nsURIs.put(prefix, uri);
+		    }
+		}
+
+		NamedNodeMap xmlnsAttrs = ((Element) currentNode).getAttributes();
+		for(int i = 0; i < xmlnsAttrs.getLength(); i++){
+		    Attr xmlnsDecl = (Attr) xmlnsAttrs.item(i);
+		    if(xmlnsDecl.getNamespaceURI() == null ||
+		       xmlnsDecl.getPrefix() == null){
+			continue;
+		    }
+
+		    if(!prefixes.containsKey(xmlnsDecl.getNamespaceURI())){
+			prefixes.put(xmlnsDecl.getNamespaceURI(), xmlnsDecl.getPrefix());
+		    }
+		    if(!nsURIs.containsKey(xmlnsDecl.getPrefix())){
+			nsURIs.put(xmlnsDecl.getPrefix(), xmlnsDecl.getNamespaceURI());
+		    }
+		}
+	    }
+	}		
+    }
+
+    /**
+     * Populates the mapping table with an assortment of prefixes and namespaces used in Moby (see MobyPrefixResolver)
+     */
     public NamespaceContextImpl(){
 	prefixes = new HashMap<String, String>();
 	nsURIs = new HashMap<String, String>();
@@ -35,6 +82,7 @@
 	prefixes.put(MobyPrefixResolver.HTTP_NAMESPACE, MobyPrefixResolver.HTTP_PREFIX);
 	prefixes.put(MobyPrefixResolver.SAWSDL_NAMESPACE, MobyPrefixResolver.SAWSDL_PREFIX);
 	prefixes.put(MobyPrefixResolver.LSID_NAMESPACE, MobyPrefixResolver.LSID_PREFIX);
+	prefixes.put(MobyPrefixResolver.XSD_NAMESPACE, MobyPrefixResolver.XSD_PREFIX);
 
 	// Reverse map prefix -> nsURI
 	nsURIs.put(MobyPrefixResolver.XSI_PREFIX, MobyPrefixResolver.XSI_NAMESPACE2001);




More information about the MOBY-guts mailing list