[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Thu Apr 28 18:39:40 UTC 2005


kawas
Thu Apr 28 14:39:40 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources
In directory pub.open-bio.org:/tmp/cvs-serv10633/org/biomoby/client/ui/graphical/servlet/jresources

Modified Files:
	RESOURCE.java 
Log Message:
added a backup to getTypes() that kicks in if mysql connections, etc dont work.
Eddie

moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources RESOURCE.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java	2005/04/07 16:42:29	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/jresources/RESOURCE.java	2005/04/28 18:39:40	1.2
@@ -1,8 +1,11 @@
 package org.biomoby.client.ui.graphical.servlet.jresources;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.URL;
 import java.util.Map;
 import java.util.Properties;
 import java.util.regex.Matcher;
@@ -156,7 +159,9 @@
 
     private static boolean RUN_MAIN = false;
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.GenericServlet#init()
      */
     public final void init() throws ServletException {
@@ -186,12 +191,14 @@
                     try {
                         model = getObjects(model);
                     } catch (MobyException e) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get Objects");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Could not get Objects");
                         e.printStackTrace();
                         return;
                     }
                     if (model == null) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cound not create model");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Cound not create model");
                         return;
                     }
                     response.setContentType("application/rdf+xml");
@@ -205,12 +212,14 @@
                     try {
                         model = getNamespaces(model);
                     } catch (MobyException e) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get Namespaces");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Could not get Namespaces");
                         e.printStackTrace();
                         return;
                     }
                     if (model == null) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cound not create model");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Cound not create model");
                         return;
                     }
                     response.setContentType("application/rdf+xml");
@@ -224,12 +233,14 @@
                     try {
                         model = getServices(model);
                     } catch (MobyException e) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get Services");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Could not get Services");
                         e.printStackTrace();
                         return;
                     }
                     if (model == null) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cound not create model");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Cound not create model");
                         return;
                     }
                     response.setContentType("application/rdf+xml");
@@ -243,12 +254,14 @@
                     try {
                         model = getServiceInstances(model);
                     } catch (Exception e) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get ServiceInstances");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Could not get ServiceInstances");
                         e.printStackTrace();
                         return;
                     }
                     if (model == null) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cound not create model");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Cound not create model");
                         return;
                     }
                     response.setContentType("application/rdf+xml");
@@ -262,12 +275,14 @@
                     try {
                         model = getAll(model);
                     } catch (Exception e) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not get All");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Could not get All");
                         e.printStackTrace();
                         return;
                     }
                     if (model == null) {
-                        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cound not create model");
+                        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+                                "Cound not create model");
                         return;
                     }
                     response.setContentType("application/rdf+xml");
@@ -279,7 +294,7 @@
                     return;
                 }
             } else {
-                //response.sendError(HttpServletResponse.SC_NOT_FOUND);
+                // response.sendError(HttpServletResponse.SC_NOT_FOUND);
                 out.println(RESOURCE.Four0FourError);
                 return;
             }
@@ -291,7 +306,7 @@
      * 
      * @param model
      * @return
-     * @throws MobyException 
+     * @throws MobyException
      */
     private final Model getAll(Model model) throws Exception {
         model = getObjects(model);
@@ -326,7 +341,8 @@
             e.printStackTrace();
         }
         if (central == null || services == null)
-            throw new MobyException("Could not retrieve useful information from CentralDigestImpl().getServices(String)");
+            throw new MobyException(
+                    "Could not retrieve useful information from CentralDigestImpl().getServices(String)");
         for (int i = 0; i < services.length; i++) {
             MobyData[] primaryInputs = services[i].getPrimaryInputs(); // consumes
             MobyData[] secondaryInputs = services[i].getSecondaryInputs(); // consumes
@@ -413,7 +429,7 @@
                             }
                         }
                         if (innerBag != null && innerBag.size() > 0) {
-                            //TODO
+                            // TODO
                             consumeBag.add(innerBag);
                         }
                         // iterate through items adding them to the bag
@@ -554,7 +570,7 @@
                 MobyNamespace mns = ns[k];
                 _li.addProperty(Predicates.namespace_type, model
                         .createResource(NS + mns.getName()));
-                //.addProperty(RDF.type, RDFS.Class));
+                // .addProperty(RDF.type, RDFS.Class));
             }
         }
         return _li;
@@ -565,7 +581,7 @@
      * 
      * @param model
      * @return
-     * @throws MobyException 
+     * @throws MobyException
      */
     private final Model getServices(Model model) throws MobyException {
 
@@ -602,7 +618,7 @@
      * 
      * @param model
      * @return
-     * @throws MobyException 
+     * @throws MobyException
      */
     private final Model getNamespaces(Model model) throws MobyException {
         String str = getTypes("Namespaces");
@@ -632,7 +648,7 @@
      * <b>PRE: </b> <p><b>POST: </b> <p>
      * 
      * @param model
-     * @throws MobyException 
+     * @throws MobyException
      */
     private final Model getObjects(Model model) throws MobyException {
         String str = getTypes("Objects");
@@ -667,7 +683,7 @@
             m = Pattern.compile(".*:isa$", Pattern.CASE_INSENSITIVE).matcher(
                     pred);
             if (m.matches()) {
-                //System.out.println("is " +pred);
+                // System.out.println("is " +pred);
                 _addSubClass(model, _subject, OBJ, obj);
             }
             m = Pattern.compile(".*:hasa$", Pattern.CASE_INSENSITIVE).matcher(
@@ -774,21 +790,61 @@
 
     private final String getTypes(String type) throws MobyException {
         if (type.equalsIgnoreCase("objects")) {
-            return new JObjects().getObjects();
+            try {
+                return new JObjects().getObjects();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            // resort to a secondary method for retrieval of JObjects
+            return getURL("http://mobycentral.cbr.nrc.ca:8090/types/Objects");
         } else if (type.equalsIgnoreCase("services")) {
-            return new JServices().getServices();
+            try {
+                return new JServices().getServices();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            // resort to a secondary method for retrieval of JServices
+            return getURL("http://mobycentral.cbr.nrc.ca:8090/types/Services");
         } else if (type.equalsIgnoreCase("namespaces")) {
-            return new JNamespaces().getNamespaces();
+            try {
+                return new JNamespaces().getNamespaces();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            // resort to a secondary method for retrieval of JNamespaces
+            return getURL("http://mobycentral.cbr.nrc.ca:8090/types/Namespaces");
         }
         return "";
     }
 
+    /*
+     * 
+     */
+    private String getURL(String url) {
+        StringBuffer sb = new StringBuffer();
+        try {
+            URL _url = new URL(url);
+            BufferedReader in = new BufferedReader(new InputStreamReader(_url
+                    .openStream()));
+            String inputLine;
+            while ((inputLine = in.readLine()) != null)
+                sb.append(inputLine+"\n");
+            in.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.err.println("Could not retrieve contents of URL.");
+        }
+        return sb.toString();
+    }
+
     protected final void doPost(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
         response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.GenericServlet#getServletInfo()
      */
     public final String getServletInfo() {
@@ -863,8 +919,9 @@
         }
         return "";
     }
+
     public static void main(String[] args) throws MobyException {
-        System.out.println(new RESOURCE().getRESOURCES("ServiceInstances"));
+        System.out.println(new RESOURCE().getRESOURCES("Objects"));
     }
 
 }




More information about the MOBY-guts mailing list