1 | package com.medias.xml.metadata; |
---|
2 | |
---|
3 | import com.medias.ConversionException; |
---|
4 | import com.medias.utils.Entity; |
---|
5 | import org.jdom.Element; |
---|
6 | |
---|
7 | /** |
---|
8 | * @author combaz |
---|
9 | * |
---|
10 | * Created on 10 févr. 2005 |
---|
11 | */ |
---|
12 | public class Duree implements Entity |
---|
13 | { |
---|
14 | /** |
---|
15 | * |
---|
16 | */ |
---|
17 | private static final long serialVersionUID = 1L; |
---|
18 | private int h; |
---|
19 | private int m; |
---|
20 | private double s; |
---|
21 | |
---|
22 | public Duree() { |
---|
23 | super(); |
---|
24 | this.h = 0; |
---|
25 | this.m = 0; |
---|
26 | this.s = 0; |
---|
27 | } |
---|
28 | |
---|
29 | /** |
---|
30 | * @return Returns the h. |
---|
31 | */ |
---|
32 | public int getH() { |
---|
33 | return h; |
---|
34 | } |
---|
35 | /** |
---|
36 | * @param h The h to set. |
---|
37 | */ |
---|
38 | public void setH(int h) { |
---|
39 | this.h = h; |
---|
40 | } |
---|
41 | /** |
---|
42 | * @return Returns the m. |
---|
43 | */ |
---|
44 | public int getM() { |
---|
45 | return m; |
---|
46 | } |
---|
47 | /** |
---|
48 | * @param m The m to set. |
---|
49 | */ |
---|
50 | public void setM(int m) { |
---|
51 | this.m = m; |
---|
52 | } |
---|
53 | /** |
---|
54 | * @return Returns the s. |
---|
55 | */ |
---|
56 | public double getS() { |
---|
57 | return s; |
---|
58 | } |
---|
59 | /** |
---|
60 | * @param s The s to set. |
---|
61 | */ |
---|
62 | public void setS(double s) { |
---|
63 | this.s = s; |
---|
64 | } |
---|
65 | |
---|
66 | public Element toXmlElement(String title) { |
---|
67 | Element heures = new Element("nb_heures"); |
---|
68 | heures.addContent(""+this.h); |
---|
69 | Element min = new Element("nb_minutes"); |
---|
70 | min.addContent(""+this.m); |
---|
71 | Element sec = new Element("nb_secondes"); |
---|
72 | sec.addContent(""+this.s); |
---|
73 | |
---|
74 | Element duree = new Element(title); |
---|
75 | duree.addContent(heures); |
---|
76 | duree.addContent(min); |
---|
77 | duree.addContent(sec); |
---|
78 | return duree; |
---|
79 | } |
---|
80 | |
---|
81 | public void fromXmlElement(Element el) throws ConversionException { |
---|
82 | Element heures = el.getChild("nb_heures"); |
---|
83 | Element min = el.getChild("nb_minutes"); |
---|
84 | Element sec = el.getChild("nb_secondes"); |
---|
85 | |
---|
86 | if((heures==null)||(min==null)||(sec==null)) |
---|
87 | throw new ConversionException(ConversionException.ERROR_fromXml + "Duree !"); |
---|
88 | |
---|
89 | else { |
---|
90 | this.setH(Integer.parseInt(heures.getText())); |
---|
91 | this.setM(Integer.parseInt(min.getText())); |
---|
92 | this.setS(Double.parseDouble(sec.getText())); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | /* public void reset() { |
---|
97 | h = 0; |
---|
98 | m = 0; |
---|
99 | s = 0; |
---|
100 | } */ |
---|
101 | } |
---|