Das client files
[jalview.git] / src / org / biojava / dasobert / das2 / DasSourceConverter.java
1 /*
2  *                  BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on Mar 23, 2006
21  *
22  */
23 package org.biojava.dasobert.das2;
24
25 import org.biojava.dasobert.dasregistry.Das1Source;
26
27 public class DasSourceConverter {
28
29     public DasSourceConverter() {
30         super();
31
32     }
33
34
35     /** convert a das2 source to a das 1 source.
36      * This only will work if is passes the Das2Source.isDas1Source() test
37      * i.e. this is really a das1 server there
38      *
39      * @return
40      */
41     public static Das1Source toDas1Source (Das2Source das2source) throws Exception{
42         if ( ! das2source.hasDas1Capabilities())
43             throw new Exception("this das source does not have das1 capabilitites");
44
45         Das1Source ds = new Das1Source();
46         ds.setAdminemail(das2source.getAdminemail());
47         ds.setDescription(das2source.getDescription());
48         ds.setHelperurl(das2source.getHelperurl());
49         ds.setRegisterDate(das2source.getRegisterDate());
50         ds.setLeaseDate(das2source.getLeaseDate());
51         ds.setLabels(das2source.getLabels());
52         ds.setCoordinateSystem(das2source.getCoordinateSystem());
53         ds.setNickname(das2source.getNickname());
54         ds.setId(das2source.getId());
55
56         // convert the capabilitites to das1 capabiltities and get the url
57         Das2Capability[] caps = das2source.getDas2Capabilities();
58         String[] das1capabilitites = new String[caps.length];
59         int DASPREFIXLENGTH = 4;
60         for ( int i = 0 ; i< caps.length;i++){
61             Das2Capability cap = caps[i];
62
63             String c = cap.getCapability();
64             das1capabilitites[i] = c.substring(4,c.length());
65             String query_uri = cap.getQueryUri();
66
67             String url = query_uri.substring(0,(query_uri.length() - c.length() + DASPREFIXLENGTH));
68             ds.setUrl(url);
69         }
70         ds.setCapabilities(das1capabilitites);
71
72         return ds ;
73     }
74
75 }