1 package jalview.ws.dbsources.das.datamodel;
3 import java.text.ParseException;
4 import java.util.ArrayList;
8 import org.biodas.jdas.dassources.Capabilities;
9 import org.biodas.jdas.dassources.utils.DasTimeFormat;
10 import org.biodas.jdas.dassources.utils.RegistrySourceAdapter;
11 import org.biodas.jdas.schema.sources.CAPABILITY;
12 import org.biodas.jdas.schema.sources.COORDINATES;
13 import org.biodas.jdas.schema.sources.MAINTAINER;
14 import org.biodas.jdas.schema.sources.PROP;
15 import org.biodas.jdas.schema.sources.SOURCE;
16 import org.biodas.jdas.schema.sources.VERSION;
18 import sun.plugin2.message.GetNameSpaceMessage;
20 import jalview.ws.dbsources.DasSequenceSource;
21 import jalview.ws.dbsources.das.api.jalviewSourceI;
22 import jalview.ws.seqfetcher.DbSourceProxy;
24 public class JalviewSource implements jalviewSourceI
28 public JalviewSource(SOURCE local2, boolean local)
35 public String getTitle()
37 return source.getTitle();
41 public VERSION getVersion()
44 return getVersionFor(source);
48 public String getDocHref()
50 return source.getDocHref();
54 public String getDescription()
56 return source.getDescription();
60 public String getUri()
62 return source.getUri();
66 public MAINTAINER getMAINTAINER()
68 return source.getMAINTAINER();
72 public String getEmail()
74 return (local) ? null: source.getMAINTAINER().getEmail();
77 boolean local = false;
80 public boolean isLocal()
86 public boolean isSequenceSource()
88 String seqcap = "das1:" + Capabilities.SEQUENCE.getName();
89 for (String cp : getCapabilityList(getVersionFor(source)))
91 if (cp.equals(seqcap))
100 public boolean isFeatureSource()
102 String seqcap = "das1:" + Capabilities.FEATURES.getName();
103 for (String cp : getCapabilityList(getVersionFor(source)))
105 if (cp.equals(seqcap))
114 private VERSION getVersionFor(SOURCE ds)
116 VERSION latest = null;
117 for (VERSION v : ds.getVERSION())
120 || isLaterThan(latest.getCreated(), v.getCreated()))
122 // TODO: das 1.6 - should just get the first version - ignore other
123 // versions since not specified how to construct URL from version's URI
131 private boolean isLaterThan(String ref, String newer)
133 Date refdate = null, newdate = null;
136 refdate = DasTimeFormat.fromDASString(ref);
138 } catch (ParseException x)
144 newdate = DasTimeFormat.fromDASString(newer);
145 } catch (ParseException e)
147 // TODO: handle exception
153 return refdate.before(newdate);
161 // assume first instance of source is newest in list. - TODO: check if
162 // natural ordering of source versions is newest first or oldest first
166 public String[] getLabelsFor(VERSION v)
168 ArrayList<String> labels = new ArrayList<String>();
169 for (PROP p : v.getPROP())
171 if (p.getName().equalsIgnoreCase("LABEL"))
173 labels.add(p.getValue());
176 return labels.toArray(new String[0]);
179 private CAPABILITY getCapability(Capabilities capability) {
180 for (CAPABILITY p: getVersion().getCAPABILITY()) {
181 if (p.getType().equalsIgnoreCase(capability.getName()) || p.getType().equalsIgnoreCase("das1:"+capability.getName()))
188 public String[] getCapabilityList(VERSION v)
191 ArrayList<String> labels = new ArrayList<String>();
192 for (CAPABILITY p : v.getCAPABILITY())
194 // TODO: work out what to do with namespace prefix
195 // does SEQUENCE == das1:SEQUENCE and das2:SEQUENCE ?
196 // for moment, just show all capabilities...
197 if (p.getType().startsWith("das1:"))
199 labels.add(p.getType());
202 return labels.toArray(new String[0]);
206 public List<DbSourceProxy> getSequenceSourceProxies()
208 if (!isSequenceSource())
212 ArrayList<DbSourceProxy> seqsources = new ArrayList<DbSourceProxy>();
215 VERSION v = getVersion();
216 for (COORDINATES cs : v.getCOORDINATES())
220 * if (css == null || css.length == 0) { // TODO: query das source
221 * directly to identify coordinate system... or // have to make up a
222 * coordinate system css = new DasCoordinateSystem[] { new
223 * DasCoordinateSystem() }; css[0].setName(d1s.getNickname());
224 * css[0].setUniqueId(d1s.getNickname()); } for (int c = 0; c <
229 seqsources.add(new DasSequenceSource("das:" + getTitle() + " ("
230 + cs.getContent() + ")", cs.getContent(), source, v, cs));
231 } catch (Exception e)
233 System.err.println("Ignoring sequence coord system " + cs + " ("
234 + cs.getContent() + ") for source " + getTitle()
235 + "- threw exception when constructing fetcher.\n");
242 seqsources.add(new DasSequenceSource("das:"+getTitle(), getTitle(), source, getVersion(), null));
243 } catch (Exception e)
245 // TODO Auto-generated catch block
253 public String getSourceURL()
256 String url = new RegistrySourceAdapter(source).getOriginalDataSourceUri();
261 System.err.println("Serious: Couldn't get the URL for source "+source.getTitle());