[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Wed Oct 11 01:54:51 UTC 2006


kawas
Tue Oct 10 21:54:51 EDT 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder
In directory dev.open-bio.org:/tmp/cvs-serv25229/Java/src/main/org/biomoby/client/rdf/builder

Modified Files:
	ServiceInstanceRDF.java RDFConfigure.java 
Log Message:

moby-live/Java/src/main/org/biomoby/client/rdf/builder ServiceInstanceRDF.java,1.30,1.31 RDFConfigure.java,1.21,1.22
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java	2006/08/30 16:55:02	1.30
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java	2006/10/11 01:54:51	1.31
@@ -9,19 +9,14 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 
+import org.apache.commons.discovery.tools.DiscoverSingleton;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.biomoby.client.CentralImpl;
 import org.biomoby.client.rdf.vocabulary.DC_PROTEGE;
 import org.biomoby.client.rdf.vocabulary.FetaVocabulary;
-
-import org.biomoby.registry.properties.MobyProperties;
+import org.biomoby.client.ui.graphical.servlet.utilities.ContextLoader;
 import org.biomoby.registry.properties.RegistryOS;
 import org.biomoby.shared.Central;
 import org.biomoby.shared.MobyData;
@@ -29,7 +24,6 @@
 import org.biomoby.shared.MobyNamespace;
 import org.biomoby.shared.MobyPrimaryDataSet;
 import org.biomoby.shared.MobyPrimaryDataSimple;
-import org.biomoby.shared.MobyResourceRef;
 import org.biomoby.shared.MobySecondaryData;
 import org.biomoby.shared.MobyService;
 import org.biomoby.shared.data.MobyDataSecondaryInstance;
@@ -79,92 +73,42 @@
 
 	private static final String DCP = DC_PROTEGE.getURI();
 
-	private static final String OBJ;// =
-
-	// "http://biomoby.org/RESOURCES/MOBY-S/Objects#";
-
-	private static final String SRV;// =
-
-	// "http://biomoby.org/RESOURCES/MOBY-S/Services#";
-
-	private static final String NS;// =
-
-	// "http://biomoby.org/RESOURCES/MOBY-S/Namespaces#";
-
-	private static final String MP;// =
-
-	// "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
-
-	private static final String SI;// =
-	// "http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#";
+	private static final String OBJ;
+	private static final String SRV;
+	private static final String NS;
+	private static final String MP;
+	private static final String SI;
+	
+	private static final String SERVER;
 
 	static {
-		boolean __success = false;
-		// attempt 1 - servlet context
-		Context c;
+		ContextLoader cLoader = null;		
 		try {
-			c = new InitialContext();
-			String MOBY_SERVER = (String) c.lookup("java:comp/env/MOBY_SERVER");
-			if (MOBY_SERVER != null && !MOBY_SERVER.equals("")) {
-				System.setProperty("MOBY_SERVER", MOBY_SERVER);
-				try {
-					Central central = new CentralImpl(MOBY_SERVER);
-					MobyResourceRef[] refs = central.getResourceRefs();
-					for (int i = 0; i < refs.length; i++) {
-						String url = refs[i].getResourceLocation().toExternalForm();
-						if (url.lastIndexOf("#") < 0)
-							url = url + "#";
-						URI_MAP.put(refs[i].getResourceName(), url);
-					}
-				} catch (Exception ex) {
+			cLoader = (ContextLoader) DiscoverSingleton.find(Class
+					.forName((String) ContextLoader.class.getCanonicalName()), Class.forName(
+					(String) ContextLoader.class.getCanonicalName()).getName());
+			log
+					.info((cLoader == null ? "ContextLoader is null and is therefore not loaded. This is BAD!"
+							: "ContextLoader has loaded successfully."));
+		} catch (Exception e) {
+			log.warn("ContextLoader is null and is therefore not loaded. This is BAD!"
+					+ System.getProperty("line.separator") + e.getMessage());
+		}
+		
+		log.info("Setting RDF ResourceLocations (RDFConfigure) for current registry...");
 
-				}
-				__success = true;
-			}
-			String MOBY_URI = (String) c.lookup("java:comp/env/MOBY_URI");
-			if (MOBY_URI != null && !MOBY_URI.equals("")) {
-				System.setProperty("MOBY_URI", MOBY_URI);
-				__success = true;
-			}
-		} catch (NamingException e) {
+		
+		OBJ = (String) cLoader.getURI_MAP().get("Object");
 
-			// e.printStackTrace();
-		}
+		SRV = (String) cLoader.getURI_MAP().get("Service");
 
-		// attempt 2 - environment variables
-		if (!__success) {
-			// maybe try for environment variables
-			Properties p = MobyProperties.PROPERTIES();
-			String MOBY_SERVER = (String) p.get("MOBY_SERVER");
-			if (MOBY_SERVER != null && !MOBY_SERVER.equals("")) {
-				System.setProperty("MOBY_SERVER", MOBY_SERVER);
-				try {
-					Central central = new CentralImpl(MOBY_SERVER);
-					MobyResourceRef[] refs = central.getResourceRefs();
-					for (int i = 0; i < refs.length; i++) {
-						String url = refs[i].getResourceLocation().toExternalForm();
-						if (url.lastIndexOf("#") < 0)
-							url = url + "#";
-						URI_MAP.put(refs[i].getResourceName(), url);
-					}
-				} catch (Exception ex) {
+		NS = (String) cLoader.getURI_MAP().get("Namespace");
 
-				}
-			}
-			String MOBY_URI = (String) p.get("MOBY_URI");
-			if (MOBY_URI != null && !MOBY_URI.equals("")) {
-				System.setProperty("MOBY_URI", MOBY_URI);
-			}
-		}
-		OBJ = (URI_MAP.get("Object") != null ? (String) URI_MAP.get("Object")
-				: "http://biomoby.org/RESOURCES/MOBY-S/Objects#");
-		SRV = (URI_MAP.get("Service") != null ? (String) URI_MAP.get("Service")
-				: "http://biomoby.org/RESOURCES/MOBY-S/Services#");
-		NS = (URI_MAP.get("Namespace") != null ? (String) URI_MAP.get("Namespace")
-				: "http://biomoby.org/RESOURCES/MOBY-S/Namespaces#");
 		MP = "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
-		SI = (URI_MAP.get("ServiceInstance") != null ? (String) URI_MAP.get("ServiceInstance")
-				: "http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#");
+
+		SI = (String) cLoader.getURI_MAP().get("ServiceInstance");
+		
+		SERVER = cLoader.getFULL_SERVER_URL();
 	}
 
 	/**
@@ -274,7 +218,7 @@
 			try {
 				central = new CentralImpl(url, uri);
 			} catch (MobyException e) {
-				System.err.println("Could not connect to " + url + " in findService.");
+				log.error("Could not connect to " + url + " in findService.");
 				return empty;
 			}
 			// set up the query service
@@ -284,7 +228,7 @@
 			try {
 				services = central.findService(service);
 			} catch (MobyException e1) {
-				System.err.println("Could not find service:\n" + e1.getMessage());
+				log.error("Could not find service:\n" + e1.getMessage());
 				return empty;
 			}
 			// only one service should be returned!
@@ -304,7 +248,7 @@
 			try {
 				central = new CentralImpl(url, uri);
 			} catch (MobyException e) {
-				System.err.println("Could not connect to " + url + " in findService.");
+				log.error("Could not connect to " + url + " in findService.");
 				return empty;
 			}
 			// set up the query service
@@ -314,7 +258,7 @@
 			try {
 				services = central.findService(service);
 			} catch (MobyException e1) {
-				System.err.println("Could not find service:\n" + e1.getMessage());
+				log.error("Could not find service:\n" + e1.getMessage());
 				return empty;
 			}
 			// get the rdf
@@ -358,7 +302,7 @@
 			try {
 				central = new CentralImpl(url, uri);
 			} catch (MobyException e) {
-				System.err.println("Could not connect to " + url + " in findService.");
+				log.error("Could not connect to " + url + " in findService.");
 				return empty;
 			}
 			// set up the query service
@@ -368,7 +312,7 @@
 			try {
 				services = central.findService(service);
 			} catch (MobyException e1) {
-				System.err.println("Could not find service:\n" + e1.getMessage());
+				log.error("Could not find service:\n" + e1.getMessage());
 				return empty;
 			}
 			// only one service should be returned!
@@ -388,7 +332,7 @@
 			try {
 				central = new CentralImpl(url, uri);
 			} catch (MobyException e) {
-				System.err.println("Could not connect to " + url + " in findService.");
+				log.error("Could not connect to " + url + " in findService.");
 				return empty;
 			}
 			// set up the query service
@@ -398,7 +342,7 @@
 			try {
 				services = central.findService(service);
 			} catch (MobyException e1) {
-				System.err.println("Could not find service:\n" + e1.getMessage());
+				log.error("Could not find service:\n" + e1.getMessage());
 				return empty;
 			}
 			// get the rdf
@@ -421,50 +365,13 @@
 		// initialize central
 		try {
 			if (!useTestMachine) {
-				String registryURL = null;
-				String registryNamespace = null;
-				Map map = RegistryOS.getEnv();
-				if (!map.isEmpty()) {
-					registryURL = (String) map.get("MOBY_SERVER");
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-					log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-					if (registryURL == null) {
-						// use default registry, since we dont have a local one
-						central = new CentralImpl();
-					} else if (registryNamespace == null) {
-						// use default namespace since one isnt defined
-						central = new CentralImpl(registryURL);
-					} else {
-						// use defined url and namespacce
-						central = new CentralImpl(registryURL, registryNamespace);
-					}
-				} else {
-					// perhaps the System propery was set earlier.
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-
-					// use the default central if we have no other choice
-					if (registryURL != null)
-						if (registryNamespace != null)
-							central = new CentralImpl(registryURL, registryNamespace);
-						else
-							central = new CentralImpl(registryURL);
-					else
-						central = new CentralImpl();
-				}
+				central = getCentralImpl();
 			} else {
 				// use test machine no longer supported
 				return empty;
 			}
 		} catch (MobyException e) {
-			System.err.println("error in getAllServices 1:\n" + e.getMessage());
+			log.error("error in getAllServices 1:\n" + e.getMessage());
 			return empty;
 		}
 		// set up the query service
@@ -474,7 +381,7 @@
 		try {
 			services = central.findService(service);
 		} catch (MobyException e1) {
-			System.err.println("error in getAllServices 2:\n" + e1.getMessage());
+			log.error("error in getAllServices 2:\n" + e1.getMessage());
 			return empty;
 		}
 		// should have >= 1 service returned
@@ -487,6 +394,42 @@
 		return str;
 	}
 
+	/**
+	 * @return
+	 * @throws MobyException
+	 */
+	private static Central getCentralImpl() throws MobyException {
+		Central central;
+		String registryURL = null;
+		String registryNamespace = null;
+		
+		// are they set in the system?
+		registryURL = System.getProperty("MOBY_SERVER");
+		registryNamespace = System.getProperty("MOBY_URI");
+
+		// if we didnt set them check the environment
+		if (registryURL == null) {
+			Map map = RegistryOS.getEnv();
+			if (!map.isEmpty()) {
+				registryURL = (String) map.get("MOBY_SERVER");
+				registryNamespace = (String) map.get("MOBY_URI");
+			}
+		}
+		
+		log.info("Using URL: " + (registryURL == null ? CentralImpl.DEFAULT_ENDPOINT : registryURL) + " URI: " + (registryNamespace == null ? CentralImpl.DEFAULT_NAMESPACE: registryNamespace));
+		if (registryURL == null) {
+			// use default registry, since we dont have a local one
+			central = new CentralImpl();
+		} else if (registryNamespace == null) {
+			// use default namespace since one isnt defined
+			central = new CentralImpl(registryURL);
+		} else {
+			// use defined url and namespacce
+			central = new CentralImpl(registryURL, registryNamespace);
+		}
+		return central;
+	}
+
 	
 	/*
 	 * a method that retrieves all of the service instances based on an
@@ -500,50 +443,13 @@
 		// initialize central
 		try {
 			if (!useTestMachine) {
-				String registryURL = null;
-				String registryNamespace = null;
-				Map map = RegistryOS.getEnv();
-				if (!map.isEmpty()) {
-					registryURL = (String) map.get("MOBY_SERVER");
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-					log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-					if (registryURL == null) {
-						// use default registry, since we dont have a local one
-						central = new CentralImpl();
-					} else if (registryNamespace == null) {
-						// use default namespace since one isnt defined
-						central = new CentralImpl(registryURL);
-					} else {
-						// use defined url and namespacce
-						central = new CentralImpl(registryURL, registryNamespace);
-					}
-				} else {
-					// perhaps the System propery was set earlier.
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-
-					// use the default central if we have no other choice
-					if (registryURL != null)
-						if (registryNamespace != null)
-							central = new CentralImpl(registryURL, registryNamespace);
-						else
-							central = new CentralImpl(registryURL);
-					else
-						central = new CentralImpl();
-				}
+				central = getCentralImpl();				
 			} else {
 				// use test machine no longer supported
 				return empty;
 			}
 		} catch (MobyException e) {
-			System.err.println("error in getAllServices 1:\n" + e.getMessage());
+			log.error("error in getAllServices 1:\n" + e.getMessage());
 			return empty;
 		}
 		// set up the query service
@@ -553,7 +459,7 @@
 		try {
 			services = central.findService(service);
 		} catch (MobyException e1) {
-			System.err.println("error in getAllServices 2:\n" + e1.getMessage());
+			log.error("error in getAllServices 2:\n" + e1.getMessage());
 			return empty;
 		}
 		// should have >= 1 service returned
@@ -578,50 +484,13 @@
 		// initialize central
 		try {
 			if (!useTestMachine) {
-				String registryURL = null;
-				String registryNamespace = null;
-				Map map = RegistryOS.getEnv();
-				if (!map.isEmpty()) {
-					registryURL = (String) map.get("MOBY_SERVER");
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-					log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-					if (registryURL == null) {
-						// use default registry, since we dont have a local one
-						central = new CentralImpl();
-					} else if (registryNamespace == null) {
-						// use default namespace since one isnt defined
-						central = new CentralImpl(registryURL);
-					} else {
-						// use defined url and namespacce
-						central = new CentralImpl(registryURL, registryNamespace);
-					}
-				} else {
-					// use default registry since we cant determine if local one
-					// exists
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-
-					if (registryURL != null)
-						if (registryNamespace != null)
-							central = new CentralImpl(registryURL, registryNamespace);
-						else
-							central = new CentralImpl(registryURL);
-					else
-						central = new CentralImpl();
-				}
+				central = getCentralImpl();
 			} else {
 				// use test machine no longer supported
 				return empty;
 			}
 		} catch (MobyException e) {
-			System.err.println("error in getService 1:\n" + e.getMessage());
+			log.error("error in getService 1:\n" + e.getMessage());
 			return empty;
 		}
 		// set up the query service
@@ -631,7 +500,7 @@
 		try {
 			services = central.findService(service);
 		} catch (MobyException e1) {
-			System.err.println("error in getService 2:\n" + e1.getMessage());
+			log.error("error in getService 2:\n" + e1.getMessage());
 			return empty;
 		}
 		// only one service should be returned!
@@ -657,50 +526,13 @@
 		// initialize central
 		try {
 			if (!useTestMachine) {
-				String registryURL = null;
-				String registryNamespace = null;
-				Map map = RegistryOS.getEnv();
-				if (!map.isEmpty()) {
-					registryURL = (String) map.get("MOBY_SERVER");
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-					log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-					if (registryURL == null) {
-						// use default registry, since we dont have a local one
-						central = new CentralImpl();
-					} else if (registryNamespace == null) {
-						// use default namespace since one isnt defined
-						central = new CentralImpl(registryURL);
-					} else {
-						// use defined url and namespacce
-						central = new CentralImpl(registryURL, registryNamespace);
-					}
-				} else {
-					// use default registry since we cant determine if local one
-					// exists
-					if (registryURL == null)
-						registryURL = System.getProperty("MOBY_SERVER");
-					registryNamespace = (String) map.get("MOBY_URI");
-					if (registryNamespace == null)
-						registryNamespace = System.getProperty("MOBY_URI");
-
-					if (registryURL != null)
-						if (registryNamespace != null)
-							central = new CentralImpl(registryURL, registryNamespace);
-						else
-							central = new CentralImpl(registryURL);
-					else
-						central = new CentralImpl();
-				}
+				central = getCentralImpl();
 			} else {
 				// use test machine no longer supported
 				return empty;
 			}
 		} catch (MobyException e) {
-			System.err.println("error in getService 1:\n" + e.getMessage());
+			log.error("error in getService 1:\n" + e.getMessage());
 			return empty;
 		}
 		// set up the query service
@@ -710,7 +542,7 @@
 		try {
 			services = central.findService(service);
 		} catch (MobyException e1) {
-			System.err.println("error in getService 2:\n" + e1.getMessage());
+			log.error("error in getService 2:\n" + e1.getMessage());
 			return empty;
 		}
 		// only one service should be returned!
@@ -794,9 +626,10 @@
 
 			{ // add meta information on whether or not this service is
 				// callable (i.e. times out or not)
+				if (useLSIDs)
 				try {
 					URL _url_ = new URL(
-							"http://mobycentral.icapture.ubc.ca:8090/servlets/ValidateService?authority="
+							SERVER + "ValidateService?authority="
 									+ services[i].getAuthority() + "&service="
 									+ services[i].getName());
 					BufferedReader in = new BufferedReader(
@@ -1016,7 +849,7 @@
 						// should not be here, but ...
 					} else {
 						// ERROR
-						System.err.println("Secondary input was not of known subtype (Secondary)");
+						log.error("Secondary input was not of known subtype (Secondary)");
 						return null;
 					}
 				}
@@ -1170,28 +1003,7 @@
 		MobyService[] services = null;
 		// initialize central
 		try {
-			String registryURL;
-			String registryNamespace;
-			Map map = RegistryOS.getEnv();
-			if (!map.isEmpty()) {
-				registryURL = (String) map.get("MOBY_SERVER");
-				registryNamespace = (String) map.get("MOBY_URI");
-				log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-				if (registryURL == null) {
-					// use default registry, since we dont have a local one
-					central = new CentralImpl();
-				} else if (registryNamespace == null) {
-					// use default namespace since one isnt defined
-					central = new CentralImpl(registryURL);
-				} else {
-					// use defined url and namespacce
-					central = new CentralImpl(registryURL, registryNamespace);
-				}
-			} else {
-				// use default registry since we cant determine if local one
-				// exists
-				central = new CentralImpl();
-			}
+			central = getCentralImpl();
 		} catch (MobyException e) {
 			return false;
 		}
@@ -1213,28 +1025,7 @@
 		MobyService[] services = null;
 		// initialize central
 		try {
-			String registryURL;
-			String registryNamespace;
-			Map map = RegistryOS.getEnv();
-			if (!map.isEmpty()) {
-				registryURL = (String) map.get("MOBY_SERVER");
-				registryNamespace = (String) map.get("MOBY_URI");
-				log.info("Using URL: " + registryURL + " URI: " + registryNamespace);
-				if (registryURL == null) {
-					// use default registry, since we dont have a local one
-					central = new CentralImpl();
-				} else if (registryNamespace == null) {
-					// use default namespace since one isnt defined
-					central = new CentralImpl(registryURL);
-				} else {
-					// use defined url and namespacce
-					central = new CentralImpl(registryURL, registryNamespace);
-				}
-			} else {
-				// use default registry since we cant determine if local one
-				// exists
-				central = new CentralImpl();
-			}
+			central = getCentralImpl();
 		} catch (MobyException e) {
 			return false;
 		}
@@ -1262,32 +1053,7 @@
 		MobyService[] services = null;
 		// initialize central
 		try {
-			String registryURL;
-			String registryNamespace;
-			Map map = RegistryOS.getEnv();
-			if (!map.isEmpty()) {
-				registryURL = (String) map.get("MOBY_SERVER");
-				registryNamespace = (String) map.get("MOBY_URI");
-				if (registryURL == null) {
-					// use default registry, since we dont have a local one
-					central = new CentralImpl();
-				} else if (registryNamespace == null) {
-					// use default namespace since one isnt defined
-					central = new CentralImpl(registryURL);
-				} else {
-					// use defined url and namespacce
-					central = new CentralImpl(registryURL, registryNamespace);
-				}
-				log.info("Using URL: "
-						+ (registryURL == null ? CentralImpl.DEFAULT_ENDPOINT : registryURL)
-						+ " URI: "
-						+ (registryNamespace == null ? CentralImpl.DEFAULT_NAMESPACE
-								: registryNamespace));
-			} else {
-				// use default registry since we cant determine if local one
-				// exists
-				central = new CentralImpl();
-			}
+			central = getCentralImpl();
 		} catch (MobyException e) {
 			return "";
 		}
@@ -1324,7 +1090,7 @@
 		// false));
 		// log.info(findService("bioinfo.icapture.ubc.ca","MOBYSHoundGetGenBankGFF",
 		// false));
-		log.info(findService("genome.imim.es", null, false));
+		log.info(findService("blah.blah.blah", "Echo_test", "http://bioinfo.icapture.ubc.ca/cgi-bin/mobycentral/MOBY-Central.pl", "http://bioinfo.icapture.ubc.ca/MOBY/Central", false));
 		// log.info(findService("", "", false));
 	}
 }

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/RDFConfigure.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/RDFConfigure.java	2006/08/28 13:50:13	1.21
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/RDFConfigure.java	2006/10/11 01:54:51	1.22
@@ -5,19 +5,15 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
-import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.biomoby.client.CentralImpl;
+import org.apache.commons.discovery.tools.DiscoverSingleton;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.biomoby.client.rdf.vocabulary.DC_PROTEGE;
 import org.biomoby.client.rdf.vocabulary.Predicates;
-import org.biomoby.registry.properties.MobyProperties;
-import org.biomoby.shared.Central;
-import org.biomoby.shared.MobyResourceRef;
+import org.biomoby.client.ui.graphical.servlet.jresources.RESOURCE;
+import org.biomoby.client.ui.graphical.servlet.utilities.ContextLoader;
 
 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
@@ -54,84 +50,53 @@
  */
 @SuppressWarnings("unchecked")
 public class RDFConfigure {
+	private static Log log = LogFactory.getLog(RESOURCE.class);
+	
+	
 	final private static String newline = System.getProperty("line.separator");
 
+	final public static String URI_OBJECT;
+
+	final public static String URI_SERVICE;
+
+	final public static String URI_NAMESPACE;
+
+	final public static String URI_PREDICATE;
+
+	final public static String URI_ServiceINSTANCE;
 	/*
 	 * Some constants for use in the rdfs
 	 */
-	private static Map URI_MAP = new HashMap();
+	
 	static {
-		boolean __success = false;
-		// attempt 1 - servlet context
+		ContextLoader cLoader = null;		
 		try {
-			Context c = new InitialContext();
-			String MOBY_SERVER = (String) c.lookup("java:comp/env/MOBY_SERVER");
-			if (MOBY_SERVER != null && !MOBY_SERVER.equals("")) {
-				Central central = new CentralImpl(MOBY_SERVER);
-				MobyResourceRef[] refs = central.getResourceRefs();
-				for (int i = 0; i < refs.length; i++) {
-					String url = refs[i].getResourceLocation().toExternalForm();
-					if (url.lastIndexOf("#") < 0)
-						url = url + "#";
-					URI_MAP.put(refs[i].getResourceName(), url);
-				}
-				__success = true;
-			}
-
+			cLoader = (ContextLoader) DiscoverSingleton.find(Class
+					.forName((String) ContextLoader.class.getCanonicalName()), Class.forName(
+					(String) ContextLoader.class.getCanonicalName()).getName());
+			log
+					.info((cLoader == null ? "ContextLoader is null and is therefore not loaded. This is BAD!"
+							: "ContextLoader has loaded successfully."));
 		} catch (Exception e) {
-			e.printStackTrace();
+			log.warn("ContextLoader is null and is therefore not loaded. This is BAD!"
+					+ System.getProperty("line.separator") + e.getMessage());
 		}
-		// attempt 2 - environment variables
-		if (!__success) {
-			// maybe try for environment variables
-			Properties p = MobyProperties.PROPERTIES();
-			String MOBY_SERVER = (String) p.get("MOBY_SERVER");
-			try {
-				if (MOBY_SERVER != null && !MOBY_SERVER.equals("")) {
-					Central central = new CentralImpl(MOBY_SERVER);
-					MobyResourceRef[] refs = central.getResourceRefs();
-					for (int i = 0; i < refs.length; i++) {
-						String url = refs[i].getResourceLocation().toExternalForm();
-						if (url.lastIndexOf("#") < 0)
-							url = url + "#";
-						URI_MAP.put(refs[i].getResourceName(), url);
-					}
-					__success = true;
-				}
-			} catch (Exception ex) {
-				// die here?
-				ex.printStackTrace();
-			}
-		}
-		// attempt 3 - default to mobycentral
-		if (!__success) {
-			// default to mobycentral
-			try {
-				Central central = new CentralImpl();
-				MobyResourceRef[] refs = central.getResourceRefs();
-				for (int i = 0; i < refs.length; i++) {
-					String url = refs[i].getResourceLocation().toExternalForm();
-					if (url.lastIndexOf("#") < 0)
-						url = url + "#";
-					URI_MAP.put(refs[i].getResourceName(), url);
-				}
-				__success = true;
-			} catch (Exception ex) {
-				// die here?
-				ex.printStackTrace();
-			}
-		}
-	}
+		
+		log.info("Setting RDF ResourceLocations (RDFConfigure) for current registry...");
 
-	final public static String URI_OBJECT = (String) URI_MAP.get("Object"); // "http://biomoby.org/RESOURCES/MOBY-S/Objects#";
+		
+		URI_OBJECT = (String) cLoader.getURI_MAP().get("Object"); 
 
-	final public static String URI_SERVICE = (String) URI_MAP.get("Service"); // "http://biomoby.org/RESOURCES/MOBY-S/Services#";
+		URI_SERVICE = (String) cLoader.getURI_MAP().get("Service"); 
 
-	final public static String URI_NAMESPACE = (String) URI_MAP.get("Namespace"); // "http://biomoby.org/RESOURCES/MOBY-S/Namespaces#";
+		URI_NAMESPACE = (String) cLoader.getURI_MAP().get("Namespace"); 
 
-	final public static String URI_PREDICATE = "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
+		URI_PREDICATE = "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
+
+		URI_ServiceINSTANCE = (String) cLoader.getURI_MAP().get("ServiceInstance");	
+	}
 
-	final public static String URI_ServiceINSTANCE = (String) URI_MAP.get("ServiceInstance"); // "http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#";
+	
 
 	private Model model = null;
 




More information about the MOBY-guts mailing list