licencing and format applied (eclipse)
[jalview.git] / src / org / biojava / dasobert / das / DAS_FeatureRetrieve.java
index 21ccee1..7d35dea 100755 (executable)
@@ -34,23 +34,27 @@ import org.xml.sax.*;
 
 /**
  * A class to perform a DAS features request
- *
- * @author Andreas Prlic
- * Adapted for jalview use.
- * @author Andrew Waterhouse 
- * Updated to Das 1.53e feature spec.
+ * 
+ * @author Andreas Prlic Adapted for jalview use.
+ * @author Andrew Waterhouse Updated to Das 1.53e feature spec.
  * @author Jim Procter
  */
 public class DAS_FeatureRetrieve
 {
   String version;
+
   List features;
+
   Logger logger;
+
   int comeBackLater;
+
   URL url;
+
   /**
-   * @param url the URL the features should be downloaded from
-   *
+   * @param url
+   *                the URL the features should be downloaded from
+   * 
    */
   public DAS_FeatureRetrieve(URL url)
   {
@@ -63,10 +67,11 @@ public class DAS_FeatureRetrieve
     reload();
   }
 
-  /** contact the DAS-feature server again. Usually
-   * it is not necessary to call this again, because the constructor already does, but
-   * if comeBackLater > -1 this should be called again.
-   *
+  /**
+   * contact the DAS-feature server again. Usually it is not necessary to call
+   * this again, because the constructor already does, but if comeBackLater > -1
+   * this should be called again.
+   * 
    */
   public void reload()
   {
@@ -78,8 +83,7 @@ public class DAS_FeatureRetrieve
       try
       {
         dasInStream = open(url);
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
         comeBackLater = -1;
         System.out.println("NO RESPONSE FROM " + url);
@@ -87,8 +91,7 @@ public class DAS_FeatureRetrieve
         return;
       }
 
-      SAXParserFactory spfactory =
-          SAXParserFactory.newInstance();
+      SAXParserFactory spfactory = SAXParserFactory.newInstance();
 
       spfactory.setValidating(false);
 
@@ -96,10 +99,8 @@ public class DAS_FeatureRetrieve
 
       try
       {
-        saxParser =
-            spfactory.newSAXParser();
-      }
-      catch (ParserConfigurationException e)
+        saxParser = spfactory.newSAXParser();
+      } catch (ParserConfigurationException e)
       {
         e.printStackTrace();
       }
@@ -117,27 +118,28 @@ public class DAS_FeatureRetrieve
 
       XMLReader xmlreader = saxParser.getXMLReader();
 
-      //XMLReader xmlreader = XMLReaderFactory.createXMLReader();
+      // XMLReader xmlreader = XMLReaderFactory.createXMLReader();
       try
       {
         xmlreader.setFeature("http://xml.org/sax/features/validation",
-                             validation);
-      }
-      catch (SAXException e)
+                validation);
+      } catch (SAXException e)
       {
         logger.log(Level.FINE, "Cannot set validation " + validation);
       }
 
       try
       {
-        xmlreader.setFeature(
-            "http://apache.org/xml/features/nonvalidating/load-external-dtd",
-            validation);
-      }
-      catch (SAXNotRecognizedException e)
+        xmlreader
+                .setFeature(
+                        "http://apache.org/xml/features/nonvalidating/load-external-dtd",
+                        validation);
+      } catch (SAXNotRecognizedException e)
       {
         e.printStackTrace();
-        logger.log(Level.FINE, "Cannot set load-external-dtd " + validation);
+        logger
+                .log(Level.FINE, "Cannot set load-external-dtd "
+                        + validation);
 
       }
 
@@ -152,30 +154,30 @@ public class DAS_FeatureRetrieve
       {
         xmlreader.parse(insource);
         features = cont_handle.get_features();
-                version  = cont_handle.getVersion();
-                
+        version = cont_handle.getVersion();
+
         comeBackLater = cont_handle.getComBackLater();
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
-        System.out.println("Error parsing response from: " + url + "\n" + e);
+        System.out
+                .println("Error parsing response from: " + url + "\n" + e);
         logger.log(Level.FINE, "error while parsing response from " + url);
         comeBackLater = -1;
         features = new ArrayList();
       }
-    }
-    catch (Exception ex)
+    } catch (Exception ex)
     {
       ex.printStackTrace();
       comeBackLater = -1;
     }
   }
 
-  /** open HttpURLConnection. Recommended way to open
-   * HttpURLConnections, since this take care of setting timeouts
-   * properly for java 1.4 and 1.5*/
+  /**
+   * open HttpURLConnection. Recommended way to open HttpURLConnections, since
+   * this take care of setting timeouts properly for java 1.4 and 1.5
+   */
   public static HttpURLConnection openHttpURLConnection(URL url)
-      throws IOException, ConnectException
+          throws IOException, ConnectException
   {
     HttpURLConnection huc = null;
     huc = (HttpURLConnection) url.openConnection();
@@ -185,18 +187,20 @@ public class DAS_FeatureRetrieve
     String os_arch = java.lang.System.getProperty("os.arch");
     String VERSION = "1.0";
 
-    String userAgent = "Jalview " + VERSION + "(" + os_name + "; " + os_arch +
-        " ; " + os_version + ")";
-    //e.g. "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040803"
+    String userAgent = "Jalview " + VERSION + "(" + os_name + "; "
+            + os_arch + " ; " + os_version + ")";
+    // e.g. "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040803"
     huc.addRequestProperty("User-Agent", userAgent);
-    //logger.finest("opening "+url);
-
+    // logger.finest("opening "+url);
 
     int timeout = 10000;
-    System.setProperty("sun.net.client.defaultConnectTimeout", timeout + "");
+    System
+            .setProperty("sun.net.client.defaultConnectTimeout", timeout
+                    + "");
     System.setProperty("sun.net.client.defaultReadTimeout", timeout + "");
 
-    // use reflection to determine if get and set timeout methods for urlconnection are available
+    // use reflection to determine if get and set timeout methods for
+    // urlconnection are available
     // seems java 1.5 does not watch the System properties any longer...
     // and java 1.4 did not provide these...
     // for 1.4 see setSystemProperties
@@ -204,33 +208,31 @@ public class DAS_FeatureRetrieve
     try
     {
       // try to use reflection to set timeout property
-      Class urlconnectionClass = Class.forName("java.net.HttpURLConnection");
+      Class urlconnectionClass = Class
+              .forName("java.net.HttpURLConnection");
 
       Method setconnecttimeout = urlconnectionClass.getMethod(
-          "setConnectTimeout", new Class[]
-          {int.class}
-          );
+              "setConnectTimeout", new Class[]
+              { int.class });
       setconnecttimeout.invoke(huc, new Object[]
-                               {new Integer(timeout)});
+      { new Integer(timeout) });
 
       Method setreadtimeout = urlconnectionClass.getMethod(
-          "setReadTimeout", new Class[]
-          {int.class}
-          );
+              "setReadTimeout", new Class[]
+              { int.class });
       setreadtimeout.invoke(huc, new Object[]
-                            {new Integer(timeout)});
-      //System.out.println("successfully set java 1.5 timeout");
-    }
-    catch (Exception e)
+      { new Integer(timeout) });
+      // System.out.println("successfully set java 1.5 timeout");
+    } catch (Exception e)
     {
-      //e.printStackTrace();
+      // e.printStackTrace();
       // most likely it was a NoSuchMEthodException and we are running java 1.4.
     }
     return huc;
   }
 
-  private InputStream open(URL url)
-      throws java.io.IOException, java.net.ConnectException
+  private InputStream open(URL url) throws java.io.IOException,
+          java.net.ConnectException
   {
     InputStream inStream = null;
 
@@ -242,32 +244,37 @@ public class DAS_FeatureRetrieve
 
   }
 
-  /** returns a List of Features
-   * @return a List of Maps containing the features*/
+  /**
+   * returns a List of Features
+   * 
+   * @return a List of Maps containing the features
+   */
   public List get_features()
   {
 
     return features;
-    }
-    
-    
-    /** Get the version string of the reference object.
-     * If it does not match the version string that is obtained from the 
-     * reference server there is a version problem!
-     *  
-     * @return version string. (e.g. a MD5 digest of the reference sequence)
-     */
-    public String getVersion() {
-               return version;
-       }
-
-
-       public void setVersion(String version) {
-               this.version = version;
   }
 
-  /** returns the comeBackLater value - if a server returned suchh -
-   *
+  /**
+   * Get the version string of the reference object. If it does not match the
+   * version string that is obtained from the reference server there is a
+   * version problem!
+   * 
+   * @return version string. (e.g. a MD5 digest of the reference sequence)
+   */
+  public String getVersion()
+  {
+    return version;
+  }
+
+  public void setVersion(String version)
+  {
+    this.version = version;
+  }
+
+  /**
+   * returns the comeBackLater value - if a server returned suchh -
+   * 
    * @return comeBackLater in seconds, or -1 if not provided by server
    */
   public int getComeBackLater()