1 package fr.orsay.lri.varna.models.rna;
4 import java.io.Serializable;
6 import javax.xml.transform.sax.TransformerHandler;
8 import org.xml.sax.SAXException;
9 import org.xml.sax.helpers.AttributesImpl;
11 import fr.orsay.lri.varna.utils.XMLUtils;
13 public class ModeleBackboneElement implements Serializable{
18 private static final long serialVersionUID = -614968737102943216L;
20 public ModeleBackboneElement(int index, BackboneType t)
23 if (t==BackboneType.CUSTOM_COLOR)
25 throw new IllegalArgumentException("Error: Missing Color while constructing Backbone");
30 public ModeleBackboneElement(int index, Color c)
33 _type=BackboneType.CUSTOM_COLOR;
37 public enum BackboneType{
39 DISCONTINUOUS_TYPE ("discontinuous"),
40 MISSING_PART_TYPE ("missing"),
41 CUSTOM_COLOR ("custom");
45 BackboneType(String s)
50 public String getLabel()
56 public static BackboneType getType(String lbl)
58 BackboneType[] vals = BackboneType.values();
59 for(int i=0;i<vals.length;i++)
61 if (vals[i].equals(lbl))
69 private BackboneType _type;
70 private Color _color = null;
74 public BackboneType getType()
84 public Color getColor()
89 public static String XML_ELEMENT_NAME = "BackboneElement";
90 public static String XML_VAR_INDEX_NAME = "index";
91 public static String XML_VAR_TYPE_NAME = "type";
92 public static String XML_VAR_COLOR_NAME = "color";
94 public void toXML(TransformerHandler hd) throws SAXException
96 AttributesImpl atts = new AttributesImpl();
97 atts.addAttribute("","",XML_VAR_INDEX_NAME,"CDATA",""+_index);
98 atts.addAttribute("","",XML_VAR_TYPE_NAME,"CDATA",""+_type.getLabel());
99 if(_type==BackboneType.CUSTOM_COLOR){
100 atts.addAttribute("","",XML_VAR_COLOR_NAME,"CDATA",""+XMLUtils.toHTMLNotation(_color));
102 hd.startElement("","",XML_ELEMENT_NAME,atts);
103 hd.endElement("","",XML_ELEMENT_NAME);