[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/ui/graphical/servlet/jresources
In directory dev.open-bio.org:/tmp/cvs-serv25229/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources

Modified Files:
	RESOURCE.java 
Log Message:

moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources RESOURCE.java,1.22,1.23
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java	2006/09/15 21:50:21	1.22
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java	2006/10/11 01:54:51	1.23
@@ -14,8 +14,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -24,18 +22,15 @@
 import org.apache.commons.discovery.tools.DiscoverSingleton;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.biomoby.client.CentralDigestImpl;
 import org.biomoby.client.CentralImpl;
 import org.biomoby.client.rdf.builder.ServiceInstanceRDF;
 import org.biomoby.client.rdf.vocabulary.DC_PROTEGE;
 import org.biomoby.client.rdf.vocabulary.Predicates;
+import org.biomoby.client.ui.graphical.servlet.utilities.ContextLoader;
 import org.biomoby.registry.definitions.types.JNamespacesSqlImpl;
 import org.biomoby.registry.definitions.types.JObjectsSqlImpl;
 import org.biomoby.registry.definitions.types.JServicesSqlImpl;
-import org.biomoby.shared.Central;
-import org.biomoby.shared.CentralDigest;
 import org.biomoby.shared.MobyException;
-import org.biomoby.shared.MobyResourceRef;
 import org.biomoby.shared.MobyService;
 import org.w3c.rdf.model.ModelException;
 
@@ -94,189 +89,44 @@
 	 * the following used to be final, but on error, i would like to ensure that
 	 * i dont waste time trying to perform caching operations
 	 */
-	private static boolean isCachableServiceInstances;
+	private static boolean isCachableServiceInstances = false;
 
-	private static boolean isCachableNamespaces;
+	private static boolean isCachableNamespaces = false;
 
-	private static boolean isCachableServiceTypes;
+	private static boolean isCachableServiceTypes = false;
 
-	private static boolean isCachableObjects;
-
-	/* the individual caching classes */
-	private static RDFCache ServiceInstanceCache = null;
-
-	private static RDFCache ServiceTypesCache = null;
-
-	private static RDFCache ObjectsCache = null;
-
-	private static RDFCache NamespaceCache = null;
+	private static boolean isCachableObjects = false;
 
 	private static boolean RUN_MAIN = false;
 
-	
+	private static ContextLoader cLoader = null;
+
 	static {
-		boolean __success = false;
-		log.info("init(setting environment variables)");
 		try {
-			Object className;
-			Context c = new InitialContext();
-			try {
-				log.info("Checking for caching classes ...");
-				className = c.lookup("java:comp/env/ServiceInstancesCachingClass");
-				if (className != null && className instanceof String) {
-					try {
-						ServiceInstanceCache = (RDFCache) DiscoverSingleton.find(Class.forName((String) className), Class.forName((String) className).getName());
-						log.info((ServiceInstanceCache == null ? "Caching of service instances not enabled."
-										: "Caching of service instances enabled."));
-					} catch (Exception e) {
-						ServiceInstanceCache = null;
-						log.info("Caching of service instances not enabled\n" + e);
-					}
-				}
-			} catch (Exception e) {
-				log
-						.info("Caching of service instances not enabled. Caching file was not specified.\n"
-								+ e);
-			}
-			try {
-				className = c.lookup("java:comp/env/ServiceTypesCachingClass");
-				if (className != null && className instanceof String) {
-					try {
-						ServiceTypesCache = (RDFCache) DiscoverSingleton.find(Class.forName((String) className), Class.forName((String) className).getName());
-						log
-								.info((ServiceTypesCache == null ? "Caching of service types not enabled."
-										: "Caching of service types enabled."));
-					} catch (Exception e) {
-						ServiceTypesCache = null;
-						log.info("Caching of service types not enabled\n" + e);
-					}
-				}
-			} catch (Exception e) {
-				log.info("Caching of service types not enabled. Caching file was not specified.\n"
-						+ e);
-			}
-			try {
-				className = c.lookup("java:comp/env/ObjectsCachingClass");
-				if (className != null && className instanceof String) {
-					try {
-						ObjectsCache = (RDFCache) DiscoverSingleton.find(Class.forName((String) className), Class.forName((String) className).getName());
-						log.info((ObjectsCache == null ? "Caching of datatypes not enabled."
-								: "Caching of datatypes enabled."));
-					} catch (Exception e) {
-						ObjectsCache = null;
-						log.info("Caching of datatypes not enabled\n" + e);
-					}
-				}
-			} catch (Exception e) {
-				log.info("Caching of datatypes not enabled. Caching file was not specified.\n" + e);
-			}
-			try {
-				className = c.lookup("java:comp/env/NamespacesCachingClass");
-				if (className != null && className instanceof String) {
-					try {
-						NamespaceCache = (RDFCache) DiscoverSingleton.find(Class.forName((String) className), Class.forName((String) className).getName());
-						log.info((NamespaceCache == null ? "Caching of namespaces not enabled."
-								: "Caching of namespaces enabled."));
-					} catch (Exception e) {
-						NamespaceCache = null;
-						log.info("Caching of namespaces not enabled\n" + e);
-					}
-				}
-			} catch (Exception e) {
-				log.info("Caching of service types not enabled. Caching file was not specified.\n"
-						+ e);
-			}
+			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.info("Caching is not enabled for any ontology.\n" + e);
+			log.warn("ContextLoader is null and is therefore not loaded. This is BAD!"
+					+ System.getProperty("line.separator") + e.getMessage());
 		}
-		// caching variables
-		isCachableNamespaces = (NamespaceCache == null ? false : true);
-		isCachableServiceTypes = (ServiceTypesCache == null ? false : true);
-		isCachableObjects = (ObjectsCache == null ? false : true);
-		isCachableServiceInstances = (ServiceInstanceCache == null ? false : true);
-
-		
-		log.info("getting mobycentral registry properties ...");
-		try {
-			Context c = new InitialContext();
-			try {
-				String MOBY_CENTRAL_CONFIG = null;
-				MOBY_CENTRAL_CONFIG = (String) c.lookup("java:comp/env/MOBY_CENTRAL_CONFIG");
-				if (MOBY_CENTRAL_CONFIG != null && !MOBY_CENTRAL_CONFIG.equals("")) {
-					// set MOBY_CENTRAL_CONFIG
-					log.info("init(setting MOBY_CENTRAL_CONFIG)");
-					System.setProperty("MOBY_CENTRAL_CONFIG", MOBY_CENTRAL_CONFIG);
-				}
 
-			} catch (Exception ex) {
-			}
-			try {
-				String MOBY_SERVER = null;
-				MOBY_SERVER = (String) c.lookup("java:comp/env/MOBY_SERVER");
-				if (MOBY_SERVER != null && !MOBY_SERVER.equals("")) {
-					// set MOBY_SERVER
-					log.info("init(setting MOBY_SERVER)");
-					System.setProperty("MOBY_SERVER", MOBY_SERVER);
-					if (!__success)
-						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);
-							}
-							__success = true;
-						} catch (Exception ex) {
-
-						}
-				}
-			} catch (Exception ex) {
-			}
-
-			try {
-				String MOBY_URI = null;
-				MOBY_URI = (String) c.lookup("java:comp/env/MOBY_URI");
-				if (MOBY_URI != null && !MOBY_URI.equals("")) {
-					// set MOBY_URI
-					log.info("init(setting MOBY_URI)");
-					System.setProperty("MOBY_URI", MOBY_URI);
-				}
-			} catch (Exception ex) {
-			}
-		} catch (Exception ex) {
+		// attempt to load caching classes
+		if (cLoader != null) {
+			isCachableNamespaces = (cLoader.getNamespaceCache() == null ? false : true);
+			isCachableServiceTypes = (cLoader.getServiceTypesCache() == null ? false : true);
+			isCachableObjects = (cLoader.getObjectsCache() == null ? false : true);
+			isCachableServiceInstances = (cLoader.getServiceInstanceCache() == null ? false : true);
 		}
 
-		if (!__success)
-			try {
-				// default to mobycentral
-				log.warn("Defaulting to default mobycentral.");
-				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);
-				}
-			} catch (Exception ex) {
-				// some defaults if nothing else works
-				URI_MAP.put("Object", "http://biomoby.org/RESOURCES/MOBY-S/Objects#");
-
-				URI_MAP.put("Service", "http://biomoby.org/RESOURCES/MOBY-S/Services#");
-
-				URI_MAP.put("Namespace", "http://biomoby.org/RESOURCES/MOBY-S/Namespaces#");
-
-				URI_MAP.put("ServiceInstance",
-						"http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances#");
-			}
-
-		OBJ = (String) URI_MAP.get("Object");
-		SRV = (String) URI_MAP.get("Service");
-		NS = (String) URI_MAP.get("Namespace");
+		OBJ = (String) cLoader.getURI_MAP().get("Object");
+		SRV = (String) cLoader.getURI_MAP().get("Service");
+		NS = (String) cLoader.getURI_MAP().get("Namespace");
 		PRED = "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
-		SI = (String) URI_MAP.get("ServiceInstance");
+		SI = (String) cLoader.getURI_MAP().get("ServiceInstance");
 	}
 
 	/*
@@ -292,11 +142,11 @@
 			throws ServletException, IOException {
 		PrintWriter out = response.getWriter();
 		String path = request.getPathInfo();
-		if (path == null ) {
+		if (path == null) {
 			out
 					.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>not MOBY-S</title></head><body><h2>not MOBY-S </h2></body></html>");
 			return;
-		} 
+		}
 		Pattern p = Pattern.compile("/MOBY\\-S/(\\S+)");
 		Matcher m = p.matcher(path);
 		if (!m.matches()) {
@@ -317,7 +167,7 @@
 					} catch (MobyException e) {
 						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
 								"Could not get Objects");
-						e.printStackTrace();
+						log.error("Exception thrown: " + e.getMessage());
 						return;
 					}
 					if (model == null) {
@@ -337,7 +187,7 @@
 					} catch (MobyException e) {
 						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
 								"Could not get Namespaces");
-						e.printStackTrace();
+						log.error("Exception thrown: " + e.getMessage());
 						return;
 					}
 					if (model == null) {
@@ -357,7 +207,7 @@
 					} catch (MobyException e) {
 						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
 								"Could not get Services");
-						e.printStackTrace();
+						log.error("Exception thrown: " + e.getMessage());
 						return;
 					}
 					if (model == null) {
@@ -377,8 +227,8 @@
 					response.setHeader("Content-Disposition",
 							"attachment;filename=ServiceInstances");
 					if (isCachableServiceInstances) {
-						if (ServiceInstanceCache.isCachedMostRecent()) {
-							out.write(ServiceInstanceCache.getCachedRDF());
+						if (cLoader.getServiceInstanceCache().isCachedMostRecent()) {
+							out.write(cLoader.getServiceInstanceCache().getCachedRDF());
 							return;
 						} else {
 							try {
@@ -401,9 +251,9 @@
 							writer.setProperty("showXmlDeclaration", "false");
 							writer.setProperty("tab", "5");
 							writer.write(model, stream, null);
-							if (!ServiceInstanceCache.isCachedMostRecent())
-								ServiceInstanceCache.cacheRDF(stream.getOutput(),
-										ServiceInstanceCache.getLatestCriteria());
+							if (!cLoader.getServiceInstanceCache().isCachedMostRecent())
+								cLoader.getServiceInstanceCache().cacheRDF(stream.getOutput(),
+										cLoader.getServiceInstanceCache().getLatestCriteria());
 							stream = null;
 							// now output the RDF
 							writer = model.getWriter("RDF/XML-ABBREV");
@@ -417,7 +267,7 @@
 						} catch (Exception e) {
 							response.sendError(HttpServletResponse.SC_BAD_REQUEST,
 									"Could not get ServiceInstances");
-							e.printStackTrace();
+							log.error("Exception thrown: " + e.getMessage());
 							return;
 						}
 						if (model == null) {
@@ -448,7 +298,7 @@
 						model = getAll(model);
 					} catch (Exception e) {
 						response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get All");
-						e.printStackTrace();
+						log.error("Exception thrown: " + e.getMessage());
 						return;
 					}
 					if (model == null) {
@@ -492,7 +342,7 @@
 		try {
 			model = getServiceInstances(model);
 		} catch (ModelException e) {
-			e.printStackTrace();
+			log.error("Exception thrown: " + e.getMessage());
 			return null;
 		}
 		return model;
@@ -513,7 +363,7 @@
 			createNsMap(model);
 		}
 
-		CentralDigest central = null;
+		CentralImpl central = null;
 		MobyService[] services = null;
 		try {
 			String registryURL;
@@ -524,26 +374,26 @@
 				log.info("System vars: " + registryURL + ", " + registryNamespace);
 				if (registryURL == null) {
 					// use default registry, since we dont have a local one
-					central = new CentralDigestImpl();
+					central = new CentralImpl();
 				} else if (registryNamespace == null) {
 					// use default namespace since one isnt defined
-					central = new CentralDigestImpl(registryURL);
+					central = new CentralImpl(registryURL);
 				} else {
 					// use defined url and namespacce
-					central = new CentralDigestImpl(registryURL, registryNamespace);
+					central = new CentralImpl(registryURL, registryNamespace);
 				}
 			} else {
 				// use default registry since we cant determine if local one
 				// exists
-				central = new CentralDigestImpl();
+				central = new CentralImpl();
 			}
-			services = central.getServices();
+			services = central.findService(new MobyService(""));
 		} catch (MobyException e) {
-			e.printStackTrace();
+			log.error("Exception thrown: " + e.getMessage());
 		}
 		if (central == null || services == null)
 			throw new MobyException(
-					"Could not retrieve useful information from CentralDigestImpl().getServices(String)");
+					"Could not retrieve useful information from CentralImpl().findService(String)");
 		return ServiceInstanceRDF.createRDFModel(model, services, true);
 	}
 
@@ -762,7 +612,7 @@
 	}
 
 	/*
-	 *
+	 * 
 	 */
 	private final Resource _addClassResource(Model model, String uri, String label, String lsid,
 			String def, String authority, String email) {
@@ -788,19 +638,19 @@
 			try {
 				return new JObjectsSqlImpl().getFullObjectsAsArray();
 			} catch (Exception e) {
-				e.printStackTrace();
+				log.error("Exception thrown: " + e.getMessage());
 			}
 		} else if (type.equalsIgnoreCase("services")) {
 			try {
 				return new JServicesSqlImpl().getFullServicesAsArray();
 			} catch (Exception e) {
-				e.printStackTrace();
+				log.error("Exception thrown: " + e.getMessage());
 			}
 		} else if (type.equalsIgnoreCase("namespaces")) {
 			try {
 				return new JNamespacesSqlImpl().getFullNamespacesAsArray();
 			} catch (Exception e) {
-				e.printStackTrace();
+				log.error("Exception thrown: " + e.getMessage());
 			}
 		}
 		return null;
@@ -858,7 +708,7 @@
 		try {
 			model = getServiceInstances(model);
 		} catch (Exception e) {
-			e.printStackTrace();
+			log.error("Exception thrown: " + e.getMessage());
 			return "";
 		}
 		RDFWriter writer = model.getWriter("RDF/XML-ABBREV");




More information about the MOBY-guts mailing list