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.*;
33 * a parser for the DAS2 sources response
35 * @author Andreas Prlic
39 public class DAS2SourceHandler extends DefaultHandler
44 Das2Source currentSource;
52 public static final String LABELPROPERTY = "label";
54 public DAS2SourceHandler()
58 sources = new ArrayList();
59 currentSource = new Das2SourceImpl();
60 coordinates = new ArrayList();
61 capabilities = new ArrayList();
62 labels = new ArrayList();
65 private void startSource(String uri, String name, String qName,
69 String id = atts.getValue("uri");
70 String title = atts.getValue("title");
71 String doc_ref = atts.getValue("doc_href");
72 String description = atts.getValue("description");
74 currentSource.setId(id);
75 currentSource.setNickname(title);
76 currentSource.setHelperurl(doc_ref);
77 currentSource.setDescription(description);
81 private DasCoordinateSystem getCoordinateSystem(String uri, String name,
82 String qname, Attributes atts)
84 // e.g. uri="http://das.sanger.ac.uk/dasregistry/coordsys/CS_LOCAL6"
85 // source="Protein Sequence" authority="UniProt" test_range="P06213" />
86 DasCoordinateSystem dcs = new DasCoordinateSystem();
87 String id = atts.getValue("uri");
90 String source = atts.getValue("source");
91 dcs.setCategory(source);
93 String authority = atts.getValue("authority");
94 dcs.setName(authority);
96 String test_range = atts.getValue("test_range");
97 dcs.setTestCode(test_range);
101 String taxidstr = atts.getValue("taxid");
102 int taxid = Integer.parseInt(taxidstr);
103 dcs.setNCBITaxId(taxid);
104 } catch (Exception e)
108 String version = atts.getValue("version");
111 dcs.setVersion(version);
117 public void startElement(String uri, String name, String qName,
120 // System.out.println("new element "+qName);
122 if (qName.equals("SOURCE"))
124 // System.out.println("new Source " + atts.getValue(uri));
125 currentSource = new Das2SourceImpl();
126 coordinates = new ArrayList();
127 capabilities = new ArrayList();
129 startSource(uri, name, qName, atts);
132 else if (qName.equals("MAINTAINER"))
134 String email = atts.getValue("email");
135 currentSource.setAdminemail(email);
137 else if (qName.equals("COORDINATES"))
139 DasCoordinateSystem dcs = getCoordinateSystem(uri, name, qName, atts);
140 coordinates.add(dcs);
143 else if (qName.equals("CAPABILITY"))
145 Das2Capability cap = getCapability(uri, name, qName, atts);
146 capabilities.add(cap);
148 else if (qName.equals("PROPERTY"))
150 addProperty(uri, name, qName, atts);
154 private Das2Capability getCapability(String uri, String name,
155 String qName, Attributes atts)
157 // e.g <CAPABILITY type="features"
158 // query_id="http://das.biopackages.net/das/genome/yeast/S228C/feature" />
159 Das2Capability cap = new Das2CapabilityImpl();
161 String type = atts.getValue("type");
162 cap.setCapability(type);
163 String query_uri = atts.getValue("query_uri");
164 cap.setQueryUri(query_uri);
169 private void addProperty(String uri, String name, String qName,
172 String pname = atts.getValue("name");
173 String label = atts.getValue("value");
174 if (pname.equals(LABELPROPERTY))
180 public void startDocument()
182 sources = new ArrayList();
183 coordinates = new ArrayList();
184 capabilities = new ArrayList();
187 public void endElement(String uri, String name, String qName)
189 if (qName.equals("SOURCE"))
191 currentSource.setDas2Capabilities((Das2Capability[]) capabilities
192 .toArray(new Das2Capability[capabilities.size()]));
193 // System.out.println("got coordinates " + coordinates.size());
194 currentSource.setCoordinateSystem((DasCoordinateSystem[]) coordinates
195 .toArray(new DasCoordinateSystem[coordinates.size()]));
197 currentSource.setLabels((String[]) labels.toArray(new String[labels
201 // System.out.println("Das2SourceHandler endElement name " + name + " uri
202 // " + uri + " qName " + qName);
203 // System.out.println("Das2SourceHandler adding to source: " +
204 // currentSource.getId());
205 sources.add(currentSource);
206 currentSource = new Das2SourceImpl();
210 public DasSource[] getSources()
212 // System.out.println("Das2SourceHandler: source size: " + sources.size());
213 return (DasSource[]) sources.toArray(new DasSource[sources.size()]);