[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Fri Jun 8 14:04:27 UTC 2007
gordonp
Fri Jun 8 10:04:27 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv28675/src/main/org/biomoby/shared
Modified Files:
MobyDataType.java MobyNamespace.java MobyService.java
MobyServiceType.java
Log Message:
Commit of Seahawk 1.0 updates and associated core updates
moby-live/Java/src/main/org/biomoby/shared MobyDataType.java,1.14,1.15 MobyNamespace.java,1.6,1.7 MobyService.java,1.18,1.19 MobyServiceType.java,1.7,1.8
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java 2006/07/07 04:12:40 1.14
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java 2007/06/08 14:04:27 1.15
@@ -7,8 +7,11 @@
package org.biomoby.shared;
-import java.util.Comparator;
-import java.util.Vector;
+import java.net.URL;
+import java.util.*;
+
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.*;
import org.biomoby.shared.extended.DataTypeParser;
/**
@@ -49,9 +52,11 @@
protected String id = null;
protected String comment = null;
protected String lsid = null;
+ protected Registry registry = null; // with which registry was the data type registered?
- private static MobyDataType[] uninitializedDatatypes = new MobyDataType[0];
- private static MobyDataType[] datatypes = uninitializedDatatypes;
+ 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;
/**************************************************************************
* Default constructor.
@@ -74,24 +79,111 @@
setName (name);
}
+ public void setRegistry(Registry r){
+ registry = r;
+ }
+
+ public Registry getRegistry(){
+ 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);
+ }
+ }
+ catch(Exception e){
+ System.err.println("Cannot parse MOBY Object Ontology: " + e);
+ e.printStackTrace();
+ return;
+ }
+ datatypesMapBySynonym.put(reg.getSynonym(), datatypes);
+ datatypesMapByURL.put(dataDefURL.toString(), datatypes);
+ }
+
public static MobyDataType getDataType(String className){
+ return getDataType(className, null);
+ }
+
+ /**
+ * Retrieves a datatype object from the registry's ontology.
+ */
+ public static MobyDataType getDataType(String className, Registry reg){
if(className == null){
return null;
}
-
+
+ if(reg == null){
+ reg = getDefaultRegistry();
+ }
+ if(reg == null){
+ return null;
+ }
+
+ MobyDataType[] datatypes = datatypesMapBySynonym.get(reg.getSynonym());
+
// This method has not been called yet in the JVM, populate the datatypes
- synchronized(datatypes){
- if(datatypes == uninitializedDatatypes){
+ synchronized(datatypesMapByURL){
+ if(datatypes == null){
+ String dataDefURL = null;
try{
- DataTypeParser p = new DataTypeParser("http://biomoby.org/RESOURCES/MOBY-S/Objects");
- //DataTypeParser p = new DataTypeParser(RdfParser.OBJECT_URI);
- datatypes = p.getMobyDataTypesFromRDF();
+ dataDefURL = convertRegistryToDataTypeResourceURL(reg);
+ datatypes = datatypesMapByURL.get(dataDefURL);
+
+ if(datatypes == null){
+ DataTypeParser p = new DataTypeParser(dataDefURL);
+ datatypes = p.getMobyDataTypesFromRDF();
+ for(MobyDataType dataType: datatypes){
+ dataType.setRegistry(reg);
+ }
+ }
}
catch(Exception e){
System.err.println("Cannot parse MOBY Object 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java 2006/09/22 22:55:38 1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java 2007/06/08 14:04:27 1.7
@@ -7,9 +7,13 @@
package org.biomoby.shared;
-import java.util.Comparator;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.extended.NamespaceParser;
+import java.util.*;
+import java.net.URL;
+
/**
* A container representing a namespace used in the Moby registry.
*<p>
@@ -30,9 +34,10 @@
protected String description = "";
protected String lsid = null;
protected String id = null;
+ protected Registry registry; //provenance of the namspace definition
- protected static MobyNamespace[] uninitializedNamespaces = new MobyNamespace[0];
- protected static MobyNamespace[] namespaces = uninitializedNamespaces;
+ private static Map<String,MobyNamespace[]> namespacesMapBySynonym = new HashMap<String,MobyNamespace[]>();
+ private static Map<String,MobyNamespace[]> namespacesMapByURL = new HashMap<String,MobyNamespace[]>();
/**************************************************************************
* Default constructor. Other characteristics are empty - which is usually
@@ -42,23 +47,91 @@
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;
+ }
+
+ public void setRegistry(Registry reg){
+ 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){
+ MobyNamespace[] namespaces;
+ try{
+ NamespaceParser p = new NamespaceParser(namespaceDefURL);
+ namespaces = p.getMobyNamespacesFromRDF();
+
+ for(MobyNamespace namespace: namespaces){
+ namespace.setRegistry(reg);
+ }
+ }
+ catch(Exception e){
+ System.err.println("Cannot parse MOBY Namespace Ontology: " + e);
+ e.printStackTrace();
+ return;
+ }
+ namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
+ namespacesMapByURL.put(namespaceDefURL.toString(), namespaces);
+ }
+
public static MobyNamespace getNamespace(String ns){
+ return getNamespace(ns, null);
+ }
+
+ public static MobyNamespace getNamespace(String ns, Registry reg){
if(ns == null){
return null;
}
+ if(reg == null){
+ reg = MobyDataType.getDefaultRegistry();
+ }
+ if(reg == null){
+ return null;
+ }
+
+ MobyNamespace[] namespaces = namespacesMapBySynonym.get(reg.getSynonym());
+
// This method has not been called yet in the JVM, populate the datatypes
- synchronized (namespaces){
- if(namespaces == uninitializedNamespaces){
+ synchronized(namespacesMapByURL){
+ if(namespaces == null){
+ String namespaceDefURL = null;
try{
- NamespaceParser p = new NamespaceParser("http://biomoby.org/RESOURCES/MOBY-S/Namespaces");
- namespaces = p.getMobyNamespacesFromRDF();
+ namespaces = namespacesMapByURL.get(namespaceDefURL);
+
+ if(namespaces == null){
+ namespaceDefURL = convertRegistryToNamespaceResourceURL(reg);
+ NamespaceParser p = new NamespaceParser(namespaceDefURL);
+ namespaces = p.getMobyNamespacesFromRDF();
+
+ for(MobyNamespace namespace: namespaces){
+ namespace.setRegistry(reg);
+ }
+ }
}
catch(Exception e){
System.err.println("Cannot parse MOBY Namespace Ontology: " + e);
e.printStackTrace();
return null;
}
+ namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
+ namespacesMapByURL.put(namespaceDefURL, namespaces);
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java 2007/05/31 13:42:51 1.18
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyService.java 2007/06/08 14:04:27 1.19
@@ -7,9 +7,9 @@
package org.biomoby.shared;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.Vector;
+import java.util.*;
+import java.net.URL;
+import java.util.regex.Pattern;
import org.biomoby.shared.extended.ServiceInstanceParser;
/**
@@ -76,6 +76,7 @@
// We need both, because you can't synchrinize on a null array
protected static MobyService[] uninitializedServices = new MobyService[0];
protected static MobyService[] services = uninitializedServices;
+ protected static Map<String,MobyService> serviceMap = new HashMap<String,MobyService>();
// the elements of these Vectors are of type MobyData
protected Vector<MobyData> primaryInputs = new Vector<MobyData>();
@@ -507,36 +508,68 @@
this.serviceType = (serviceType == null ? new MobyServiceType() : serviceType);
}
+ public static MobyService getService(String lsid){
+ String[] lsidParts = lsid.split(":");
+ String[] sNameParts = lsidParts[4].split(",");
+ return getService(sNameParts[1], sNameParts[0]);
+ }
+
public static MobyService getService(String name, String authority){
if(name == null || authority == null){
return null;
}
- // This method has not been called yet in the JVM, populate the datatypes
- synchronized (services){
- if(services == uninitializedServices){
- try{
- ServiceInstanceParser p = new ServiceInstanceParser("http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances");
- services = p.getMobyServicesFromRDF();
+ // Perform a linear search for the corresponding namespace and authority
+ String lsid = "urn:lsid:biomoby.org:serviceinstance:"+authority+","+name;
+ if(!serviceMap.containsKey(lsid)){
+ try{
+ URL lsidResolver = new URL("http://mobycentral.icapture.ubc.ca/authority/lsid/ResolveLSID?lsid="+lsid);
+ Object o = getContent(lsidResolver);
+ if(!(o instanceof String)){
+ System.err.println("Response for "+lsid + " was not a String, but a " + o.getClass());
+ }
+ String metadata = (String) o;
+
+ String redirectPattern = "latest>";
+ int redirectStringIndex = metadata.indexOf(redirectPattern+lsid);
+ String lsidFull = null;
+ if(redirectStringIndex != -1){
+ int lsidFullIndex = redirectStringIndex+redirectPattern.length();
+ lsidFull = metadata.substring(lsidFullIndex, lsidFullIndex+lsid.length()+21);
+ //System.err.println("Retrieving full LSID " + lsidFull);
+ lsidResolver = new URL("http://mobycentral.icapture.ubc.ca/authority/lsid/ResolveLSID?lsid="+lsidFull);
+ metadata = getContent(lsidResolver);
}
- catch(Exception e){
- System.err.println("Cannot parse MOBY Service Instance Database: " + e);
- e.printStackTrace();
- return null;
+ metadata = Pattern.compile(".*(<\\?xml\\s.*RDF>).*", Pattern.DOTALL).matcher(metadata).replaceFirst("$1")
+ .replaceAll(">",">")
+ .replaceAll("<","<")
+ .replaceAll(""", "\"")
+ .replaceAll("&", "&");
+ //System.err.println(metadata);
+
+ ServiceInstanceParser p = new ServiceInstanceParser();
+ services = p.getMobyServicesFromRDF(metadata);
+ if(services.length > 0){
+ serviceMap.put(lsid, services[0]);
+ if(lsidFull != null){
+ serviceMap.put(lsidFull, services[0]);
+ }
}
+ } catch(Exception e){
+ e.printStackTrace();
}
}
- // Perform a linear search for the corresponding namespace and authority
- for(int i = 0; i < services.length; i++){
- if(name.equals(services[i].getName()) &&
- authority.equals(services[i].getAuthority())){
- return services[i];
- }
- }
+ return serviceMap.get(lsid);
+ }
- // Wasn't found if we got to here
- return null;
+ private static String getContent(URL u) throws Exception{
+ StringBuffer contents = new StringBuffer();
+ java.io.LineNumberReader reader = new java.io.LineNumberReader(new java.io.InputStreamReader(u.openStream()));
+ for(String line = reader.readLine(); line != null; line = reader.readLine()){
+ contents.append(line+"\n");
+ }
+ return contents.toString();
}
public boolean isAsynchronous(){
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.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/MobyServiceType.java 2006/09/22 22:56:44 1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.java 2007/06/08 14:04:27 1.8
@@ -7,10 +7,13 @@
package org.biomoby.shared;
-import java.util.Comparator;
-import java.util.Vector;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.extended.ServiceTypeParser;
+import java.util.*;
+import java.net.URL;
+
/**
* A container representing a service type used in the Moby registry.
*<p>
@@ -33,9 +36,10 @@
protected String[] parentNames = new String[] { };
protected String id = null;
protected String lsid = null;
+ protected Registry registry; // provenance of the service type definition
- protected static MobyServiceType[] unintializedServicetypes = new MobyServiceType[0];
- protected static MobyServiceType[] servicetypes = unintializedServicetypes;
+ private static Map<String,MobyServiceType[]> servicetypesMapBySynonym = new HashMap<String,MobyServiceType[]>();
+ private static Map<String,MobyServiceType[]> servicetypesMapByURL = new HashMap<String,MobyServiceType[]>();
public int compareTo (Object obj) {
return name.compareToIgnoreCase ( ((MobyServiceType)obj).getName() );
@@ -59,23 +63,91 @@
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(){
+ return registry;
+ }
+
+ public void setRegistry(Registry reg){
+ reg = registry;
+ }
+
+ /**
+ * 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);
+ }
+ }
+ catch(Exception e){
+ System.err.println("Cannot parse MOBY Service Type Ontology: " + e);
+ e.printStackTrace();
+ return;
+ }
+ servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
+ servicetypesMapByURL.put(serviceDefURL.toString(), servicetypes);
+ }
+
public static MobyServiceType getServiceType(String className){
+ return getServiceType(className, null);
+ }
+
+ public static MobyServiceType getServiceType(String className, Registry reg){
if(className == null){
return null;
}
- synchronized(servicetypes){
- if(servicetypes == unintializedServicetypes){
+ if(reg == null){
+ reg = MobyDataType.getDefaultRegistry();
+ }
+ if(reg == null){
+ return null;
+ }
+
+ MobyServiceType[] servicetypes = servicetypesMapBySynonym.get(reg.getSynonym());
+
+ // This method has not been called yet in the JVM, populate the datatypes
+ synchronized(servicetypesMapByURL){
+ if(servicetypes == null){
+ String serviceDefURL = null;
try{
- // Using test server for now, as it deals with the RDF properly
- ServiceTypeParser p = new ServiceTypeParser("http://biomoby.org/RESOURCES/MOBY-S/Services");
- servicetypes = p.getMobyServiceTypesFromRDF();
+ 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);
+ }
+ }
}
catch(Exception e){
System.err.println("Cannot parse MOBY Service Type Ontology: " + e);
e.printStackTrace();
return null;
}
+ servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
+ servicetypesMapByURL.put(serviceDefURL, servicetypes);
}
}
More information about the MOBY-guts
mailing list