[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue Jun 9 18:59:33 UTC 2009


gordonp
Tue Jun  9 14:59:33 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv19712/src/main/org/biomoby/shared

Modified Files:
	NamespaceContextImpl.java 
Log Message:
Added simple c-tor, better support for null namespaces, and XPath function prefix
moby-live/Java/src/main/org/biomoby/shared NamespaceContextImpl.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java	2009/03/12 00:02:46	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/NamespaceContextImpl.java	2009/06/09 18:59:33	1.7
@@ -19,6 +19,18 @@
     private Map<String, String> nsURIs;
 
     /**
+     * Sets just one prefix, the one provided, which also gets mapped to the blank prefix
+     */
+    public NamespaceContextImpl(String ns, String nsPrefix){
+	prefixes = new HashMap<String, String>();
+	nsURIs = new HashMap<String, String>();
+
+	prefixes.put(ns, nsPrefix);
+	nsURIs.put(nsPrefix, ns);
+	nsURIs.put("", ns);
+    }
+
+    /**
      * 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.
@@ -33,8 +45,8 @@
 		String uri = el.getNamespaceURI();
 		String prefix = el.getPrefix();
 		if(uri != null && uri.length() != 0){
-		    if(prefix == null){
-			prefix = defaultNSPrefix;
+		    if(prefix == null || prefix.length() == 0){
+			nsURIs.put(defaultNSPrefix, uri);
 		    }
 		    if(!nsURIs.containsKey(prefix)){
 			nsURIs.put(prefix, uri);
@@ -49,15 +61,33 @@
 			continue;
 		    }
 
-		    if(!prefixes.containsKey(xmlnsDecl.getNamespaceURI())){
-			prefixes.put(xmlnsDecl.getNamespaceURI(), xmlnsDecl.getPrefix());
+		    if(xmlnsDecl.getPrefix().equals("xmlns")){
+			uri = xmlnsDecl.getValue();
+			prefix = xmlnsDecl.getLocalName();
+		    }
+		    else{
+			uri = xmlnsDecl.getNamespaceURI();
+			prefix = xmlnsDecl.getPrefix();
+		    }
+
+		    if(!prefixes.containsKey(uri)){
+			prefixes.put(uri, prefix);
 		    }
-		    if(!nsURIs.containsKey(xmlnsDecl.getPrefix())){
-			nsURIs.put(xmlnsDecl.getPrefix(), xmlnsDecl.getNamespaceURI());
+		    if(!nsURIs.containsKey(prefix)){
+			nsURIs.put(prefix, uri);
 		    }
 		}
 	    }
-	}		
+	}
+
+	// If no defaultNS is declared, bind it to the last one we encountered, i.e. (for RPC WS data)
+	if(!nsURIs.containsKey(defaultNSPrefix)){
+	    nsURIs.put(defaultNSPrefix, "");
+	}
+
+	// As a bonus, always include the "fn" prefix, which allows access to XPath functions
+	prefixes.put("http://www.w3.org/2005/xpath-functions", "fn");
+	nsURIs.put("fn", "http://www.w3.org/2005/xpath-functions");
     }
 
     /**
@@ -83,6 +113,7 @@
 	prefixes.put(MobyPrefixResolver.SAWSDL_NAMESPACE, MobyPrefixResolver.SAWSDL_PREFIX);
 	prefixes.put(MobyPrefixResolver.LSID_NAMESPACE, MobyPrefixResolver.LSID_PREFIX);
 	prefixes.put(MobyPrefixResolver.XSD_NAMESPACE, MobyPrefixResolver.XSD_PREFIX);
+	prefixes.put(MobyPrefixResolver.DUBLIN_CORE_NAMESPACE, MobyPrefixResolver.DUBLIN_CORE_PREFIX);
 
 	// Reverse map prefix -> nsURI
 	nsURIs.put(MobyPrefixResolver.XSI_PREFIX, MobyPrefixResolver.XSI_NAMESPACE2001);
@@ -93,6 +124,7 @@
 
     // JAX NamespaceContext requirements
     public String getNamespaceURI(String prefix){
+	//System.err.println("Asked for ns of '" + prefix + "', giving " + nsURIs.get(prefix));
 	return nsURIs.get(prefix);
     }
 




More information about the MOBY-guts mailing list