2 * BioJava development code
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,
9 * http://www.gnu.org/copyleft/lesser.html
11 * Copyright for this code is held jointly by the individual
12 * authors. These should be listed in @author doc comments.
14 * For more information on the BioJava project and its aims,
15 * or to join the biojava-l mailing list, visit the home page
18 * http://www.biojava.org/
20 * Created on Mar 15, 2006
23 package org.biojava.dasobert.das2.io;
27 import org.biojava.dasobert.das2.*;
28 import org.biojava.dasobert.dasregistry.*;
30 import org.xml.sax.helpers.*;
32 /** a parser for the DAS2 sources response
34 * @author Andreas Prlic
38 public class DAS2SourceHandler
39 extends DefaultHandler
43 Das2Source currentSource;
48 public static final String LABELPROPERTY = "label";
50 public DAS2SourceHandler()
54 sources = new ArrayList();
55 currentSource = new Das2SourceImpl();
56 coordinates = new ArrayList();
57 capabilities = new ArrayList();
58 labels = new ArrayList();
61 private void startSource(String uri, String name, String qName,
65 String id = atts.getValue("uri");
66 String title = atts.getValue("title");
67 String doc_ref = atts.getValue("doc_href");
68 String description = atts.getValue("description");
70 currentSource.setId(id);
71 currentSource.setNickname(title);
72 currentSource.setHelperurl(doc_ref);
73 currentSource.setDescription(description);
77 private DasCoordinateSystem getCoordinateSystem(String uri, String name,
78 String qname, Attributes atts)
80 // e.g. uri="http://das.sanger.ac.uk/dasregistry/coordsys/CS_LOCAL6"
81 // source="Protein Sequence" authority="UniProt" test_range="P06213" />
82 DasCoordinateSystem dcs = new DasCoordinateSystem();
83 String id = atts.getValue("uri");
86 String source = atts.getValue("source");
87 dcs.setCategory(source);
89 String authority = atts.getValue("authority");
90 dcs.setName(authority);
92 String test_range = atts.getValue("test_range");
93 dcs.setTestCode(test_range);
97 String taxidstr = atts.getValue("taxid");
98 int taxid = Integer.parseInt(taxidstr);
99 dcs.setNCBITaxId(taxid);
104 String version = atts.getValue("version");
107 dcs.setVersion(version);
113 public void startElement(String uri, String name, String qName,
116 //System.out.println("new element "+qName);
118 if (qName.equals("SOURCE"))
120 //System.out.println("new Source " + atts.getValue(uri));
121 currentSource = new Das2SourceImpl();
122 coordinates = new ArrayList();
123 capabilities = new ArrayList();
125 startSource(uri, name, qName, atts);
128 else if (qName.equals("MAINTAINER"))
130 String email = atts.getValue("email");
131 currentSource.setAdminemail(email);
133 else if (qName.equals("COORDINATES"))
135 DasCoordinateSystem dcs = getCoordinateSystem(uri, name, qName, atts);
136 coordinates.add(dcs);
139 else if (qName.equals("CAPABILITY"))
141 Das2Capability cap = getCapability(uri, name, qName, atts);
142 capabilities.add(cap);
144 else if (qName.equals("PROPERTY"))
146 addProperty(uri, name, qName, atts);
150 private Das2Capability getCapability(String uri, String name, String qName,
153 // e.g <CAPABILITY type="features" query_id="http://das.biopackages.net/das/genome/yeast/S228C/feature" />
154 Das2Capability cap = new Das2CapabilityImpl();
156 String type = atts.getValue("type");
157 cap.setCapability(type);
158 String query_uri = atts.getValue("query_uri");
159 cap.setQueryUri(query_uri);
164 private void addProperty(String uri, String name, String qName,
167 String pname = atts.getValue("name");
168 String label = atts.getValue("value");
169 if (pname.equals(LABELPROPERTY))
175 public void startDocument()
177 sources = new ArrayList();
178 coordinates = new ArrayList();
179 capabilities = new ArrayList();
182 public void endElement(String uri, String name, String qName)
184 if (qName.equals("SOURCE"))
186 currentSource.setDas2Capabilities( (Das2Capability[]) capabilities.
187 toArray(new Das2Capability[capabilities.
189 //System.out.println("got coordinates " + coordinates.size());
190 currentSource.setCoordinateSystem( (DasCoordinateSystem[]) coordinates.
191 toArray(new DasCoordinateSystem[
192 coordinates.size()]));
194 currentSource.setLabels( (String[]) labels.toArray(new String[labels.size()]));
197 //System.out.println("Das2SourceHandler endElement name " + name + " uri " + uri + " qName " + qName);
198 //System.out.println("Das2SourceHandler adding to source: " + currentSource.getId());
199 sources.add(currentSource);
200 currentSource = new Das2SourceImpl();
204 public DasSource[] getSources()
206 //System.out.println("Das2SourceHandler: source size: " + sources.size());
207 return (DasSource[]) sources.toArray(new DasSource[sources.size()]);