source: ether_megapoli/domain/interface/com/medias/xml/metadata/Parametre.java @ 89

Last change on this file since 89 was 89, checked in by vmipsl, 13 years ago

Import du projet MEGAPOLI

File size: 5.9 KB
Line 
1package com.medias.xml.metadata;
2
3import java.util.Comparator;
4
5import com.medias.ConversionException;
6import org.jdom.*;
7import com.medias.ConversionException;
8import org.medias.megapoli.utils.Entity;
9import com.medias.Constantes;
10
11/**
12 * @author combaz
13 * Created on 10 févr. 2005
14 * TODO To change the template for this generated type comment go to
15 * Window - Preferences - Java - Code Style - Code Templates
16 */
17public class Parametre implements Entity {
18        /**
19     *
20     */
21    private static final long serialVersionUID = 1L;
22    private String nom;
23    private String nomOth;
24        private String abrev;
25        private String unite;
26        private String uniteOth;
27        // Utilisé dans la partie dépÃŽt de données
28        private String nomCapteur;
29        // Utilisé dans la partie accÚs aux données
30        private String desc;
31        private String categorie;
32        private String categOth;
33        private String domaine;
34        private String idParametre;
35       
36        public Parametre() {
37                super();
38                this.nom = "";
39                this.nomOth = "";
40                this.abrev = "";
41                this.unite = "";
42                this.uniteOth = "";
43                this.categorie = "";
44                this.categOth = "";
45                this.domaine = "";
46                this.desc = "";
47                this.idParametre = null;
48                this.nomCapteur = "";
49        }
50
51       
52    public String getIdParametre() {
53        return idParametre;
54    }
55   
56    public void setIdParametre(String idParametre) {
57        this.idParametre = idParametre;
58    }
59   
60    public String getDesc() {
61        return desc;
62    }
63   
64    public void setDesc(String desc) {
65        this.desc = desc;
66    }
67   
68    public String getDomaine() {
69        return domaine;
70    }
71   
72    public void setDomaine(String domaine) {
73        this.domaine = domaine;
74    }
75   
76    public String getCategorie() {
77        return categorie;
78    }
79   
80    public void setCategorie(String categorie) {
81        this.categorie = categorie;
82    }
83   
84        /**
85         * @return Returns the abrev.
86         */
87        public String getAbrev() {
88                return abrev;
89        }
90        /**
91         * @param abrev The abrev to set.
92         */
93        public void setAbrev(String abrev) {
94                this.abrev = abrev;
95        }
96        /**
97         * @return Returns the nom.
98         */
99        public String getNom() {
100                return nom;
101        }
102        /**
103         * @param nom The nom to set.
104         */
105        public void setNom(String nom) {
106                this.nom = nom;
107        }
108        /**
109         * @return Returns the unite.
110         */
111        public String getUnite() {
112                return unite;
113        }
114        /**
115         * @param unite The unite to set.
116         */
117        public void setUnite(String unite) {
118                this.unite = unite;
119        }
120               
121        public String getNomCapteur() {
122                return nomCapteur;
123        }
124
125        public void setNomCapteur(String nomCapteur) {
126                this.nomCapteur = nomCapteur;
127        }
128
129        public Element toXmlElement(String title) {
130                Element n = new Element("nom");
131                n.addContent(this.nom);
132                Element a = new Element("abrev");
133//              a.addContent(this.abrev);
134                a.addContent(this.categorie);
135                Element u = new Element("unite");
136//              try {
137//                      unite = new String(unite.getBytes("ISO-8859-1"),"UTF-8");
138//              } catch (UnsupportedEncodingException e) {
139//                      e.printStackTrace();
140//              }
141                u.addContent(this.unite);
142                Element nomCapt = new Element("capteur");
143                if (this.nomCapteur != null)
144                    nomCapt.addContent(this.nomCapteur);
145                else
146                    nomCapt.addContent("");
147                Element param = new Element(title);
148                param.addContent(n);
149                param.addContent(a);
150                param.addContent(u);
151                param.addContent(nomCapt);
152                return param;
153        }
154       
155        public void fromXmlElement(Element el) throws ConversionException
156    {
157                Element n = el.getChild("nom");
158                Element a = el.getChild("abrev");
159                Element u = el.getChild("unite");
160                Element c = el.getChild("capteur");
161               
162                if((n==null)||(a==null)||(u==null))
163                        throw new ConversionException(ConversionException.ERROR_fromXml + "Parametre !");
164               
165                else {
166//                      this.setNom(n.getText());
167                        boolean isNomDefault = false;
168                        for (String nomP: Constantes.listeNomParams) {
169                                if (n.getText().equals(nomP)) {
170                                        isNomDefault = true;
171                                        break;
172                                }
173                        }
174                        if (isNomDefault)
175                                this.setNom(n.getText());
176                        else {
177                                this.setNom("-");
178                                this.setNomOth(n.getText());
179                        }
180//                      this.setAbrev(a.getText());
181                        boolean isCategDefault = false;
182                        for (String cat: Constantes.listeCategParams) {
183                                if (a.getText().equals(cat)) {
184                                        isCategDefault = true;
185                                        break;
186                                }
187                        }
188                        if (isCategDefault)
189                                this.setCategorie(a.getText());
190                        else {
191                                this.setCategorie("-");
192                                this.setCategOth(a.getText());
193                        }
194                        boolean isUnitDefault = false;
195                        for (String unit: Constantes.listeUnites) {
196                                if (u.getText().equals(unit)) {
197                                        isUnitDefault = true;
198                                        break;
199                                }
200                        }
201                        if (isUnitDefault)
202                                this.setUnite(u.getText());
203                        else {
204                                this.setUnite("-");
205                                this.setUniteOth(u.getText());
206                        }
207                        if (c==null) {
208                            c = new Element("capteur");
209                            c.addContent("");
210                            this.setNomCapteur(c.getText());
211                        } else {
212                            this.setNomCapteur(c.getText());
213                        }
214                }
215        }
216       
217        public void formToModel() {
218                abrev = ( abrev == null ? "" : abrev.trim() );
219//              nom = ( nom == null ? "" : nom.trim() );
220                if (nom == null || nom.equals("-")) {
221                        if (nomOth == null) {
222                                nom = "";
223                        } else {
224                                nom = nomOth.trim();
225                        }
226                } else {
227                        nom = nom.trim();
228                }
229                if (categorie == null || categorie.equals("-")) {
230                        if (categOth == null) {
231                                categorie = "";
232                        } else {
233                                categorie = categOth.trim();
234                        }
235                } else {
236                        categorie = categorie.trim();
237                }
238//              unite = ( unite == null ? "" : unite.trim() );
239                if (unite == null || unite.equals("-")) {
240                        if (uniteOth == null) {
241                                unite = "";
242                        } else {
243                                unite = uniteOth.trim();
244                        }
245                } else {
246                        unite = unite.trim();
247                }
248        }
249       
250    public class ComparatorNom implements Comparator<Parametre>{
251        public int compare(Parametre p1, Parametre p2){
252                return p1.getNom().compareTo(p2.getNom());
253        }
254    }
255
256        public String getUniteOth() {
257                return uniteOth;
258        }
259
260        public void setUniteOth(String uniteOth) {
261                this.uniteOth = uniteOth;
262        }
263
264
265        public String getCategOth() {
266                return categOth;
267        }
268
269
270        public void setCategOth(String categOth) {
271                this.categOth = categOth;
272        }
273
274
275        public String getNomOth() {
276                return nomOth;
277        }
278
279
280        public void setNomOth(String nomOth) {
281                this.nomOth = nomOth;
282        }
283}
Note: See TracBrowser for help on using the repository browser.