Team:Freiburg software/Code/BioBrick DAS Entry Points Handler.java

From 2009.igem.org

(Difference between revisions)
 
Line 1: Line 1:
-
<nowiki>
+
<nowiki>
/*
/*

Latest revision as of 00:10, 22 October 2009


/*
    Copyright: synbiowave
     
    License: GPL
     
    Authors: Jörg Wassolesk
     
    Version: 0.1 
    
    DESCRIPTION:
    	This class provides the methods needed for the handling of DAS entry_point requests.
*/

package org.synbiowave.biobrick ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;


// TODO: Auto-generated Javadoc
/**
 * a class to parse the reponse of the BioBrick DAS - entry_points request.
 */
public class BioBrick_DAS_Entry_Points_Handler extends DefaultHandler {

	/** The segments. */
	List<Map<String,String>> segments;
	
	/** The ids. */
	TreeSet<String> ids;
	
	/** The current entry point. */
	Map<String,String> currentEntryPoint;
	
	/**
	 * Instantiates a new bio brick_ da s_ entry_ points_ handler.
	 */
	public BioBrick_DAS_Entry_Points_Handler(){
		segments=new ArrayList<Map<String,String>>();
		ids=new TreeSet<String>();
		currentEntryPoint=new HashMap<String,String>();}
	
	/* (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#startDocument()
	 */
	public void startDocument(){
		segments=new ArrayList<Map<String,String>>();
		ids=new TreeSet<String>();}

	/* (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
	public void startElement(String uri,String name,String qName,Attributes atts){
		if(qName.equals("SEGMENT")){
			currentEntryPoint=new HashMap<String,String>();
			String id=atts.getValue("id");
			if(!(id==null)){
				currentEntryPoint.put("id",id);
				ids.add(id);}
			String size=atts.getValue("size");
			if(!(size==null)){currentEntryPoint.put("size",size);}
			String start=atts.getValue("start");
			if(!(start==null)){currentEntryPoint.put("start",start);}
			String stop=atts.getValue("stop");
			if(!(stop==null)){currentEntryPoint.put("stop",stop);}
			String orientation=atts.getValue("orientation");
			if(!(orientation==null)){currentEntryPoint.put("orientation",orientation);}
			String subparts=atts.getValue("subparts");
			if(!(subparts==null)){currentEntryPoint.put("subparts",subparts);}}}
	
	/* (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
	 */
	public void endElement(String uri,String name,String qName){
		if(qName.equals("SEGMENT")){segments.add(currentEntryPoint);}}
	
	/**
	 * Gets the segemnts.
	 * 
	 * @return the segemnts
	 */
	public List<Map<String,String>> getSegemnts(){return segments;}
	
	/**
	 * Gets the i ds.
	 * 
	 * @return the i ds
	 */
	public TreeSet<String> getIDs(){return ids;}
}