[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Jul 16 20:34:07 UTC 2008


gordonp
Wed Jul 16 16:34:07 EDT 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv16200/src/main/org/biomoby/shared

Modified Files:
	MobyNamespace.java 
Log Message:
Updated getNamespace() to use the new caching mechanism
moby-live/Java/src/main/org/biomoby/shared MobyNamespace.java,1.11,1.12
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java	2007/08/24 09:35:27	1.11
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java	2008/07/16 20:34:07	1.12
@@ -13,6 +13,7 @@
 import org.biomoby.shared.extended.NamespaceParser;
 
 import java.util.*;
+import java.util.logging.*;
 import java.net.URL;
 
 /**
@@ -37,8 +38,8 @@
     protected String id = null;
     protected Registry registry; //provenance of the namspace definition
 
-    private static Map<String,MobyNamespace[]> namespacesMapBySynonym = new HashMap<String,MobyNamespace[]>();
-    private static Map<URL,MobyNamespace[]> namespacesMapByURL = new HashMap<URL,MobyNamespace[]>();
+    private static Logger logger = Logger.getLogger("org.biomoby.shared.MobyNamespace");
+    private static Map<String,MobyNamespace[]> namespacesMapByURL = new HashMap<String,MobyNamespace[]>();
 
     /**************************************************************************
      * Default constructor. Other characteristics are empty - which is usually
@@ -48,18 +49,6 @@
 	this.name = name;
     }
 
-    protected static String convertRegistryToNamespaceResourceURL(Registry reg) throws MobyException{
-	CentralImpl central = new CentralImpl(reg.getEndpoint());
-	MobyResourceRef[] resources = central.getResourceRefs();
-	for(MobyResourceRef resource: resources){
-	    if(Central.NAMESPACES_RESOURCE_NAME.equals(resource.getResourceName())){
-		return resource.getResourceLocation().toString();
-	    }
-	}
-	System.err.println("Error! Could not find the namespace resource from the registry " + reg.getSynonym());
-	return null;
-    }
-
     public Registry getRegistry(){
 	return registry;
     }
@@ -68,29 +57,6 @@
 	reg = registry;
     }
  
-    /**
-     * Particularly useful for loading namespace definitions from cached file, or
-     * refreshing an in-memory cache.
-     */
-    public static void loadNamespaces(URL namespaceDefURL, Registry reg) throws Exception{
-	synchronized(namespacesMapBySynonym){
-	    if(reg == null){
-		reg = RegistryCache.getDefaultRegistry();
-	    }
-	    
-	    MobyNamespace[] namespaces;
-	    NamespaceParser p = new NamespaceParser(namespaceDefURL);	    
-	    namespaces = p.getMobyNamespacesFromRDF();
-	    
-	    for(MobyNamespace namespace: namespaces){
-		namespace.setRegistry(reg);
-	    }
-	    
-	    namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
-	    namespacesMapByURL.put(namespaceDefURL, namespaces);  
-	}
-    }
-
     public static MobyNamespace getNamespace(String ns){
 	return getNamespace(ns, null);
     }
@@ -100,31 +66,24 @@
 	    return null;
 	}
 	
-	if(reg == null){
-	    reg = RegistryCache.getDefaultRegistry();
-	}
-	if(reg == null){
-	    return null;
-	}
-
 	MobyNamespace[] namespaces = null;
-	// sync makes sure we don't fetch it if it's currently being loaded by loadNamespaces
-	synchronized(namespacesMapBySynonym){  
-	    namespaces = namespacesMapBySynonym.get(reg.getSynonym());
-	}
 
-	// This method has not been called yet in the JVM, populate the namespaces 
+	// This method has not been called yet in the JVM, populate the namespaces, 
+	// ensuring concurrent calls don't collide
 	synchronized(namespacesMapByURL){
+	    namespaces = namespacesMapByURL.get(reg == null ? "" : reg.getEndpoint());
 	    if(namespaces == null){
+		Central central = null;
+		try{
+		    central = CentralImpl.getDefaultCentral(reg);
+		} catch(MobyException e){
+		    logger.log(Level.WARNING,
+			       "Cannot find a default Moby Central implementation",
+			       e);
+		    return null;
+		}
 		try{
-		    URL namespaceDefURL = Registry.findResourceURL(reg, Central.NAMESPACES_RESOURCE_NAME);
-		    namespaces = namespacesMapByURL.get(namespaceDefURL);		    
-		    if(namespaces == null){
-			System.err.println("Fetching namespace ontology from "+namespaceDefURL);
-			loadNamespaces(namespaceDefURL, reg);
-			namespaces = namespacesMapByURL.get(namespaceDefURL);
-		    }
-		    
+		    namespaces = central.getFullNamespaces();
 		}
 		catch(Exception e){
 		    System.err.println("Cannot parse MOBY Namespace Ontology: " + e);




More information about the MOBY-guts mailing list