svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / castor / ProjectElement.java @ 652
History | View | Annotate | Download (5.33 KB)
1 |
package com.iver.cit.gvsig.project.castor; |
---|---|
2 |
|
3 |
import java.beans.PropertyChangeListener; |
4 |
import java.beans.PropertyChangeSupport; |
5 |
import java.io.Serializable; |
6 |
import java.text.DateFormat; |
7 |
import java.util.Date; |
8 |
|
9 |
import com.hardcode.driverManager.DriverLoadException; |
10 |
import com.iver.andami.messages.NotificationManager; |
11 |
import com.iver.cit.gvsig.fmap.DriverException; |
12 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
13 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
14 |
import com.iver.cit.gvsig.fmap.layers.DifferentVersionException; |
15 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
16 |
import com.iver.utiles.XMLEntity; |
17 |
|
18 |
|
19 |
/**
|
20 |
* Clase base de los elementos del proyecto (mapas, tablas y vistas)
|
21 |
*
|
22 |
* @author Fernando Gonz?lez Cort?s
|
23 |
*/
|
24 |
public abstract class ProjectElement implements Serializable { |
25 |
protected PropertyChangeSupport change; |
26 |
protected Project project;
|
27 |
protected String name; |
28 |
protected String creationDate; |
29 |
protected String owner; |
30 |
protected String comment; |
31 |
|
32 |
/**
|
33 |
* Creates a new ProjectElement object.
|
34 |
*/
|
35 |
public ProjectElement() {
|
36 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
37 |
change = new PropertyChangeSupport(this); |
38 |
} |
39 |
|
40 |
/**
|
41 |
* @see java.lang.Object#toString()
|
42 |
*/
|
43 |
public String toString() { |
44 |
return name;
|
45 |
} |
46 |
|
47 |
/**
|
48 |
* Obtiene el nombre del elemento
|
49 |
*
|
50 |
* @return
|
51 |
*/
|
52 |
public String getName() { |
53 |
return name;
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Establece el nombre del elemento
|
58 |
*
|
59 |
* @param string
|
60 |
*/
|
61 |
public void setName(String string) { |
62 |
String oldValue = name;
|
63 |
name = string; |
64 |
change.firePropertyChange("name", oldValue, name);
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Obtiene la fecha de creaci?n del elemento
|
69 |
*
|
70 |
* @return
|
71 |
*/
|
72 |
public String getCreationDate() { |
73 |
return creationDate;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Obtiene el propietario del elemento
|
78 |
*
|
79 |
* @return
|
80 |
*/
|
81 |
public String getOwner() { |
82 |
return owner;
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* Establece la fecha de creaci?n del elemento.
|
87 |
*
|
88 |
* @param string
|
89 |
*/
|
90 |
public void setCreationDate(String string) { |
91 |
creationDate = string; |
92 |
change.firePropertyChange("creationDate", creationDate, creationDate);
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Establece el propietario del elemento
|
97 |
*
|
98 |
* @param string
|
99 |
*/
|
100 |
public void setOwner(String string) { |
101 |
owner = string; |
102 |
change.firePropertyChange("owner", owner, owner);
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Obtiene los comentarios del proyecto
|
107 |
*
|
108 |
* @return
|
109 |
*/
|
110 |
public String getComment() { |
111 |
return comment;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Establece los comentarios del proyecto
|
116 |
*
|
117 |
* @param string
|
118 |
*/
|
119 |
public void setComment(String string) { |
120 |
comment = string; |
121 |
change.firePropertyChange("comment", comment, comment);
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* A?ade un listener para los cambios en las bounded properties
|
126 |
*
|
127 |
* @param listener
|
128 |
*/
|
129 |
public synchronized void addPropertyChangeListener( |
130 |
PropertyChangeListener listener) {
|
131 |
change.addPropertyChangeListener(listener); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* DOCUMENT ME!
|
136 |
*
|
137 |
* @return DOCUMENT ME!
|
138 |
* @throws DriverException
|
139 |
*/
|
140 |
public XMLEntity getXMLEntity() {
|
141 |
XMLEntity xml = new XMLEntity();
|
142 |
xml.putProperty("comment", comment);
|
143 |
xml.putProperty("creationDate", creationDate);
|
144 |
xml.putProperty("name", name);
|
145 |
xml.putProperty("owner", owner);
|
146 |
|
147 |
//xml.addChild(mapContext.getXMLEntity);
|
148 |
return xml;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* DOCUMENT ME!
|
153 |
*
|
154 |
* @param xml DOCUMENT ME!
|
155 |
* @param p DOCUMENT ME!
|
156 |
*
|
157 |
* @return DOCUMENT ME!
|
158 |
* @throws DifferentVersionException
|
159 |
* @throws CancelationException
|
160 |
* @throws DifferentVersionException
|
161 |
* @throws ClassNotFoundException
|
162 |
* @throws InstantiationException
|
163 |
* @throws IllegalAccessException
|
164 |
* @throws DriverIOException
|
165 |
* @throws DriverLoadException
|
166 |
*/
|
167 |
public static ProjectElement createFromXML(XMLEntity xml, Project p) throws XMLException, DriverException{ |
168 |
ProjectElement pe = null;
|
169 |
|
170 |
Class clase;
|
171 |
try {
|
172 |
clase = Class.forName(xml.getStringProperty("nameClass")); |
173 |
pe = (ProjectElement) clase.newInstance(); |
174 |
} catch (ClassNotFoundException e) { |
175 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
176 |
e); |
177 |
} catch (InstantiationException e) { |
178 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
179 |
e); |
180 |
} catch (IllegalAccessException e) { |
181 |
NotificationManager.addError("Clase de ProjectElement no reconocida",
|
182 |
e); |
183 |
} |
184 |
|
185 |
pe.setComment(xml.getStringProperty("comment"));
|
186 |
pe.setCreationDate(xml.getStringProperty("creationDate"));
|
187 |
pe.setName(xml.getStringProperty("name"));
|
188 |
pe.setOwner(xml.getStringProperty("owner"));
|
189 |
pe.project = p; |
190 |
|
191 |
pe.setXMLEntity(xml,p); |
192 |
|
193 |
return pe;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* DOCUMENT ME!
|
198 |
*
|
199 |
* @param xml DOCUMENT ME!
|
200 |
* @throws IllegalAccessException
|
201 |
* @throws InstantiationException
|
202 |
* @throws ClassNotFoundException
|
203 |
* @throws DriverIOException
|
204 |
* @throws DriverLoadException
|
205 |
* @throws XMLException
|
206 |
*/
|
207 |
public abstract void setXMLEntity(XMLEntity xml,Project p)throws XMLException, DriverException; |
208 |
} |