source: ether_statistics/domain/interface/com/medias/xml/metadata/Presentation.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 3.8 KB
Line 
1package com.medias.xml.metadata;
2
3import com.medias.ConversionException;
4import com.medias.utils.Entity;
5import org.jdom.Element;
6
7import java.util.ArrayList;
8import java.util.Iterator;
9import java.util.List;
10
11/**
12 * @author combaz
13 * Created on 10 févr. 2005
14 *
15 * Represente la partie "Presentation" des metadonnees.
16 */
17public class Presentation implements Entity
18{
19        /**
20     *
21     */
22    private static final long serialVersionUID = 1L;
23    private String nom;
24        private String def;
25        private String dest;
26        private String cat;
27        private ArrayList<Contact> contacts;
28       
29        public Presentation() {
30                super();
31                this.nom = null;
32                this.def = null;
33                this.dest = null;
34                this.cat = null;
35                this.contacts = new ArrayList<Contact>();
36        }
37       
38        public ArrayList<Contact> getContactsList() {
39                return this.contacts;
40        }
41        /**
42         * @return Returns the contacts.
43         */
44        public Object[] getContacts() {
45                if(this.contacts.isEmpty()) {
46                        Contact pers = new Contact();
47                        this.contacts.add(pers);
48                }
49                return this.contacts.toArray();
50        }
51        /**
52         * @param contacts The contacts to set.
53         */
54        public void setContacts(Contact[] contacts) {
55                this.contacts = new ArrayList<Contact>();
56                for(int i=0; i<contacts.length; i++)
57                        this.contacts.add(contacts[i]);
58        }
59        /**
60         * @return Returns the cat.
61         */
62        public String getCat() {
63                return cat;
64        }
65        /**
66         * @param cat The cat to set.
67         */
68        public void setCat(String cat) {
69                this.cat = cat;
70        }
71        /**
72         * @return Returns the def.
73         */
74        public String getDef() {
75                return def;
76        }
77        /**
78         * @param def The def to set.
79         */
80        public void setDef(String def) {
81                this.def = def;
82        }
83        /**
84         * @return Returns the dest.
85         */
86        public String getDest() {
87                return dest;
88        }
89        /**
90         * @param dest The dest to set.
91         */
92        public void setDest(String dest) {
93                this.dest = dest;
94        }
95        /**
96         * @return Returns the nom.
97         */
98        public String getNom() {
99                return nom;
100        }
101        /**
102         * @param nom The nom to set.
103         */
104        public void setNom(String nom) {
105                this.nom = nom;
106        }
107       
108        public void addContact() {
109                Contact contact = new Contact();
110                this.contacts.add(contact);
111        }
112       
113        public void removeContact(Integer idx) {
114//          System.out.println ("PRESENTATION : removeContact (" + idx + ")");
115                this.contacts.remove(idx.intValue());
116        }
117       
118       
119        public Element toXmlElement(String title) {
120                Element n = new Element("nom");
121                n.addContent(this.nom);
122                Element d = new Element("definition");
123                d.addContent(this.def);
124                Element de = new Element("destination");
125                de.addContent(this.dest);
126                Element c = new Element("categorie");
127                c.addContent(this.cat);
128                Element p = new Element("contacts");
129                ArrayList<Element> pl = new ArrayList<Element>();
130                for(int i = 0; i<this.contacts.size(); i++) {
131                        Contact pers = (Contact)(this.contacts.get(i));
132                        Element elem = pers.toXmlElement("personne");
133                        pl.add(elem);
134                }
135                p.addContent(pl);
136               
137                Element pres = new Element(title);
138                pres.addContent(n);
139                pres.addContent(d);
140                pres.addContent(de);
141                pres.addContent(c);
142                pres.addContent(p);
143               
144                return pres;
145        }
146       
147        public void fromXmlElement(Element el) throws ConversionException {
148                Element n = el.getChild("nom");
149                Element d = el.getChild("definition");
150                Element de = el.getChild("destination");
151                Element c = el.getChild("categorie");
152                Element p = el.getChild("contacts");
153               
154                if((n==null)||(d==null)||(de==null)||(c==null)||(p==null)) {
155                        throw new ConversionException(ConversionException.ERROR_fromXml + "Presentation !");
156                }
157               
158                else {
159                        this.setNom(n.getText());
160                        this.setDef(d.getText());
161                        this.setDest(de.getText());
162                        this.setCat(c.getText());
163                        List<?> pl = p.getChildren("personne");
164                        Iterator<?> plit = pl.iterator();
165                        while(plit.hasNext()) {
166                                Element elem = (Element) plit.next();
167                                Contact pers = new Contact();
168                                pers.fromXmlElement(elem);
169                                this.contacts.add(pers);
170                        }
171                }
172        }
173
174/*      public void reset() {
175                this.nom = null;
176                this.def = null;
177                this.dest = null;
178                this.cat = null;
179        }*/
180}
Note: See TracBrowser for help on using the repository browser.