[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Mon Feb 25 16:25:53 UTC 2008


kawas
Mon Feb 25 11:25:53 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory dev.open-bio.org:/tmp/cvs-serv13430/Java/src/main/org/biomoby/client

Modified Files:
	CentralDigestCachedImpl.java 
Log Message:
updates:
removed unused methods
made the isXLoaded() and setXLoaded private
no longer query the registry for resource refs on new, but rather do it when needed
no longer query the registry to create the list file when reading datatypes/servicetypes/namespaces unless asked too
renamed getURLasString to getResourceAsString and used CentralImpl.getResource(x) to get an input stream to the resource

moby-live/Java/src/main/org/biomoby/client CentralDigestCachedImpl.java,1.24,1.25
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2008/02/23 13:58:32	1.24
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2008/02/25 16:25:53	1.25
@@ -77,13 +77,8 @@
 	org.apache.commons.logging.LogFactory.getLog(CentralDigestCachedImpl.class);
 
     // for optimalization
-    private String datatypesResourceRef = null;
-    private String servicesResourceRef = null;
-    private String namespacesResourceRef = null;
-    private String serviceTypesResourceRef = null;
     private Registry reg = null;
     private boolean datatypesLoaded = false;
-    private boolean servicesLoaded = false;
     private boolean namespacesLoaded = false;
     private boolean serviceTypesLoaded = false;
 
@@ -105,21 +100,6 @@
     public CentralDigestCachedImpl (String endpoint, String namespace, String cacheDir)
 	throws MobyException {
 	super (endpoint, namespace, cacheDir);
-
-	MobyResourceRef[] refs = getResourceRefs();
-	for (MobyResourceRef ref : refs) {
-	    if (ref.getResourceName().equals(DATA_TYPES_RESOURCE_NAME)) {
-		datatypesResourceRef = ref.getResourceLocation().toString();
-	    } else if (ref.getResourceName().equals(
-		    SERVICE_INSTANCES_RESOURCE_NAME)) {
-		servicesResourceRef = ref.getResourceLocation().toString();
-	    } else if (ref.getResourceName().equals(NAMESPACES_RESOURCE_NAME)) {
-		namespacesResourceRef = ref.getResourceLocation().toString();
-	    } else if (ref.getResourceName()
-		    .equals(SERVICE_TYPES_RESOURCE_NAME)) {
-		serviceTypesResourceRef = ref.getResourceLocation().toString();
-	    }
-	}
 	reg = new Registry(getRegistryEndpoint(), getRegistryEndpoint(),
 		getRegistryNamespace());
 
@@ -193,7 +173,7 @@
 	    }
 	    if (isStale) {
 		// store the RDF_FILE
-		String rdf = getUrlAsString(datatypesResourceRef);
+		String rdf = getResourceAsString(DATA_TYPES_RESOURCE_NAME);
 		store(dataTypesCache, RDF_FILE, rdf.toString());
 	    }
 	    fireEvent(DATA_TYPE_LOADED, DATA_TYPES_RESOURCE_NAME
@@ -228,21 +208,12 @@
      * @throws MalformedURLException
      * @throws IOException
      */
-    private String getUrlAsString(String url) throws MalformedURLException,
+    private String getResourceAsString(String ref) throws MobyException,
 	    IOException {
 	StringBuilder rdf = new StringBuilder();
 	String line = null;
-	URL rdf_url = new URL(url);
-	HttpURLConnection urlConnection = null;
-	urlConnection = (HttpURLConnection) rdf_url.openConnection();
-	urlConnection.setDefaultUseCaches(false);
-	urlConnection.setUseCaches(false);
-	urlConnection.setRequestProperty("User-agent",
-		"jMoby_CentralDigest/1.19");
-	urlConnection.setConnectTimeout(1000 * 60 * 5);
 
-	BufferedReader br = new BufferedReader(new InputStreamReader(
-		urlConnection.getInputStream()));
+	BufferedReader br = new BufferedReader(new InputStreamReader(getResource(ref)));
 	String newline = System.getProperty("line.separator");
 	while ((line = br.readLine()) != null) {
 	    rdf.append(line + newline);
@@ -280,7 +251,7 @@
 		    // TODO add the fireevent calls ...
 		    // download the file, save it, then parse it
 		    store(servicesCache, RDF_FILE,
-			    getUrlAsString(servicesResourceRef));
+			    getResourceAsString(SERVICE_INSTANCES_RESOURCE_NAME));
 		    // extract the services
 		    ServiceInstanceParser sip = new ServiceInstanceParser(
 			    "file:///" + servicesCache.getAbsolutePath()
@@ -457,43 +428,6 @@
 
     }
 
-    protected Map createServicesByAuthorityFromXML(String result)
-	    throws MobyException {
-
-	// parse returned XML
-	Map<String, Map<String, String>> results = new TreeMap<String, Map<String, String>>(
-		getStringComparator());
-	Document document = loadDocument(new ByteArrayInputStream(result
-		.getBytes()));
-	NodeList list = document.getElementsByTagName("serviceName");
-	for (int i = 0; i < list.getLength(); i++) {
-	    Element elem = (Element) list.item(i);
-	    String name = elem.getAttribute("name");
-	    String auth = elem.getAttribute("authURI");
-	    String lsid = elem.getAttribute("lsid");
-	    Map map = (results.containsKey(auth) ? results.get(auth)
-		    : new HashMap<String, String>());
-	    map.put(name, lsid);
-	    results.put(auth, map);
-	}
-
-	return results;
-    }
-
-    protected String[] extractServiceProviders(String xml) {
-	Document document;
-	try {
-	    document = loadDocument(new ByteArrayInputStream(xml.getBytes()));
-	} catch (MobyException e) {
-	    return new String[] {};
-	}
-	NodeList list = document.getElementsByTagName("serviceName");
-	String[] results = new String[list.getLength()];
-	for (int i = 0; i < list.getLength(); i++)
-	    results[i] = ((Element) list.item(i)).getAttribute("authURI");
-	return results;
-    }
-
     /***************************************************************************
      * Update service types from a moby registry: - get a new LIST_FILE (but do
      * not put it into the cache yet) if failed do nothing (except reporting it) -
@@ -564,7 +498,7 @@
 	    // if we are stale, fetch new RDF
 	    if (isStale) {
 		// store the RDF_FILE
-		String rdf = getUrlAsString(serviceTypesResourceRef);
+		String rdf = getResourceAsString(SERVICE_TYPES_RESOURCE_NAME);
 		store(serviceTypesCache, RDF_FILE, rdf.toString());
 	    }
 	    fireEvent(SERVICE_TYPE_LOADED, SERVICE_TYPES_RESOURCE_NAME
@@ -660,7 +594,7 @@
 	    // if we are stale, fetch new RDF
 	    if (isStale) {
 		// store the RDF_FILE
-		String rdf = getUrlAsString(namespacesResourceRef);
+		String rdf = getResourceAsString(NAMESPACES_RESOURCE_NAME);
 		store(namespacesCache, RDF_FILE, rdf.toString());
 	    }
 	    fireEvent(NAMESPACE_LOADED, NAMESPACES_RESOURCE_NAME
@@ -705,12 +639,21 @@
 	    // iterate over datatypes in the LIST_FILE
 	    Map<String, MobyDataType> cachedTypes = new HashMap<String, MobyDataType>();
 	    // XML from Cache
-	    if (getListFile(dataTypesCache) == null || !isDatatypesLoaded()) {
+	    if (getListFile(dataTypesCache) == null || !rdfExists(dataTypesCache)) {
 		if (!fillDataTypesCache())
 		    // callback stopped filling
 		    return new MobyDataType[] {};
 	    }
-
+	    try {
+        	    if (!isDatatypesLoaded()) {
+        		MobyDataType.loadDataTypes(new URL("file:///"
+        			    + dataTypesCache.getAbsolutePath() + File.separator
+        			    + RDF_FILE), reg);
+        		setDatatypesLoaded(true);
+        	    }
+	    } catch (Exception e) {
+		    throw new MobyException(formatException(e), e);
+	    } 
 	    String xmlList = getListFile(dataTypesCache);
 	    // get the datatype names from the XML
 	    if (xmlList != null)
@@ -794,13 +737,25 @@
 
 	    // get a list file (with all namespaces)
 	    String xmlList = getListFile(namespacesCache);
-	    if (xmlList == null || !isNamespacesLoaded()) {
+	    if (xmlList == null || !rdfExists(namespacesCache)) {
 		initCache();
 		fillNamespacesCache();
 		xmlList = getListFile(namespacesCache);
 		if (xmlList == null)
 		    return new MobyNamespace[] {};
 	    }
+	    
+	    try {
+        	    if (!isNamespacesLoaded()) {
+        		MobyNamespace.loadNamespaces(new URL("file:///"
+        			    + namespacesCache.getAbsolutePath() + File.separator
+        			    + RDF_FILE), reg);
+        		setNamespacesLoaded(true);
+        	    }
+	    } catch (Exception e) {
+		    throw new MobyException(formatException(e), e);
+	    }
+	    
 	    String[] names = extractNamespacesFromXML(xmlList);
 	    ArrayList<MobyNamespace> types = new ArrayList<MobyNamespace>();
 	    for (String name : names) {
@@ -830,7 +785,7 @@
 
 	    // get a list file (with all service type names)
 	    String xmlList = getListFile(serviceTypesCache);
-	    if (xmlList == null || !isServiceTypesLoaded()) {
+	    if (xmlList == null || !rdfExists(serviceTypesCache)) {
 		if (!fillServiceTypesCache())
 		    // a callback stopped filling
 		    return new MobyServiceType[] {};
@@ -840,6 +795,16 @@
 			return new MobyServiceType[] {};
 		}
 	    }
+	    try {
+    	    if (!isServiceTypesLoaded()) {
+    		MobyServiceType.loadServiceTypes(new URL("file:///"
+    			    + serviceTypesCache.getAbsolutePath() + File.separator
+    			    + RDF_FILE), reg);
+    		setServiceTypesLoaded(true);
+    	    }
+	    } catch (Exception e) {
+		    throw new MobyException(formatException(e), e);
+	    }
 
 	    ArrayList<MobyServiceType> list = new ArrayList<MobyServiceType>();
 	    MobyServiceType[] types = createServiceTypesFromXML(xmlList);
@@ -888,35 +853,27 @@
 	return path.endsWith("~") || path.endsWith(RDF_FILE);
     }
 
-    public boolean isDatatypesLoaded() {
+    private boolean isDatatypesLoaded() {
 	return datatypesLoaded;
     }
 
-    public void setDatatypesLoaded(boolean datatypesLoaded) {
+    private void setDatatypesLoaded(boolean datatypesLoaded) {
 	this.datatypesLoaded = datatypesLoaded;
     }
 
-    public boolean isServicesLoaded() {
-	return servicesLoaded;
-    }
-
-    public void setServicesLoaded(boolean servicesLoaded) {
-	this.servicesLoaded = servicesLoaded;
-    }
-
-    public boolean isNamespacesLoaded() {
+    private boolean isNamespacesLoaded() {
 	return namespacesLoaded;
     }
 
-    public void setNamespacesLoaded(boolean namespacesLoaded) {
+    private void setNamespacesLoaded(boolean namespacesLoaded) {
 	this.namespacesLoaded = namespacesLoaded;
     }
 
-    public boolean isServiceTypesLoaded() {
+    private boolean isServiceTypesLoaded() {
 	return serviceTypesLoaded;
     }
 
-    public void setServiceTypesLoaded(boolean serviceTypesLoaded) {
+    private void setServiceTypesLoaded(boolean serviceTypesLoaded) {
 	this.serviceTypesLoaded = serviceTypesLoaded;
     }
 




More information about the MOBY-guts mailing list