(JAL-1016) noted position where race condition occurs
[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.bio.program.das.dasalignment.DASException;
26 import org.biojava.dasobert.dasregistry.*;
27
28 public class DasSourceConverter
29 {
30
31   public DasSourceConverter()
32   {
33     super();
34
35   }
36
37   /**
38    * convert a das2 source to a das 1 source. This only will work if is passes
39    * the Das2Source.isDas1Source() test i.e. this is really a das1 server there
40    * 
41    * @param das2source
42    *                a DAS2Source to be converted
43    * @return a Das1Source
44    * @throws DASException
45    */
46   public static Das1Source toDas1Source(Das2Source das2source)
47           throws Exception
48   {
49     if (!das2source.hasDas1Capabilities())
50     {
51       throw new Exception(
52               "this das source does not have das1 capabilitites");
53     }
54
55     Das1Source ds = new Das1Source();
56     ds.setAdminemail(das2source.getAdminemail());
57     ds.setDescription(das2source.getDescription());
58     ds.setHelperurl(das2source.getHelperurl());
59     ds.setRegisterDate(das2source.getRegisterDate());
60     ds.setLeaseDate(das2source.getLeaseDate());
61     ds.setLabels(das2source.getLabels());
62     ds.setCoordinateSystem(das2source.getCoordinateSystem());
63     ds.setNickname(das2source.getNickname());
64     ds.setId(das2source.getId());
65     ds.setLabels(das2source.getLabels());
66
67     // convert the capabilitites to das1 capabiltities and get the url
68     Das2Capability[] caps = das2source.getDas2Capabilities();
69     String[] das1capabilitites = new String[caps.length];
70     int DASPREFIXLENGTH = Das2CapabilityImpl.DAS1_CAPABILITY_PREFIX
71             .length();
72
73     for (int i = 0; i < caps.length; i++)
74     {
75       Das2Capability cap = caps[i];
76
77       String c = cap.getCapability();
78
79       das1capabilitites[i] = c.substring(DASPREFIXLENGTH, c.length());
80
81       String query_uri = cap.getQueryUri();
82
83       String url = query_uri.substring(0,
84               (query_uri.length() - c.length() + DASPREFIXLENGTH));
85       ds.setUrl(url);
86     }
87     ds.setCapabilities(das1capabilitites);
88
89     return ds;
90   }
91
92 }