Das client files
[jalview.git] / src / org / biojava / dasobert / das / DAS_Types_Handler.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 19.03.2004
21  * @author Andreas Prlic
22  *
23  */
24 package org.biojava.dasobert.das ;
25
26 import org.xml.sax.helpers.DefaultHandler;
27 import org.xml.sax.Attributes;
28
29 import java.util.ArrayList ;
30 import java.util.List;
31
32
33 /** a class to parse the reponse of a DAS - types request 
34  */
35 public class DAS_Types_Handler extends DefaultHandler {
36     List types;
37     boolean dastypesPresent;
38     boolean gffPresent;
39     boolean segmentPresent;
40     
41     public DAS_Types_Handler() {
42         super();
43         types = new ArrayList();
44         dastypesPresent = false;
45         gffPresent=false;
46         segmentPresent=false;
47     }
48
49     public void startElement (String uri, String name, String qName, Attributes atts){
50         if ( qName.equals("DASTYPES")) {
51             dastypesPresent = true;
52             
53         } else if ( qName.equals("GFF")) {
54             gffPresent = true;
55             
56         } else if ( qName.equals("SEGMENT")) {
57             segmentPresent = true;      
58          
59             String id = atts.getValue("id");
60             // id is optional here
61             if ( id != null ) {
62                 types.add(id);
63             }
64         } else if ( qName.equals("TYPE")){
65             String type = atts.getValue("id");
66             // id is mandatory ...          
67             types.add(type);
68             
69         }
70         
71     }
72
73     public String[] getTypes(){
74         return (String[])types.toArray(new String[types.size()]);
75     }
76 }
77