[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Fri Jun 8 20:30:22 UTC 2007


gordonp
Fri Jun  8 16:30:22 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv29870/src/main/org/biomoby/shared

Modified Files:
	MobyDataType.java MobyNamespace.java MobyServiceType.java 
Log Message:
Code revamp to deal with new disk cache
moby-live/Java/src/main/org/biomoby/shared MobyDataType.java,1.15,1.16 MobyNamespace.java,1.7,1.8 MobyServiceType.java,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2007/06/08 14:04:27	1.15
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2007/06/08 20:30:22	1.16
@@ -11,7 +11,8 @@
 import java.util.*;
 
 import org.biomoby.client.CentralImpl;
-import org.biomoby.registry.meta.*;
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.registry.meta.RegistryCache;
 import org.biomoby.shared.extended.DataTypeParser;
 
 /**
@@ -55,8 +56,7 @@
     protected Registry registry = null;  // with which registry was the data type registered?
 
     private static Map<String,MobyDataType[]> datatypesMapBySynonym = new HashMap<String,MobyDataType[]>();
-    private static Map<String,MobyDataType[]> datatypesMapByURL = new HashMap<String,MobyDataType[]>();
-    private static Registry defaultRegistry = null;
+    private static Map<URL,MobyDataType[]> datatypesMapByURL = new HashMap<URL,MobyDataType[]>();
 
     /**************************************************************************
      * Default constructor.
@@ -87,57 +87,24 @@
 	return registry;
     }
 
-    protected static String convertRegistryToDataTypeResourceURL(Registry reg) throws MobyException{
-	CentralImpl central = new CentralImpl(reg.getEndpoint());
-	MobyResourceRef[] resources = central.getResourceRefs();
-	for(MobyResourceRef resource: resources){
-	    if(Central.DATA_TYPES_RESOURCE_NAME.equals(resource.getResourceName())){
-		return resource.getResourceLocation().toString();
-	    }
-	}
-	System.err.println("Error! Could not find the data type resource from the registry " + reg.getSynonym());
-	return null;
-    }
-
-    public synchronized static Registry getDefaultRegistry(){
-	if(defaultRegistry == null){
-	    try{
-		defaultRegistry = (new RegistriesList()).get(Registries.DEFAULT_REGISTRY_SYNONYM);
-	    } catch(Exception e){
-		e.printStackTrace();
-	    }
-	    if(defaultRegistry == null){
-		System.err.println("Error!  Could not find a default registry!  No data types will be available.");
-		System.err.println("Sought " + Registries.DEFAULT_REGISTRY_SYNONYM + " but available options are:");
-		for(String synonym: (new RegistriesList()).list()){
-		    System.err.println(synonym);
-		}
-	    }
-	}
-	return defaultRegistry;
-    }
-
     /**
      * Particularly useful for loading data types from cached file, or
      * refreshing an in-memory cache.
      */
-    public static void loadDataTypes(URL dataDefURL, Registry reg){
-	MobyDataType[] datatypes;
-	try{
-	    DataTypeParser p = new DataTypeParser(dataDefURL);
-	    
-	    datatypes = p.getMobyDataTypesFromRDF();
-	    for(MobyDataType dataType: datatypes){
-		dataType.setRegistry(reg);
-	    }
+    public static void loadDataTypes(URL dataDefURL, Registry reg) throws Exception{
+	if(reg == null){
+	    reg = RegistryCache.getDefaultRegistry();
 	}
-	catch(Exception e){
-	    System.err.println("Cannot parse MOBY Object Ontology: " + e);
-	    e.printStackTrace();
-	    return;
+
+	MobyDataType[] datatypes;
+	DataTypeParser p = new DataTypeParser(dataDefURL);
+	
+	datatypes = p.getMobyDataTypesFromRDF();
+	for(MobyDataType dataType: datatypes){
+	    dataType.setRegistry(reg);
 	}
 	datatypesMapBySynonym.put(reg.getSynonym(), datatypes);
-	datatypesMapByURL.put(dataDefURL.toString(), datatypes);  
+	datatypesMapByURL.put(dataDefURL, datatypes);  
     }
 
     public static MobyDataType getDataType(String className){
@@ -153,7 +120,7 @@
 	}
 
 	if(reg == null){
-	    reg = getDefaultRegistry();
+	    reg = RegistryCache.getDefaultRegistry();
 	}
 	if(reg == null){
 	    return null;
@@ -164,26 +131,20 @@
 	// This method has not been called yet in the JVM, populate the datatypes 
 	synchronized(datatypesMapByURL){
 	    if(datatypes == null){
-		String dataDefURL = null;
 		try{
-		    dataDefURL = convertRegistryToDataTypeResourceURL(reg);
-		    datatypes = datatypesMapByURL.get(dataDefURL);
-
+		    URL dataDefURL = Registry.findResourceURL(reg, Central.DATA_TYPES_RESOURCE_NAME);
+		    datatypes = datatypesMapByURL.get(dataDefURL);		    
 		    if(datatypes == null){
-			DataTypeParser p = new DataTypeParser(dataDefURL);
-			datatypes = p.getMobyDataTypesFromRDF();
-			for(MobyDataType dataType: datatypes){
-			    dataType.setRegistry(reg);
-			}
+			loadDataTypes(dataDefURL, reg);
+			datatypes = datatypesMapByURL.get(dataDefURL);
 		    }
+		    
 		}
 		catch(Exception e){
-		    System.err.println("Cannot parse MOBY Object Ontology: " + e);
+		    System.err.println("Cannot parse MOBY Service Type Ontology: " + e);
 		    e.printStackTrace();
 		    return null;
 		}
-		datatypesMapBySynonym.put(reg.getSynonym(), datatypes);
-		datatypesMapByURL.put(dataDefURL, datatypes);
 	    }
 	}
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java	2007/06/08 14:04:27	1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java	2007/06/08 20:30:22	1.8
@@ -9,6 +9,7 @@
 
 import org.biomoby.client.CentralImpl;
 import org.biomoby.registry.meta.Registry;
+import org.biomoby.registry.meta.RegistryCache;
 import org.biomoby.shared.extended.NamespaceParser;
 
 import java.util.*;
@@ -100,7 +101,7 @@
 	}
 	
 	if(reg == null){
-	    reg = MobyDataType.getDefaultRegistry();
+	    reg = RegistryCache.getDefaultRegistry();
 	}
 	if(reg == null){
 	    return null;

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.java	2007/06/08 14:04:27	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.java	2007/06/08 20:30:22	1.9
@@ -9,6 +9,7 @@
 
 import org.biomoby.client.CentralImpl;
 import org.biomoby.registry.meta.Registry;
+import org.biomoby.registry.meta.RegistryCache;
 import org.biomoby.shared.extended.ServiceTypeParser;
 
 import java.util.*;
@@ -39,7 +40,7 @@
     protected Registry registry; // provenance of the service type definition
 
     private static Map<String,MobyServiceType[]> servicetypesMapBySynonym = new HashMap<String,MobyServiceType[]>();
-    private static Map<String,MobyServiceType[]> servicetypesMapByURL = new HashMap<String,MobyServiceType[]>();
+    private static Map<URL,MobyServiceType[]> servicetypesMapByURL = new HashMap<URL,MobyServiceType[]>();
 
     public int compareTo (Object obj) {
 	return name.compareToIgnoreCase ( ((MobyServiceType)obj).getName() );
@@ -63,19 +64,7 @@
 	setName (typeName);
     }
 
-    protected static String convertRegistryToServiceTypeResourceURL(Registry reg) throws MobyException{
-	CentralImpl central = new CentralImpl(reg.getEndpoint());
-	MobyResourceRef[] resources = central.getResourceRefs();
-	for(MobyResourceRef resource: resources){
-	    if(Central.SERVICE_TYPES_RESOURCE_NAME.equals(resource.getResourceName())){
-		return resource.getResourceLocation().toString();
-	    }
-	}
-	System.err.println("Error! Could not find the service type resource from the registry " + reg.getSynonym());
-	return null;
-    }
-
-       public Registry getRegistry(){
+    public Registry getRegistry(){
 	return registry;
     }
 
@@ -87,23 +76,20 @@
      * Particularly useful for loading namespace definitions from cached file, or
      * refreshing an in-memory cache.
      */
-    public static void loadServiceTypes(URL serviceDefURL, Registry reg){
-	MobyServiceType[] servicetypes;
-	try{
-	    ServiceTypeParser p = new ServiceTypeParser(serviceDefURL);	    
-	    servicetypes = p.getMobyServiceTypesFromRDF();
-
-	    for(MobyServiceType servicetype: servicetypes){
-		servicetype.setRegistry(reg);
-	    }
+    public static void loadServiceTypes(URL serviceDefURL, Registry reg) throws Exception{
+	if(reg == null){
+	    reg = RegistryCache.getDefaultRegistry();
 	}
-	catch(Exception e){
-	    System.err.println("Cannot parse MOBY Service Type Ontology: " + e);
-	    e.printStackTrace();
-	    return;
+
+	MobyServiceType[] servicetypes;
+	ServiceTypeParser p = new ServiceTypeParser(serviceDefURL);	    
+	servicetypes = p.getMobyServiceTypesFromRDF();
+	
+	for(MobyServiceType servicetype: servicetypes){
+	    servicetype.setRegistry(reg);
 	}
 	servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
-	servicetypesMapByURL.put(serviceDefURL.toString(), servicetypes);  
+	servicetypesMapByURL.put(serviceDefURL, servicetypes);  
     }
     
     public static MobyServiceType getServiceType(String className){
@@ -116,7 +102,7 @@
 	}
 
 	if(reg == null){
-	    reg = MobyDataType.getDefaultRegistry();
+	    reg = RegistryCache.getDefaultRegistry();
 	}
 	if(reg == null){
 	    return null;
@@ -127,18 +113,12 @@
 	// This method has not been called yet in the JVM, populate the datatypes 
 	synchronized(servicetypesMapByURL){
 	    if(servicetypes == null){
-		String serviceDefURL = null; 
 		try{
-		    servicetypes = servicetypesMapByURL.get(serviceDefURL);
-		    
+		    URL serviceDefURL = Registry.findResourceURL(reg, Central.SERVICE_TYPES_RESOURCE_NAME);
+		    servicetypes = servicetypesMapByURL.get(serviceDefURL);		    
 		    if(servicetypes == null){
-			serviceDefURL = convertRegistryToServiceTypeResourceURL(reg);
-			ServiceTypeParser p = new ServiceTypeParser(serviceDefURL);
-			servicetypes = p.getMobyServiceTypesFromRDF();
-
-			for(MobyServiceType servicetype: servicetypes){
-			    servicetype.setRegistry(reg);
-			}
+			loadServiceTypes(serviceDefURL, reg);
+			servicetypes = servicetypesMapByURL.get(serviceDefURL);
 		    }
 		}
 		catch(Exception e){
@@ -146,8 +126,6 @@
 		    e.printStackTrace();
 		    return null;
 		}
-		servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
-		servicetypesMapByURL.put(serviceDefURL, servicetypes);
 	    }
 	}
 




More information about the MOBY-guts mailing list