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

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

Import du projet MEGAPOLI

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