root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectElement.java @ 3553
History | View | Annotate | Download (8.19 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project; |
42 |
|
43 |
import com.hardcode.driverManager.DriverLoadException; |
44 |
|
45 |
import com.iver.andami.messages.NotificationManager; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
48 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
49 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
50 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
51 |
import com.iver.cit.gvsig.gui.project.OpenException; |
52 |
import com.iver.cit.gvsig.gui.project.SaveException; |
53 |
|
54 |
import com.iver.utiles.XMLEntity; |
55 |
|
56 |
import java.beans.PropertyChangeListener; |
57 |
import java.beans.PropertyChangeSupport; |
58 |
|
59 |
import java.io.Serializable; |
60 |
|
61 |
import java.text.DateFormat; |
62 |
|
63 |
import java.util.Date; |
64 |
|
65 |
|
66 |
/**
|
67 |
* Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
68 |
*
|
69 |
* @author Fernando Gonz?lez Cort?s
|
70 |
*/
|
71 |
public abstract class ProjectElement implements Serializable { |
72 |
protected PropertyChangeSupport change; |
73 |
protected Project project;
|
74 |
protected int index; |
75 |
protected String name; |
76 |
protected String creationDate; |
77 |
protected String owner; |
78 |
protected String comment; |
79 |
|
80 |
/**
|
81 |
* Creates a new ProjectElement object.
|
82 |
*/
|
83 |
public ProjectElement() {
|
84 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
85 |
change = new PropertyChangeSupport(this); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see java.lang.Object#toString()
|
90 |
*/
|
91 |
public String toString() { |
92 |
return name;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Obtiene el nombre del elemento
|
97 |
*
|
98 |
* @return
|
99 |
*/
|
100 |
public String getName() { |
101 |
return name;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Establece el nombre del elemento
|
106 |
*
|
107 |
* @param string
|
108 |
*/
|
109 |
public void setName(String string) { |
110 |
String oldValue = name;
|
111 |
name = string; |
112 |
change.firePropertyChange("name", oldValue, name);
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Obtiene la fecha de creaci?n del elemento
|
117 |
*
|
118 |
* @return
|
119 |
*/
|
120 |
public String getCreationDate() { |
121 |
return creationDate;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Obtiene el propietario del elemento
|
126 |
*
|
127 |
* @return
|
128 |
*/
|
129 |
public String getOwner() { |
130 |
return owner;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Establece la fecha de creaci?n del elemento.
|
135 |
*
|
136 |
* @param string
|
137 |
*/
|
138 |
public void setCreationDate(String string) { |
139 |
creationDate = string; |
140 |
change.firePropertyChange("creationDate", creationDate, creationDate);
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Establece el propietario del elemento
|
145 |
*
|
146 |
* @param string
|
147 |
*/
|
148 |
public void setOwner(String string) { |
149 |
owner = string; |
150 |
change.firePropertyChange("owner", owner, owner);
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Obtiene los comentarios del proyecto
|
155 |
*
|
156 |
* @return
|
157 |
*/
|
158 |
public String getComment() { |
159 |
return comment;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* Establece los comentarios del proyecto
|
164 |
*
|
165 |
* @param string
|
166 |
*/
|
167 |
public void setComment(String string) { |
168 |
comment = string; |
169 |
change.firePropertyChange("comment", comment, comment);
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* A?ade un listener para los cambios en las bounded properties
|
174 |
*
|
175 |
* @param listener
|
176 |
*/
|
177 |
public synchronized void addPropertyChangeListener( |
178 |
PropertyChangeListener listener) {
|
179 |
change.addPropertyChangeListener(listener); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* DOCUMENT ME!
|
184 |
*
|
185 |
* @return DOCUMENT ME!
|
186 |
* @throws XMLException
|
187 |
* @throws SaveException
|
188 |
*/
|
189 |
public XMLEntity getXMLEntity() throws SaveException { |
190 |
XMLEntity xml = new XMLEntity();
|
191 |
try{
|
192 |
xml.putProperty("className", this.getClass().getName()); |
193 |
xml.putProperty("comment", comment);
|
194 |
xml.putProperty("creationDate", creationDate);
|
195 |
xml.putProperty("name", name);
|
196 |
xml.putProperty("owner", owner);
|
197 |
|
198 |
//xml.addChild(mapContext.getXMLEntity);
|
199 |
}catch (Exception e) { |
200 |
throw new SaveException(e,this.getClass().getName()); |
201 |
} |
202 |
return xml;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* DOCUMENT ME!
|
207 |
*
|
208 |
* @param xml DOCUMENT ME!
|
209 |
* @param p DOCUMENT ME!
|
210 |
*
|
211 |
* @return DOCUMENT ME!
|
212 |
* @throws XMLException
|
213 |
* @throws DriverException
|
214 |
* @throws DriverIOException
|
215 |
* @throws CancelationException
|
216 |
* @throws ClassNotFoundException
|
217 |
* @throws InstantiationException
|
218 |
* @throws IllegalAccessException
|
219 |
* @throws DriverIOException
|
220 |
* @throws DriverLoadException
|
221 |
*/
|
222 |
public static ProjectElement createFromXML03(XMLEntity xml, Project p) throws XMLException, DriverException, DriverIOException{ |
223 |
ProjectElement pe = null;
|
224 |
|
225 |
Class clase;
|
226 |
try {
|
227 |
clase = Class.forName(xml.getStringProperty("className")); |
228 |
pe = (ProjectElement) clase.newInstance(); |
229 |
} catch (ClassNotFoundException e) { |
230 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
231 |
e); |
232 |
} catch (InstantiationException e) { |
233 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
234 |
e); |
235 |
} catch (IllegalAccessException e) { |
236 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
237 |
e); |
238 |
} |
239 |
|
240 |
pe.setComment(xml.getStringProperty("comment"));
|
241 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
242 |
pe.setName(xml.getStringProperty("name"));
|
243 |
pe.setOwner(xml.getStringProperty("owner"));
|
244 |
pe.project = p; |
245 |
|
246 |
pe.setXMLEntity03(xml,p); |
247 |
|
248 |
return pe;
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* DOCUMENT ME!
|
253 |
*
|
254 |
* @param xml DOCUMENT ME!
|
255 |
* @param p DOCUMENT ME!
|
256 |
*
|
257 |
* @return DOCUMENT ME!
|
258 |
*
|
259 |
* @throws XMLException
|
260 |
* @throws DriverException
|
261 |
* @throws DriverIOException
|
262 |
* @throws OpenException
|
263 |
*/
|
264 |
public static ProjectElement createFromXML(XMLEntity xml, Project p) |
265 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
266 |
ProjectElement pe = null;
|
267 |
try{
|
268 |
Class clase;
|
269 |
|
270 |
try {
|
271 |
clase = Class.forName(xml.getStringProperty("className")); |
272 |
pe = (ProjectElement) clase.newInstance(); |
273 |
} catch (ClassNotFoundException e) { |
274 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
275 |
e); |
276 |
} catch (InstantiationException e) { |
277 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
278 |
e); |
279 |
} catch (IllegalAccessException e) { |
280 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
281 |
e); |
282 |
} |
283 |
|
284 |
pe.setComment(xml.getStringProperty("comment"));
|
285 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
286 |
pe.setName(xml.getStringProperty("name"));
|
287 |
pe.setOwner(xml.getStringProperty("owner"));
|
288 |
pe.project = p; |
289 |
}catch (Exception e) { |
290 |
throw new OpenException(e,pe.getClass().getName()); |
291 |
} |
292 |
pe.setXMLEntity(xml, p); |
293 |
|
294 |
return pe;
|
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*
|
300 |
* @param xml DOCUMENT ME!
|
301 |
* @param p DOCUMENT ME!
|
302 |
*
|
303 |
* @throws XMLException
|
304 |
* @throws DriverException
|
305 |
* @throws DriverIOException
|
306 |
* @throws OpenException
|
307 |
*/
|
308 |
public abstract void setXMLEntity(XMLEntity xml, Project p) |
309 |
throws XMLException, DriverException, DriverIOException, OpenException;
|
310 |
|
311 |
/**
|
312 |
* DOCUMENT ME!
|
313 |
*
|
314 |
* @param xml DOCUMENT ME!
|
315 |
* @param p DOCUMENT ME!
|
316 |
*
|
317 |
* @throws XMLException
|
318 |
* @throws DriverException
|
319 |
* @throws DriverIOException
|
320 |
*/
|
321 |
public abstract void setXMLEntity03(XMLEntity xml, Project p) |
322 |
throws XMLException, DriverException, DriverIOException;
|
323 |
|
324 |
/**
|
325 |
* DOCUMENT ME!
|
326 |
*
|
327 |
* @return DOCUMENT ME!
|
328 |
*/
|
329 |
public Project getProject() {
|
330 |
return project;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* DOCUMENT ME!
|
335 |
*
|
336 |
* @param project DOCUMENT ME!
|
337 |
*/
|
338 |
public void setProject(Project project, int index) { |
339 |
this.project = project;
|
340 |
this.index = index;
|
341 |
} |
342 |
public int getIndex() { |
343 |
return index;
|
344 |
} |
345 |
} |