Readded
authoramwaterhouse <Andrew Waterhouse>
Thu, 27 Jul 2006 07:34:20 +0000 (07:34 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 27 Jul 2006 07:34:20 +0000 (07:34 +0000)
22 files changed:
src/jalview/biojava/dasobert/das/DAS_FeatureRetrieve.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das/DAS_Feature_Handler.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das/FeatureThread.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/Das2Capability.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/Das2CapabilityImpl.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/Das2Source.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/Das2SourceImpl.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/DasSourceConverter.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/io/DAS2SourceHandler.java [new file with mode: 0755]
src/jalview/biojava/dasobert/das2/io/DasSourceReader.java [new file with mode: 0644]
src/jalview/biojava/dasobert/das2/io/DasSourceReaderImpl.java [new file with mode: 0644]
src/jalview/biojava/dasobert/dasregistry/Das1Source.java [new file with mode: 0644]
src/jalview/biojava/dasobert/dasregistry/Das2Validator.java [new file with mode: 0755]
src/jalview/biojava/dasobert/dasregistry/DasCoordSysComparator.java [new file with mode: 0644]
src/jalview/biojava/dasobert/dasregistry/DasCoordinateSystem.java [new file with mode: 0644]
src/jalview/biojava/dasobert/dasregistry/DasSource.java [new file with mode: 0644]
src/jalview/biojava/dasobert/dasregistry/DasSourceComparator.java [new file with mode: 0644]
src/jalview/biojava/dasobert/eventmodel/FeatureEvent.java [new file with mode: 0644]
src/jalview/biojava/dasobert/eventmodel/FeatureListener.java [new file with mode: 0644]
src/jalview/biojava/dasobert/eventmodel/ObjectListener.java [new file with mode: 0644]
src/jalview/biojava/dasobert/eventmodel/SequenceEvent.java [new file with mode: 0644]
src/jalview/biojava/dasobert/eventmodel/SequenceListener.java [new file with mode: 0644]

diff --git a/src/jalview/biojava/dasobert/das/DAS_FeatureRetrieve.java b/src/jalview/biojava/dasobert/das/DAS_FeatureRetrieve.java
new file mode 100644 (file)
index 0000000..b65a847
--- /dev/null
@@ -0,0 +1,235 @@
+/**
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 19.03.2004
+ * @author Andreas Prlic
+ *
+ */
+package org.biojava.dasobert.das;
+
+
+import java.net.URL                         ;
+import java.io.InputStream                  ;
+import org.xml.sax.InputSource              ;
+import org.xml.sax.XMLReader                ;
+import javax.xml.parsers.*                  ;
+import org.xml.sax.*                        ;
+import java.util.ArrayList                  ;
+import java.util.List;
+import java.util.logging.*                  ;
+import java.net.HttpURLConnection           ;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.lang.reflect.Method;
+
+
+
+
+/**
+ * A class to perform a DAS features request
+ *
+ * @author Andreas Prlic
+ *
+ */
+public class DAS_FeatureRetrieve {
+
+    List features ;
+    Logger logger     ;
+    int comeBackLater;
+    URL url;
+    /**
+     * @param url the URL the features should be downloaded from
+     *
+     */
+    public DAS_FeatureRetrieve(URL url) {
+        super();
+
+        logger = Logger.getLogger("org.biojava.spice");
+        features = new ArrayList() ;
+        comeBackLater = -1;
+        this.url=url;
+        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.
+     *
+     */
+    public void reload(){
+
+        try {
+
+            InputStream dasInStream = null;
+            try {
+                dasInStream    = open(url);
+            } catch (Exception e ){
+                comeBackLater = -1;
+                logger.log(Level.FINE,"could not open connection to " + url,e);
+                return ;
+            }
+
+
+            SAXParserFactory spfactory =
+                SAXParserFactory.newInstance();
+
+            spfactory.setValidating(false);
+
+            SAXParser saxParser = null ;
+
+            try{
+                saxParser =
+                    spfactory.newSAXParser();
+            } catch (ParserConfigurationException e) {
+                e.printStackTrace();
+            }
+
+
+
+            String vali = System.getProperty("XMLVALIDATION");
+
+            boolean validation = false ;
+            if ( vali != null )
+                if ( vali.equals("true") )
+                    validation = true ;
+
+
+            XMLReader xmlreader = saxParser.getXMLReader();
+
+            //XMLReader xmlreader = XMLReaderFactory.createXMLReader();
+            try {
+                xmlreader.setFeature("http://xml.org/sax/features/validation", 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){
+                e.printStackTrace();
+                logger.log(Level.FINE,"Cannot set load-external-dtd "+validation);
+
+            }
+
+            DAS_Feature_Handler cont_handle = new DAS_Feature_Handler() ;
+            cont_handle.setDASCommand(url.toString());
+            xmlreader.setContentHandler(cont_handle);
+            xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
+            InputSource insource = new InputSource() ;
+            insource.setByteStream(dasInStream);
+
+            try {
+                xmlreader.parse(insource);
+                features = cont_handle.get_features();
+                comeBackLater = cont_handle.getComBackLater();
+            }
+            catch ( Exception e){
+                e.printStackTrace();
+                logger.log(Level.FINE,"error while parsing response from "+ url);
+                comeBackLater = -1;
+                features = new ArrayList();
+            }
+        }
+        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*/
+    public static HttpURLConnection openHttpURLConnection(URL url)
+    throws IOException, ConnectException {
+    HttpURLConnection huc = null;
+    huc = (HttpURLConnection) url.openConnection();
+
+    String os_name    = java.lang.System.getProperty("os.name");
+    String os_version = java.lang.System.getProperty("os.version");
+    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"
+     huc.addRequestProperty("User-Agent", userAgent);
+    //logger.finest("opening "+url);
+
+
+    // 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
+    int timeout = 15000;
+    try {
+        // try to use reflection to set timeout property
+        Class urlconnectionClass = Class.forName("java.net.HttpURLConnection");
+
+            Method setconnecttimeout = urlconnectionClass.getMethod (
+                                     "setConnectTimeout", new Class [] {int.class}
+                                     );
+        setconnecttimeout.invoke(huc,new Object[] {new Integer(timeout)});
+
+        Method setreadtimeout = urlconnectionClass.getMethod (
+                                  "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) {
+        //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
+    {
+        InputStream inStream = null;
+
+
+        HttpURLConnection huc = openHttpURLConnection(url);
+
+        inStream = huc.getInputStream();
+
+        return inStream;
+
+    }
+
+    /** returns a List of Features
+     * @return a List of Maps containing the features*/
+    public List get_features() {
+
+        return features;
+    }
+
+    /** returns the comeBackLater value - if a server returned suchh -
+     *
+     * @return comeBackLater in seconds, or -1 if not provided by server
+     */
+    public int getComeBackLater(){
+
+        return comeBackLater;
+
+    }
+
+
+}
diff --git a/src/jalview/biojava/dasobert/das/DAS_Feature_Handler.java b/src/jalview/biojava/dasobert/das/DAS_Feature_Handler.java
new file mode 100644 (file)
index 0000000..fa42fe4
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 19.03.2004
+ * @author Andreas Prlic
+ *
+ */
+package org.biojava.dasobert.das;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Attributes;
+
+import java.util.ArrayList ;
+import java.util.HashMap ;
+import java.util.List;
+
+/**
+ * a class to parse the response of a DAS - Feature request
+ * @author Andreas Prlic
+ *
+ */
+public class DAS_Feature_Handler  extends DefaultHandler{
+
+    /**
+     *
+     */
+    List features ;
+    boolean first_flag ;
+    HashMap feature ;
+    String featurefield ;
+    String characterdata ;
+    String dasCommand ;
+
+    int comeBackLater ;
+
+    int maxFeatures ;
+
+    public DAS_Feature_Handler() {
+        super();
+
+        features= new ArrayList() ;
+        first_flag = true ;
+        featurefield = "" ;
+        characterdata = "";
+        dasCommand = "" ;
+        comeBackLater = -1;
+       maxFeatures = -1;
+    }
+
+    /** specifies a maximum number of features to be downloaded. if a
+       server returns more, they will be ignored.  default is to load
+       all features
+    @param max the maximium number of features to be downloaded
+    */
+
+    public void setMaxFeatures(int max) {
+       maxFeatures = max;
+    }
+
+    public int getMaxFeatures() {
+       return maxFeatures;
+    }
+
+    public void setDASCommand(String cmd) { dasCommand = cmd ;}
+    public String getDASCommand() { return dasCommand; }
+
+    public List get_features() {
+        return features ;
+    }
+
+    public int getComBackLater(){
+        return comeBackLater;
+    }
+
+    void start_feature(String uri, String name, String qName, Attributes atts) {
+
+       if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
+           characterdata = "";
+           return;
+       }
+        feature = new HashMap() ;
+        String id      = atts.getValue("id");
+        feature.put("id",id);
+        feature.put("dassource",dasCommand);
+        characterdata = "";
+    }
+
+    void add_featuredata(String uri, String name, String qName) {
+        //System.out.println("featurefield "+featurefield+ " data "+characterdata);
+        // NOTE can have multiple lines ..
+
+       if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
+           return;
+       }
+
+
+        String data = (String)feature.get(featurefield);
+        if (data != null){
+            characterdata = data + " " + characterdata;
+        }
+
+        feature.put(featurefield,characterdata);
+        featurefield = "";
+        characterdata = "";
+    }
+
+    private void addLink(String uri, String name, String qName, Attributes atts) {
+        String href = atts.getValue("href");
+        feature.put("LINK",href);
+        characterdata="";
+        featurefield = "LINK-TEXT";
+
+    }
+
+    public void startElement (String uri, String name, String qName, Attributes atts){
+        //System.out.println("new element "+qName);
+
+        if (qName.equals("FEATURE"))
+            start_feature(uri,  name,  qName,  atts);
+        else if ( qName.equals("LINK"))
+            addLink(uri,name,qName, atts);
+        else if ( qName.equals("METHOD") ||
+                qName.equals("TYPE") ||
+                qName.equals("START") ||
+                qName.equals("END") ||
+                qName.equals("NOTE") ||
+                qName.equals("SCORE")
+        ){
+            characterdata ="";
+            featurefield = qName ;
+        }
+
+    }
+
+    public void startDocument() {
+    }
+
+    public void endDocument () {
+    }
+    public void endElement(String uri, String name, String qName) {
+
+        if ( qName.equals("METHOD") ||
+                qName.equals("TYPE") ||
+                qName.equals("START") ||
+                qName.equals("END") ||
+                qName.equals("NOTE") ||
+                qName.equals("LINK") ||
+                qName.equals("SCORE")
+        ) {
+            add_featuredata(uri,name,qName);
+        }
+        else if ( qName.equals("FEATURE")) {
+
+           if ( maxFeatures > 0 ) {
+               if ( features.size() < maxFeatures ) {
+                    features.add(feature);
+               }
+           } else {
+               // no restriction
+               features.add(feature);
+           }
+        }
+    }
+
+    public void characters (char ch[], int start, int length){
+
+        for (int i = start; i < start + length; i++) {
+
+            characterdata += ch[i];
+        }
+
+    }
+
+}
diff --git a/src/jalview/biojava/dasobert/das/FeatureThread.java b/src/jalview/biojava/dasobert/das/FeatureThread.java
new file mode 100644 (file)
index 0000000..4d07c89
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 21.09.2004
+ * @author Andreas Prlic
+ *
+ */
+
+package org.biojava.dasobert.das ;
+
+import java.util.*;
+import java.net.*;
+import java.util.logging.* ;
+import org.biojava.dasobert.eventmodel.FeatureListener;
+import org.biojava.dasobert.eventmodel.FeatureEvent;
+import org.biojava.dasobert.dasregistry.Das1Source;
+
+/** a thread that connects to a DAS - Feature service and gets the features
+ *
+ * @author Andreas Prlic
+ */
+
+
+
+public class FeatureThread
+    implements Runnable
+{
+
+    /** number of times the client tries to reconnect to the server if a "come back later" is returned.
+     * the server should provide a reasonable estimation how long it will take him to create results.
+     * if this number of requests is still not successfull, give up.
+     */
+    public static int MAX_COME_BACK_ITERATIONS = 5;
+
+    public static int MAX_NR_FEATURES = 300;
+
+    static Logger logger = Logger.getLogger("org.biojava.spice");
+
+    Das1Source dasSource;
+    String ac ;
+    List featureListeners;
+    Thread thread;
+
+    public FeatureThread (String accessionCode, Das1Source dasSource) {
+       this.dasSource = dasSource;
+       this.ac = accessionCode;
+       featureListeners = new ArrayList();
+    }
+
+    public void addFeatureListener(FeatureListener li) {
+       featureListeners.add(li);
+    }
+
+    public void clearFeatureListeners() {
+       featureListeners.clear();
+    }
+
+    public synchronized void stop(){
+       thread = null;
+       notify();
+    }
+
+
+
+
+    public void run() {
+       Thread me = Thread.currentThread();
+       while ( thread == me) {
+           String url = dasSource.getUrl();
+           String queryString = url + "features?segment="+ ac ;
+           URL cmd = null ;
+           try {
+               cmd = new URL(queryString);
+           } catch (MalformedURLException e ) {
+               logger.warning("got MalformedURL from das source " +dasSource);
+               e.printStackTrace();
+
+           }
+
+           logger.info("requesting features from " + cmd);
+           DAS_FeatureRetrieve ftmp = new DAS_FeatureRetrieve(cmd);
+
+
+           int comeBackLater = ftmp.getComeBackLater();
+           int securityCounter = 0;
+           while ( (thread == me) && ( comeBackLater > 0 )) {
+               securityCounter++;
+               if ( securityCounter >= MAX_COME_BACK_ITERATIONS){
+                   comeBackLater = -1;
+                   break;
+
+               }
+               notifyComeBackLater(comeBackLater);
+               // server is still calculating - asks us to come back later
+               try {
+                   wait (comeBackLater);
+               } catch (InterruptedException e){
+                   comeBackLater = -1;
+                   break;
+               }
+
+               ftmp.reload();
+               comeBackLater = ftmp.getComeBackLater();
+           }
+
+           if ( ! (thread == me ) ) {
+               break;
+           }
+
+           List features = ftmp.get_features();
+
+           // a fallback mechanism to prevent DAS sources from bringing down spice
+           if ( features.size() > MAX_NR_FEATURES){
+               logger.warning("DAS source returned more than " + MAX_NR_FEATURES + "features. " +
+                              " throwing away excess features at " +cmd);
+               features = features.subList(0,MAX_NR_FEATURES);
+           }
+
+
+           // notify FeatureListeners
+           Map[] feats = (Map[])features.toArray(new Map[features.size()]);
+           notifyFeatureListeners(feats);
+
+           break;
+
+
+       }
+       thread = null;
+
+    }
+
+    public void start() {
+       thread = new Thread(this);
+       thread.start();
+    }
+
+    private void notifyFeatureListeners(Map[] feats){
+        logger.finest("FeatureThread found " + feats.length + " features");
+        FeatureEvent fevent = new FeatureEvent(feats,dasSource);
+        Iterator fiter = featureListeners.iterator();
+        while (fiter.hasNext()){
+            FeatureListener fi = (FeatureListener)fiter.next();
+            fi.newFeatures(fevent);
+        }
+    }
+
+ /** the Annotation server requested to be queried again in a while
+     *
+     * @param comeBackLater
+     */
+    private void notifyComeBackLater(int comeBackLater){
+        FeatureEvent event = new FeatureEvent(new HashMap[0],dasSource);
+        event.setComeBackLater(comeBackLater);
+        Iterator fiter = featureListeners.iterator();
+        while (fiter.hasNext()){
+            FeatureListener fi = (FeatureListener)fiter.next();
+            fi.comeBackLater(event);
+        }
+
+    }
+
+
+}
+
diff --git a/src/jalview/biojava/dasobert/das2/Das2Capability.java b/src/jalview/biojava/dasobert/das2/Das2Capability.java
new file mode 100644 (file)
index 0000000..5cff3f5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 9, 2006
+ *
+ */
+package org.biojava.dasobert.das2;
+
+public interface Das2Capability {
+
+    public boolean equals(Das2Capability other);
+    public int hashCode();
+
+    public void setCapability(String type);
+    public String getCapability();
+
+    public void setQueryUri(String id);
+    public String getQueryUri();
+
+    public void setFormats(String[] formats);
+    public String[] getFormats();
+
+    /** checks if this capability is actually of das1 style
+     *
+     * @return boolean true if the capability is in DAS1 style
+     */
+    public boolean isDas1Style();
+
+}
diff --git a/src/jalview/biojava/dasobert/das2/Das2CapabilityImpl.java b/src/jalview/biojava/dasobert/das2/Das2CapabilityImpl.java
new file mode 100644 (file)
index 0000000..507a2d3
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 9, 2006
+ *
+ */
+package org.biojava.dasobert.das2;
+
+public class Das2CapabilityImpl
+implements Das2Capability{
+
+    String capability;
+    String[] formats;
+    String queryId;
+
+    public static String DAS1_CAPABILITY_PREFIX = "das1:";
+
+    public Das2CapabilityImpl() {
+        super();
+        capability = "undef";
+        queryId = "";
+        formats = new String[0];
+
+    }
+
+    public boolean isDas1Style(){
+
+        if ( capability == null)
+            return false;
+        if ( capability.length() < DAS1_CAPABILITY_PREFIX.length())
+            return false;
+        if ( capability.substring(0,DAS1_CAPABILITY_PREFIX.length()).equals(DAS1_CAPABILITY_PREFIX))
+            return true;
+        return false;
+
+    }
+
+    public boolean equals(Das2Capability other){
+
+        boolean status = true;
+
+        if (!  capability.equals(other.getCapability()))
+            status = false;
+        if ( ! queryId.equals(other.getQueryUri()))
+            status = false;
+
+        return status;
+    }
+
+    public int hashCode(){
+        int h = 7;
+        h = 31 * h + ( null == capability ? 0 : capability.hashCode()) ;
+        h = 31 * h + ( null == queryId    ? 0 : queryId.hashCode()) ;
+
+        return h;
+    }
+
+    public String toString(){
+        String txt ="capability " + capability + " queryId " + queryId;
+        return txt;
+    }
+
+    public String getCapability() {
+
+        return capability;
+    }
+
+    public String[] getFormats() {
+        return formats;
+    }
+
+    public String getQueryUri() {
+        return queryId;
+    }
+
+    public void setCapability(String type) {
+       capability = type;
+
+    }
+
+    public void setFormats(String[] formats) {
+
+        this.formats = formats;
+    }
+
+    public void setQueryUri(String id) {
+       queryId = id;
+
+    }
+
+
+
+}
diff --git a/src/jalview/biojava/dasobert/das2/Das2Source.java b/src/jalview/biojava/dasobert/das2/Das2Source.java
new file mode 100644 (file)
index 0000000..c370de9
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 9, 2006
+ *
+ */
+package org.biojava.dasobert.das2;
+
+import org.biojava.dasobert.dasregistry.DasSource;
+
+public interface Das2Source
+extends DasSource {
+
+   public Das2Capability[] getDas2Capabilities();
+   public void setDas2Capabilities(Das2Capability[] capabilities);
+
+   /** test if this is a DAS1 source represented as a DAS2 source
+    *  if true - this source can be converted into a DAS1 source by using
+    *  DasSourceConverter.toDas1(Das2Source);
+    *
+    * @return true if the DasSource has DAS1 capabilties
+    */
+   public boolean hasDas1Capabilities();
+}
diff --git a/src/jalview/biojava/dasobert/das2/Das2SourceImpl.java b/src/jalview/biojava/dasobert/das2/Das2SourceImpl.java
new file mode 100644 (file)
index 0000000..bb5325d
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 9, 2006
+ *
+ */
+package org.biojava.dasobert.das2;
+
+import org.biojava.dasobert.dasregistry.Das1Source;
+import org.biojava.dasobert.dasregistry.DasSource;
+
+public class Das2SourceImpl
+extends Das1Source
+implements Das2Source
+
+{
+
+    Das2Capability[] capabilities;
+
+    public Das2SourceImpl() {
+        super();
+
+        capabilities = new Das2Capability[0];
+    }
+
+
+    /**  compare if two DasSources are identical
+     *
+     */
+    public boolean equals(DasSource other){
+
+        if ( this == other)
+            return true;
+
+        if ( ( other == null) || (other.getClass() != this.getClass()))
+            return false;
+
+        // to compare if two Das2Sources are identical we do the following:
+        //  we check the capabilities
+
+        Das2SourceImpl d2o = (Das2SourceImpl)other;
+
+        if ( nickname.equals(d2o.getNickname()))
+            return true;
+
+        Das2Capability[] othercaps = d2o.getDas2Capabilities();
+
+        if ( ! (capabilities.length == othercaps.length))
+            return false;
+
+        for ( int x=0;x<capabilities.length;x++){
+            Das2Capability tmpcap = capabilities[x];
+            boolean foundCap = false;
+            for (int y=0; y< othercaps.length;y++){
+                Das2Capability tmpcapo = othercaps[y];
+                if ( tmpcap.equals(tmpcapo))
+                    foundCap = true;
+            }
+            if ( ! foundCap)
+                return false;
+        }
+
+
+        //TODO?
+        // should we add a check for coordinate systems?
+        // but we already check for the endpoints, that should be enough...
+
+        return true;
+
+    }
+
+    public int hashCode(){
+        int h = 7 ;
+
+        h = 31 * h + (null == nickname ? 0 :  nickname.hashCode());
+
+        for ( int x=0;x<capabilities.length;x++){
+            Das2Capability cap = capabilities[x];
+            h = 31 * h + cap.hashCode();
+        }
+
+        return h;
+    }
+
+
+    public boolean hasDas1Capabilities(){
+
+        // test if any of the capabilities is a das1 capabilitiy
+
+        for (int i = 0 ; i < capabilities.length; i++) {
+            Das2Capability cap = capabilities[i];
+            if ( cap.isDas1Style())
+                return true;
+        }
+        return false;
+
+
+    }
+
+    public String[] getCapabilities() {
+        //todo mark as not needed / not appropriate ...
+        return super.getCapabilities();
+    }
+
+
+
+    public void setCapabilities(String[] u) {
+        // TODO Auto-generated method stub
+        super.setCapabilities(u);
+    }
+
+
+
+    public Das2Capability[] getDas2Capabilities() {
+        // TODO Auto-generated method stub
+        return capabilities;
+    }
+
+    public void setDas2Capabilities(Das2Capability[] capabilities) {
+        // TODO Auto-generated method stub
+        this.capabilities = capabilities;
+
+    }
+
+
+
+
+}
diff --git a/src/jalview/biojava/dasobert/das2/DasSourceConverter.java b/src/jalview/biojava/dasobert/das2/DasSourceConverter.java
new file mode 100644 (file)
index 0000000..513ba3f
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Mar 23, 2006
+ *
+ */
+package org.biojava.dasobert.das2;
+
+//import org.biojava.bio.program.das.dasalignment.DASException;
+import org.biojava.dasobert.dasregistry.Das1Source;
+
+public class DasSourceConverter {
+
+    public DasSourceConverter() {
+        super();
+
+    }
+
+
+    /** convert a das2 source to a das 1 source.
+     * This only will work if is passes the Das2Source.isDas1Source() test
+     * i.e. this is really a das1 server there
+     *
+     * @param das2source a DAS2Source to be converted
+     * @return a Das1Source
+     * @throws DASException
+     */
+    public static Das1Source toDas1Source (Das2Source das2source) throws Exception{
+        if ( ! das2source.hasDas1Capabilities())
+            throw new Exception("this das source does not have das1 capabilitites");
+
+        Das1Source ds = new Das1Source();
+        ds.setAdminemail(das2source.getAdminemail());
+        ds.setDescription(das2source.getDescription());
+        ds.setHelperurl(das2source.getHelperurl());
+        ds.setRegisterDate(das2source.getRegisterDate());
+        ds.setLeaseDate(das2source.getLeaseDate());
+        ds.setLabels(das2source.getLabels());
+        ds.setCoordinateSystem(das2source.getCoordinateSystem());
+        ds.setNickname(das2source.getNickname());
+        ds.setId(das2source.getId());
+        ds.setLabels(das2source.getLabels());
+
+        // convert the capabilitites to das1 capabiltities and get the url
+        Das2Capability[] caps = das2source.getDas2Capabilities();
+        String[] das1capabilitites = new String[caps.length];
+        int DASPREFIXLENGTH = Das2CapabilityImpl.DAS1_CAPABILITY_PREFIX.length();
+
+        for ( int i = 0 ; i< caps.length;i++){
+            Das2Capability cap = caps[i];
+
+            String c = cap.getCapability();
+
+            das1capabilitites[i] = c.substring(DASPREFIXLENGTH,c.length());
+
+            String query_uri = cap.getQueryUri();
+
+            String url = query_uri.substring(0,(query_uri.length() - c.length() + DASPREFIXLENGTH));
+            ds.setUrl(url);
+        }
+        ds.setCapabilities(das1capabilitites);
+
+        return ds ;
+    }
+
+}
diff --git a/src/jalview/biojava/dasobert/das2/io/DAS2SourceHandler.java b/src/jalview/biojava/dasobert/das2/io/DAS2SourceHandler.java
new file mode 100755 (executable)
index 0000000..a9c0af3
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Mar 15, 2006
+ *
+ */
+package org.biojava.dasobert.das2.io;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.biojava.dasobert.das2.Das2Capability;
+import org.biojava.dasobert.das2.Das2CapabilityImpl;
+import org.biojava.dasobert.das2.Das2Source;
+import org.biojava.dasobert.das2.Das2SourceImpl;
+import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
+import org.biojava.dasobert.dasregistry.DasSource;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+/** a parser for the DAS2 sources response
+ *
+ * @author Andreas Prlic
+ * @since 6:53:45 PM
+ * @version %I% %G%
+ */
+public class DAS2SourceHandler extends DefaultHandler{
+
+    List sources;
+    Das2Source currentSource;
+    List coordinates;
+    List capabilities;
+    List labels;
+
+    public static final String LABELPROPERTY = "label";
+
+    public DAS2SourceHandler() {
+        super();
+
+        sources       = new ArrayList();
+        currentSource = new Das2SourceImpl();
+        coordinates   = new ArrayList();
+        capabilities  = new ArrayList();
+       labels        = new ArrayList();
+    }
+
+    private void startSource (String uri, String name, String qName, Attributes atts){
+
+        String id = atts.getValue("uri");
+        String title = atts.getValue("title");
+        String doc_ref = atts.getValue("doc_href");
+        String description = atts.getValue("description");
+
+
+        currentSource.setId(id);
+        currentSource.setNickname(title);
+        currentSource.setHelperurl(doc_ref);
+        currentSource.setDescription(description);
+
+    }
+
+    private DasCoordinateSystem getCoordinateSystem(String uri, String name, String qname, Attributes atts){
+        // e.g. uri="http://das.sanger.ac.uk/dasregistry/coordsys/CS_LOCAL6"
+        // source="Protein Sequence" authority="UniProt" test_range="P06213" />
+        DasCoordinateSystem dcs = new DasCoordinateSystem();
+        String id = atts.getValue("uri");
+        dcs.setUniqueId(id);
+
+        String source = atts.getValue("source");
+        dcs.setCategory(source);
+
+        String authority = atts.getValue("authority");
+        dcs.setName(authority);
+
+        String test_range = atts.getValue("test_range");
+        dcs.setTestCode(test_range);
+
+        try {
+            String taxidstr = atts.getValue("taxid");
+            int taxid = Integer.parseInt(taxidstr);
+            dcs.setNCBITaxId(taxid);
+        } catch (Exception e){}
+
+        String version = atts.getValue("version");
+        if ( version != null)
+            dcs.setVersion(version);
+
+        return dcs;
+    }
+
+    public void startElement (String uri, String name, String qName, Attributes atts){
+        //System.out.println("new element "+qName);
+
+        if (qName.equals("SOURCE")) {
+            //System.out.println("new Source " + atts.getValue(uri));
+            currentSource = new Das2SourceImpl();
+            coordinates = new ArrayList();
+            capabilities = new ArrayList();
+
+            startSource(uri,name, qName, atts);
+
+        } else if ( qName.equals("MAINTAINER")){
+            String email = atts.getValue("email");
+            currentSource.setAdminemail(email);
+        } else if ( qName.equals("COORDINATES")){
+            DasCoordinateSystem dcs = getCoordinateSystem(uri,name,qName,atts);
+            coordinates.add(dcs);
+
+        } else if ( qName.equals("CAPABILITY")){
+            Das2Capability cap = getCapability(uri,name,qName,atts);
+            capabilities.add(cap);
+        } else if (qName.equals("PROPERTY")) {
+           addProperty(uri,name,qName,atts);
+       }
+    }
+
+    private Das2Capability getCapability(String uri, String name, String qName, Attributes atts){
+        // e.g <CAPABILITY type="features" query_id="http://das.biopackages.net/das/genome/yeast/S228C/feature" />
+        Das2Capability cap = new Das2CapabilityImpl();
+
+        String type = atts.getValue("type");
+        cap.setCapability(type);
+        String query_uri = atts.getValue("query_uri");
+        cap.setQueryUri(query_uri);
+        return cap;
+
+    }
+
+    private void addProperty(String uri, String name, String qName, Attributes atts){
+       String pname = atts.getValue("name");
+       String label = atts.getValue("value");
+       if ( pname.equals(LABELPROPERTY) )
+           labels.add(label);
+    }
+
+    public void startDocument(){
+        sources = new ArrayList();
+        coordinates = new ArrayList();
+        capabilities = new ArrayList();
+    }
+
+    public void endElement(String uri, String name, String qName) {
+        if ( qName.equals("SOURCE")) {
+            currentSource.setDas2Capabilities((Das2Capability[])capabilities.toArray(new Das2Capability[capabilities.size()]));
+            //System.out.println("got coordinates " + coordinates.size());
+            currentSource.setCoordinateSystem((DasCoordinateSystem[])coordinates.toArray(new DasCoordinateSystem[coordinates.size()]));
+
+           currentSource.setLabels((String[])labels.toArray(new String[labels.size()]));
+           labels.clear();
+
+            //System.out.println("Das2SourceHandler endElement name " + name + " uri " + uri + " qName " + qName);
+            //System.out.println("Das2SourceHandler adding to source: " + currentSource.getId());
+            sources.add(currentSource);
+            currentSource = new Das2SourceImpl();
+        }
+    }
+
+    public DasSource[] getSources(){
+        //System.out.println("Das2SourceHandler: source size: " + sources.size());
+        return (DasSource[])sources.toArray(new DasSource[sources.size()]);
+    }
+
+
+
+}
diff --git a/src/jalview/biojava/dasobert/das2/io/DasSourceReader.java b/src/jalview/biojava/dasobert/das2/io/DasSourceReader.java
new file mode 100644 (file)
index 0000000..8044fb7
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 24, 2006
+ *
+ */
+package org.biojava.dasobert.das2.io;
+
+import java.io.InputStream;
+
+import org.biojava.dasobert.dasregistry.DasSource;
+
+public interface DasSourceReader {
+
+    public DasSource[] readDasSource(InputStream stream);
+}
diff --git a/src/jalview/biojava/dasobert/das2/io/DasSourceReaderImpl.java b/src/jalview/biojava/dasobert/das2/io/DasSourceReaderImpl.java
new file mode 100644 (file)
index 0000000..3f0a07a
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 24, 2006
+ *
+ */
+package org.biojava.dasobert.das2.io;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+//import org.biojava.dasobert.das.AlignmentThread;
+import org.biojava.dasobert.das.DAS_FeatureRetrieve;
+import org.biojava.dasobert.dasregistry.DasSource;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.XMLReader;
+
+public class DasSourceReaderImpl implements DasSourceReader {
+
+    Exception loggedException;
+
+    public DasSourceReaderImpl() {
+        super();
+        loggedException = null;
+
+        // open the stream to a server and then parse the result ...
+    }
+
+    private InputStream open(URL url)
+    throws java.io.IOException, java.net.ConnectException
+    {
+        InputStream inStream = null;
+
+
+        HttpURLConnection huc = DAS_FeatureRetrieve.openHttpURLConnection(url);
+
+        inStream = huc.getInputStream();
+
+        return inStream;
+
+    }
+
+
+    public DasSource[] readDasSource(URL url){
+        DasSource[] sources = new DasSource[0];
+
+        try {
+            InputStream stream = open(url);
+
+            sources = readDasSource(stream);
+        } catch (Exception e){
+            e.printStackTrace();
+            loggedException = e;
+        }
+        return sources;
+    }
+
+    /** read a DAS2 sources response and return a list of DAS sources.
+     *
+     */
+    public DasSource[] readDasSource(InputStream stream)  {
+
+        DasSource[] sources = new DasSource[0];
+
+        try {
+        SAXParserFactory spfactory =
+            SAXParserFactory.newInstance();
+
+        spfactory.setValidating(false);
+
+        SAXParser saxParser = null ;
+
+        try{
+            saxParser =
+                spfactory.newSAXParser();
+        } catch (ParserConfigurationException e) {
+            e.printStackTrace();
+            loggedException = e;
+        }
+
+        String vali = System.getProperty("XMLVALIDATION");
+
+        boolean validation = false ;
+        if ( vali != null )
+            if ( vali.equals("true") )
+                validation = true ;
+
+
+        XMLReader xmlreader = saxParser.getXMLReader();
+
+        //XMLReader xmlreader = XMLReaderFactory.createXMLReader();
+        try {
+            xmlreader.setFeature("http://xml.org/sax/features/validation", 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){
+            e.printStackTrace();
+            //logger.log(Level.FINE,"Cannot set load-external-dtd "+validation);
+
+        }
+
+        DAS2SourceHandler cont_handle = new DAS2SourceHandler() ;
+
+        xmlreader.setContentHandler(cont_handle);
+        xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
+        InputSource insource = new InputSource() ;
+        insource.setByteStream(stream);
+
+
+        xmlreader.parse(insource);
+        sources = cont_handle.getSources();
+
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            loggedException = e;
+        }
+        return sources;
+    }
+
+    public Exception getLoggedException(){
+        return loggedException;
+    }
+
+    public static void main (String[] args){
+        String url = "http://www.spice-3d.org/dasregistry/das2/sources/";
+        DasSourceReaderImpl reader = new DasSourceReaderImpl();
+        try {
+            URL u = new URL(url);
+            DasSource[] sources = reader.readDasSource(u);
+            for (int i=0; i< sources.length;i++){
+                DasSource ds = sources[i];
+                System.out.println(ds.toString());
+            }
+
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+
+    }
+
+
+
+}
diff --git a/src/jalview/biojava/dasobert/dasregistry/Das1Source.java b/src/jalview/biojava/dasobert/dasregistry/Das1Source.java
new file mode 100644 (file)
index 0000000..de007d6
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 15.04.2004
+ * @author Andreas Prlic
+ *
+ */
+package org.biojava.dasobert.dasregistry;
+
+import java.util.Date ;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+
+//import org.biojava.dasobert.das2.io.DasSourceWriter;
+//import org.biojava.dasobert.das2.io.DasSourceWriterImpl;
+//import org.biojava.utils.xml.PrettyXMLWriter;
+
+
+/** a simple Bean class to be returned via SOAP
+ * @author Andreas Prlic
+ */
+
+public class Das1Source implements DasSource {
+    String url                ;
+    protected String nickname           ;
+    String adminemail         ;
+    String description        ;
+    DasCoordinateSystem[] coordinateSystem ;
+    String[] capabilities     ;
+    String[] labels           ;
+    String helperurl          ;
+    Date   registerDate       ;
+    Date   leaseDate          ;
+    String id                 ;
+    boolean local;
+
+    boolean alertAdmin;
+
+    public static String EMPTY_ID = "UNK:-1" ;
+
+    public Das1Source () {
+        id               = EMPTY_ID;
+        url              = "";
+        adminemail       = "" ;
+        description      = "" ;
+        //String empty     = "" ;
+        nickname         = "" ;
+        coordinateSystem = new DasCoordinateSystem[0];
+        //coordinateSystem[0] = new DasCoordinateSystem();
+        capabilities     =  new String[0];
+        labels                  = new String[0];
+        //capabilities[0]  = empty ;
+        registerDate     = new Date() ;
+        leaseDate        = new Date() ;
+        helperurl        = "";
+        local=true;
+    }
+
+
+    public boolean equals(DasSource other){
+        System.out.println("Das1Source equals, comparing with other DasSource");
+        if (! (other instanceof Das1Source))
+            return false;
+
+        Das1Source ods = (Das1Source) other;
+
+        if ( ods.getUrl().equals(url))
+            return true;
+        if ( ods.getNickname().equals(nickname))
+            return true;
+        return false;
+    }
+
+    public int hashCode() {
+        int h = 7;
+
+        h = 31 * h + ( null == nickname ? 0 : nickname.hashCode());
+        h = 31 * h + ( null == url ? 0 : url.hashCode());
+
+        return h;
+    }
+
+    /** the DAS2 string representation of this DAS source
+     *
+    public String toString() {
+
+        StringWriter writer = new StringWriter();
+
+        PrintWriter pw = new PrintWriter(writer);
+        PrettyXMLWriter xw = new PrettyXMLWriter(pw);
+
+        DasSourceWriter dswriter = new DasSourceWriterImpl();
+        try {
+            dswriter.writeDasSource(xw,this);
+        } catch (IOException e){
+            e.printStackTrace();
+        }
+
+        return writer.toString();
+
+    }
+    */
+    public void setLocal(boolean flag){ local = flag;}
+    public boolean isLocal(){return local;}
+
+    public void setId(String i) { id = i; }
+
+    /** get a the Id of the DasSource. The Id is a unique db
+     * identifier. The public DAS-Registry has Auto_Ids that look like
+     * DASSOURCE:12345; public look like XYZ:12345, where the XYZ
+     * prefix can be configured in the config file.
+     */
+    public String getId() { return id;}
+
+    public void setNickname(String name) {
+        nickname = name ;
+    }
+    public String getNickname(){
+        return nickname;
+    }
+    public void setUrl(String u) {
+        char lastChar = u.charAt(u.length()-1);
+        if ( lastChar  != '/')
+            u += "/";
+
+        url = u ;
+    }
+
+    public void setAdminemail (String u) {
+        adminemail = u ;
+    }
+
+    public void setDescription (String u) {
+        description = u;
+    }
+
+    public void setCoordinateSystem (DasCoordinateSystem[] u){
+        coordinateSystem=u ;
+    }
+
+    public void setCapabilities (String[] u){
+        capabilities = u ;
+    }
+
+    public String getUrl(){return url;}
+    public String getAdminemail(){return adminemail;}
+    public String getDescription(){return description;}
+    public String[] getCapabilities(){return capabilities;}
+    public DasCoordinateSystem[] getCoordinateSystem(){return coordinateSystem;}
+
+    public void setRegisterDate(Date d) {
+        registerDate = d;
+    }
+    public Date getRegisterDate() {
+        return registerDate ;
+    }
+    public void setLeaseDate(Date d) {
+        leaseDate =d ;
+    }
+    public Date getLeaseDate() {
+        return leaseDate ;
+    }
+
+    public void setLabels(String[] ls) {
+        labels = ls ;
+    }
+
+    public String[] getLabels() {
+        return labels;
+    }
+
+    public void setHelperurl(String url) {
+        helperurl = url;
+    }
+
+    public String getHelperurl() {
+        return helperurl;
+    }
+
+    public void setAlertAdmin(boolean flag) {
+        alertAdmin = flag;
+    }
+
+    public boolean getAlertAdmin() {
+        return alertAdmin;
+    }
+
+}
diff --git a/src/jalview/biojava/dasobert/dasregistry/Das2Validator.java b/src/jalview/biojava/dasobert/dasregistry/Das2Validator.java
new file mode 100755 (executable)
index 0000000..48cb4f0
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Mar 20, 2006
+ *
+ */
+package org.biojava.dasobert.dasregistry;
+
+import org.biojava.dasobert.das2.Das2Source;
+
+public class Das2Validator {
+
+    public Das2Validator() {
+        super();
+
+    }
+
+    public boolean validate(Das2Source ds){
+
+        // TODO this bit still needs to be implemented!
+
+        return true;
+    }
+
+
+
+}
diff --git a/src/jalview/biojava/dasobert/dasregistry/DasCoordSysComparator.java b/src/jalview/biojava/dasobert/dasregistry/DasCoordSysComparator.java
new file mode 100644 (file)
index 0000000..621fbc8
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 15.04.2004
+ * @author Andreas Prlic
+ *
+ */
+
+
+package org.biojava.dasobert.dasregistry ;
+
+import java.util.Comparator ;
+import java.util.Map ;
+import java.util.HashMap ;
+
+import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
+
+/** a comparator to sort DasSources
+ * @author Andreas Prlic
+ */
+
+
+public abstract class DasCoordSysComparator
+    implements Comparator
+{
+
+    private final String name ;
+    private static final Map COMPS_BY_NAME;
+
+
+    public DasCoordSysComparator(String str) {
+       //System.out.println("new dasSourceComparator " + str);
+       name = str ;
+    }
+
+    public static final Comparator BY_NAME = new DasCoordSysComparator("name") {
+        protected Comparable getField(DasCoordinateSystem ds) {
+            return ds.getName();
+        }
+    };
+
+    public static final Comparator BY_ID = new DasCoordSysComparator("id") {
+        protected Comparable getField(DasCoordinateSystem ds) {
+            return ds.getUniqueId();
+        }
+    };
+    public static final Comparator BY_CATEGORY = new DasCoordSysComparator("category") {
+        protected Comparable getField(DasCoordinateSystem ds) {
+            return ds.getCategory();
+        }
+    };
+    public static final Comparator BY_ORGANISM = new DasCoordSysComparator("organism") {
+        protected Comparable getField(DasCoordinateSystem ds) {
+            return ds.getOrganismName();
+        }
+    };
+    public static final Comparator BY_TAXID = new DasCoordSysComparator("taxid") {
+        protected Comparable getField(DasCoordinateSystem ds) {
+            return ds.getNCBITaxId()+"";
+        }
+    };
+
+
+
+    static {
+        COMPS_BY_NAME = new HashMap();
+        COMPS_BY_NAME.put(BY_ID.toString(),           BY_ID);
+       COMPS_BY_NAME.put(BY_NAME.toString(),         BY_NAME);
+        COMPS_BY_NAME.put(BY_CATEGORY.toString(),     BY_CATEGORY);
+        COMPS_BY_NAME.put(BY_ORGANISM.toString(),     BY_ORGANISM);
+        COMPS_BY_NAME.put(BY_TAXID.toString(),        BY_TAXID);
+    }
+
+
+
+    public static Comparator fromString(String name) {
+        if (COMPS_BY_NAME.containsKey(name)) {
+            return (Comparator) COMPS_BY_NAME.get(name);
+        } else {
+            throw new IllegalArgumentException("Can't compare by key " + name);
+        }
+    }
+
+    protected abstract Comparable getField(DasCoordinateSystem ds);
+
+    /** compare two DasCoordSys objects */
+    public int compare( Object a, Object b) {
+        DasCoordinateSystem x = (DasCoordinateSystem) a ;
+        DasCoordinateSystem y = (DasCoordinateSystem) b ;
+        return getField(x).compareTo(getField(y));
+    }
+
+    public String toString() {
+        return name;
+    }
+
+
+}
+
+
diff --git a/src/jalview/biojava/dasobert/dasregistry/DasCoordinateSystem.java b/src/jalview/biojava/dasobert/dasregistry/DasCoordinateSystem.java
new file mode 100644 (file)
index 0000000..8fc4ccb
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 15.04.2004
+ * @author Andreas Prlic
+ *
+ */
+package org.biojava.dasobert.dasregistry;
+
+
+/** a Bean to be returned via SOAP. It takes care of the DAS -  coordinate Systems
+ * @author Andreas Prlic
+ */
+public class DasCoordinateSystem {
+
+    String name;
+    String category;
+    String organism_name;
+    int ncbi_tax_id ;
+    String uniqueId ;
+    String version;
+    String testCode;
+
+    public DasCoordinateSystem () {
+        uniqueId = "";
+        name = "";
+        category ="";
+        organism_name = "";
+        ncbi_tax_id = 0;
+        version = "";
+        testCode = "";
+    }
+
+    public boolean equals(DasCoordinateSystem other){
+        boolean match = true;
+        System.out.println("comparing " + this.toString() + " to " + other.toString());
+        // URI has piority
+        if ( (! uniqueId.equals("")) && ( uniqueId.equals( other.getUniqueId())))
+            return true;
+
+        if ( ncbi_tax_id != other.getNCBITaxId()) {
+            System.out.println("mismatch in ncbi tax id " + ncbi_tax_id + " != " + other.getNCBITaxId());
+            match = false;
+        }
+        if ( ! version.equals(other.getVersion() )){
+            System.out.println("mismatch in version");
+            match = false;
+        }
+        if ( ! category.equals(other.getCategory())  ) {
+            System.out.println("mismatch in category");
+            match = false;
+        }
+        if ( ! name.equals(other.getName())) {
+            System.out.println("mismatch in name");
+            match = false;
+        }
+        System.out.println(" match: " + match);
+
+        return match;
+    }
+
+    public Object clone() {
+        DasCoordinateSystem d = new DasCoordinateSystem();
+        d.setTestCode(testCode);
+        d.setCategory(category);
+        d.setName(name);
+        d.setNCBITaxId(ncbi_tax_id);
+        d.setUniqueId(getUniqueId());
+        d.setOrganismName(getOrganismName());
+        d.setVersion(getVersion());
+        return d;
+    }
+
+    public String getTestCode() {
+        return testCode;
+    }
+
+
+
+    public void setTestCode(String testCode) {
+        if ( testCode == null)
+            testCode = "";
+        this.testCode = testCode;
+    }
+
+
+
+    public void setUniqueId(String id) { uniqueId = id ;   }
+    public String getUniqueId() { return uniqueId;         }
+
+    public void setName(String n) { name = n; }
+    public String getName() { return name; }
+
+    public void setCategory(String c) { category = c;}
+    public String getCategory() { return category;}
+
+    public void setOrganismName(String t) { organism_name  =t;}
+    public String getOrganismName() { return organism_name;}
+
+    public void setNCBITaxId(int id) { ncbi_tax_id = id;}
+    public int getNCBITaxId(){ return ncbi_tax_id ;}
+
+
+
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        if ( version == null)
+            version = "";
+        this.version = version;
+    }
+
+    public String toString() {
+        String nam = name;
+        if ( ! version.equals(""))
+            nam += "_" + version;
+
+       if ( organism_name.equals("") )
+           return nam+","+category ;
+       else
+           return nam+","+category+"," + organism_name ;
+    }
+
+    public static DasCoordinateSystem fromString(String rawString) {
+       String[] spl = rawString.split(",");
+       DasCoordinateSystem dcs = new DasCoordinateSystem();
+       if ( spl.length == 2 ) {
+           dcs.setName(spl[0]);
+           dcs.setCategory(spl[1]);
+       }
+       if ( spl.length == 3 ) {
+           dcs.setName(spl[0]);
+           dcs.setCategory(spl[1]);
+           dcs.setOrganismName(spl[2]);
+       }
+       return dcs;
+    }
+
+
+}
diff --git a/src/jalview/biojava/dasobert/dasregistry/DasSource.java b/src/jalview/biojava/dasobert/dasregistry/DasSource.java
new file mode 100644 (file)
index 0000000..6dd49e5
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Feb 8, 2006
+ *
+ */
+package org.biojava.dasobert.dasregistry;
+
+import java.util.Date;
+
+public interface DasSource {
+
+    public  void setLocal(boolean flag);
+
+    public  boolean isLocal();
+
+    /** compare if two das sources are equal
+     *
+     * @param ds
+     * @return returns true if two DAS sources are equivalent
+     */
+    public boolean equals(DasSource ds);
+
+    /** classes that implement equals, should also implement hashKey
+     *
+     * @return the hash code of a das source
+     */
+    public int hashCode();
+
+
+    public  void setId(String i);
+
+    /** get a the Id of the DasSource. The Id is a unique db
+     * identifier. The public DAS-Registry has Auto_Ids that look like
+     * DASSOURCE:12345; public look like XYZ:12345, where the XYZ
+     * prefix can be configured in the config file.
+     * @return String the ID of a Das Source
+     */
+    public  String getId();
+
+    public  void setNickname(String name);
+
+    public  String getNickname();
+
+    public  void setUrl(String u);
+
+    public  void setAdminemail(String u);
+
+    public  void setDescription(String u);
+
+    public  void setCoordinateSystem(DasCoordinateSystem[] u);
+
+    public  void setCapabilities(String[] u);
+
+    public  String getUrl();
+
+    public  String getAdminemail();
+
+    public  String getDescription();
+
+    public  String[] getCapabilities();
+
+    public  DasCoordinateSystem[] getCoordinateSystem();
+
+    public  void setRegisterDate(Date d);
+
+    public  Date getRegisterDate();
+
+    public  void setLeaseDate(Date d);
+
+    public  Date getLeaseDate();
+
+    public  void setLabels(String[] ls);
+
+    public  String[] getLabels();
+
+    public  void setHelperurl(String url);
+
+    public  String getHelperurl();
+
+    // TestCode is now part of the coordinate system!
+    //public  void setTestCode(String code);
+    //public  String getTestCode();
+
+    public  void setAlertAdmin(boolean flag);
+
+    public  boolean getAlertAdmin();
+
+}
diff --git a/src/jalview/biojava/dasobert/dasregistry/DasSourceComparator.java b/src/jalview/biojava/dasobert/dasregistry/DasSourceComparator.java
new file mode 100644 (file)
index 0000000..ddbad1a
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ *                    BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on 15.04.2004
+ * @author Andreas Prlic
+ *
+ */
+
+
+package org.biojava.dasobert.dasregistry ;
+
+import java.util.Comparator ;
+import java.util.Map ;
+import java.util.HashMap ;
+
+
+/** a comparator to sort DasSources
+ * @author Andreas Prlic, Thomas Down
+ */
+
+
+public abstract class DasSourceComparator
+    implements Comparator
+{
+
+    private final String name ;
+    private static final Map COMPS_BY_NAME;
+
+
+    public DasSourceComparator(String str) {
+       //System.out.println("new dasSourceComparator " + str);
+       name = str ;
+    }
+
+    public static final Comparator BY_ID = new DasSourceComparator("id") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getId();
+        }
+    };
+
+    public static final Comparator BY_NICKNAME = new DasSourceComparator("nickname") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getNickname();
+        }
+    };
+    public static final Comparator BY_REGISTER_DATE = new DasSourceComparator("registerdate") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getRegisterDate();
+        }
+    };
+    public static final Comparator BY_LEASE_DATE = new DasSourceComparator("leasedate") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getLeaseDate();
+        }
+    };
+    public static final Comparator BY_URL = new DasSourceComparator("url") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getUrl();
+        }
+    };
+    public static final Comparator BY_ADMIN_EMAIL = new DasSourceComparator("adminemail") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getAdminemail();
+        }
+    };
+    public static final Comparator BY_DESCRIPTION = new DasSourceComparator("description") {
+        protected Comparable getField(DasSource ds) {
+            return ds.getDescription();
+        }
+    };
+    public static final Comparator BY_CAPABILITIES = new DasSourceComparator("capabilities") {
+        protected Comparable getField(DasSource ds) {
+            String[] caps = ds.getCapabilities();
+            return caps.length == 0 ? "" : caps[0];
+        }
+    };
+    public static final Comparator BY_COORDINATE_SYSTEM = new DasSourceComparator("coordinateSystem") {
+        protected Comparable getField(DasSource ds) {
+            DasCoordinateSystem[] dcss = ds.getCoordinateSystem();
+            return dcss.length == 0 ? "" : dcss[0].toString();
+        }
+    };
+
+    static {
+        COMPS_BY_NAME = new HashMap();
+        COMPS_BY_NAME.put(BY_ID.toString(),                BY_ID);
+        COMPS_BY_NAME.put(BY_NICKNAME.toString(),          BY_NICKNAME);
+        COMPS_BY_NAME.put(BY_REGISTER_DATE.toString(),     BY_REGISTER_DATE);
+        COMPS_BY_NAME.put(BY_LEASE_DATE.toString(),        BY_LEASE_DATE);
+        COMPS_BY_NAME.put(BY_URL.toString(),               BY_URL);
+        COMPS_BY_NAME.put(BY_ADMIN_EMAIL.toString(),       BY_ADMIN_EMAIL);
+        COMPS_BY_NAME.put(BY_DESCRIPTION.toString(),       BY_DESCRIPTION);
+        COMPS_BY_NAME.put(BY_CAPABILITIES.toString(),      BY_CAPABILITIES);
+        COMPS_BY_NAME.put(BY_COORDINATE_SYSTEM.toString(), BY_COORDINATE_SYSTEM);
+    }
+
+
+
+    public static Comparator fromString(String name) {
+        if (COMPS_BY_NAME.containsKey(name)) {
+            return (Comparator) COMPS_BY_NAME.get(name);
+        } else {
+            throw new IllegalArgumentException("Can't compare by key " + name);
+        }
+    }
+
+    protected abstract Comparable getField(DasSource ds);
+
+    /** compare two DasSource objects */
+    public int compare( Object a, Object b) {
+
+        DasSource x = (DasSource) a ;
+        DasSource y = (DasSource) b ;
+        return getField(x).compareTo(getField(y));
+    }
+
+    public String toString() {
+        return name;
+    }
+
+
+}
+
+
diff --git a/src/jalview/biojava/dasobert/eventmodel/FeatureEvent.java b/src/jalview/biojava/dasobert/eventmodel/FeatureEvent.java
new file mode 100644 (file)
index 0000000..63b5da4
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Oct 28, 2005
+ *
+ */
+package org.biojava.dasobert.eventmodel;
+
+import java.util.Map;
+
+import org.biojava.dasobert.dasregistry.Das1Source;
+public class FeatureEvent {
+
+    Map[] features;
+    Das1Source dasSource;
+    int comeBackLater;
+
+    public FeatureEvent(Map[] features,Das1Source dasSource) {
+        super();
+        this.features =features;
+        this.dasSource = dasSource;
+        comeBackLater = -1;
+    }
+
+    public int getComeBackLater(){
+        return comeBackLater;
+    }
+
+    public void setComeBackLater(int comeBackLater){
+        this.comeBackLater = comeBackLater;
+    }
+
+
+    /** get the features that have been found.
+     *
+     * do something like
+     * Map[] features = event.getFeatures();
+     * <pre>
+     * for (int i = 0 ; i< features;i++) {
+     *      Map f = features[i];
+     *      String type = (String) f.get("TYPE") ;
+     *      System.out.println(type);
+     * }
+     * </pre>
+     * @return a Map containng the features
+     */
+    public Map[] getFeatures(){
+        return features;
+    }
+
+    public Das1Source getDasSource(){
+        return dasSource;
+    }
+
+}
+
diff --git a/src/jalview/biojava/dasobert/eventmodel/FeatureListener.java b/src/jalview/biojava/dasobert/eventmodel/FeatureListener.java
new file mode 100644 (file)
index 0000000..299a6bf
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Oct 28, 2005
+ *
+ */
+package org.biojava.dasobert.eventmodel;
+
+//import org.biojava.spice.multipanel.eventmodel.FeatureEvent;
+
+/**  a feature listener that returns the raw features as returned by a DAS source.
+ *
+ */
+public interface FeatureListener {
+
+    /** new features have been returned from the Annotation server
+     *
+     * @param e
+     */
+    public void newFeatures(FeatureEvent e);
+
+    /** the server says that he is busy and we should try again in x seconds
+     *
+     * @param e
+     */
+    public void comeBackLater(FeatureEvent e);
+
+}
+
+
+
+
+
diff --git a/src/jalview/biojava/dasobert/eventmodel/ObjectListener.java b/src/jalview/biojava/dasobert/eventmodel/ObjectListener.java
new file mode 100644 (file)
index 0000000..640b413
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Nov 1, 2005
+ *
+ */
+package org.biojava.dasobert.eventmodel;
+
+/** an interface for the listeners of new PDB code requested / new Uniprot code requested
+ *
+ * @author Andreas Prlic
+ *
+ */
+public interface ObjectListener {
+
+    /** a new object has been requested
+     *
+     * @param accessionCode
+     */
+    public void newObjectRequested(String accessionCode);
+
+    /** no object with that accessionCode has been found
+     *
+     * @param accessionCode
+     */
+    public void noObjectFound(String accessionCode);
+
+
+   // public void exceptionOccured(Exception e);
+
+}
diff --git a/src/jalview/biojava/dasobert/eventmodel/SequenceEvent.java b/src/jalview/biojava/dasobert/eventmodel/SequenceEvent.java
new file mode 100644 (file)
index 0000000..7798da1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Nov 20, 2005
+ *
+ */
+package org.biojava.dasobert.eventmodel;
+
+
+public class SequenceEvent {
+
+    String sequence;
+    String accessionCode;
+    public SequenceEvent(String accessionCode, String seq) {
+        super();
+        sequence = seq;
+        this.accessionCode = accessionCode;
+    }
+
+    public String getAccessionCode(){
+        return accessionCode;
+    }
+
+    public String getSequence(){
+        return sequence;
+    }
+
+}
diff --git a/src/jalview/biojava/dasobert/eventmodel/SequenceListener.java b/src/jalview/biojava/dasobert/eventmodel/SequenceListener.java
new file mode 100644 (file)
index 0000000..37779bd
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *                  BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence.  This should
+ * be distributed with the code.  If you do not have a copy,
+ * see:
+ *
+ *      http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors.  These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ *      http://www.biojava.org/
+ *
+ * Created on Jun 10, 2005
+ *
+ */
+package org.biojava.dasobert.eventmodel;
+
+/** An interface fore events related to selections of sequence
+ * position, sequence range and locking of the selection.
+ *
+ * @author Andreas Prlic
+ *
+ */
+public interface SequenceListener
+extends ObjectListener{
+
+    /* select a certain sequence position */
+    public void selectedSeqPosition(int position);
+
+    /** select a certain range of a sequence
+     * @param start the start
+     * @param end the end of the range
+     * */
+    public void selectedSeqRange(int start, int end);
+
+    /** the current selecetion is locked and can not be changed
+     * @param flag true if selection should be locked
+     * */
+    public void selectionLocked(boolean flag);
+
+    public void newSequence(SequenceEvent e);
+
+    /** clear what has been selected
+     *
+     *
+     */
+    public void clearSelection();
+}