Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLWriter.java
GMLWriter.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.geom.Rectangle2D; |
4 | 4 |
import java.io.File; |
5 |
import java.io.FileWriter; |
|
6 | 5 |
import java.io.IOException; |
7 | 6 |
|
8 | 7 |
import org.cresques.cts.IProjection; |
9 | 8 |
import org.geotools.feature.FeatureType; |
10 | 9 |
|
10 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
|
11 |
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException; |
|
12 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException; |
|
13 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
|
14 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
|
11 | 15 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
12 | 16 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
13 | 17 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
14 | 18 |
import com.iver.cit.gvsig.fmap.drivers.gml.GMLTypesConversor; |
15 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
16 | 19 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
17 | 20 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
18 | 21 |
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter; |
19 |
import com.iver.utiles.StringUtilities; |
|
20 | 22 |
import com.vividsolutions.jts.geom.Geometry; |
21 | 23 |
|
22 | 24 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
... | ... | |
63 | 65 |
* |
64 | 66 |
* $Id$ |
65 | 67 |
* $Log$ |
66 |
* Revision 1.6 2006-09-21 15:47:04 jorpiell |
|
68 |
* Revision 1.7 2007-03-06 17:08:56 caballero |
|
69 |
* Exceptions |
|
70 |
* |
|
71 |
* Revision 1.6 2006/09/21 15:47:04 jorpiell |
|
67 | 72 |
* Ya se pueden exportar ficheros a GML en Linux cuyo path tenga una may?scula |
68 | 73 |
* |
69 | 74 |
* Revision 1.5 2006/08/25 13:04:07 fjp |
... | ... | |
87 | 92 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
88 | 93 |
*/ |
89 | 94 |
public class GMLWriter extends AbstractWriter implements ISpatialWriter{ |
90 |
private File m_File = null;
|
|
95 |
private File m_File = null; |
|
91 | 96 |
private FeatureType featureType = null; |
92 |
private GMLFileCreator gmlFile = null;
|
|
97 |
private GMLFileCreator gmlFile = null; |
|
93 | 98 |
private GMLSchemaCreator gmlSchemaFileCreator = null; |
94 |
|
|
99 |
|
|
95 | 100 |
/** |
96 | 101 |
* Sets the output file |
97 | 102 |
* @param f |
... | ... | |
99 | 104 |
public void setFile(File f) { |
100 | 105 |
m_File = f; |
101 | 106 |
} |
102 |
|
|
107 |
|
|
103 | 108 |
/** |
104 | 109 |
* Sets the schema definition |
105 | 110 |
* @param lyrDef |
106 |
* @throws EditionException
|
|
107 |
* @throws Exception
|
|
111 |
* @throws EditionException |
|
112 |
* @throws Exception |
|
108 | 113 |
*/ |
109 |
public void setSchema(LayerDefinition lyrDef) throws EditionException{ |
|
114 |
public void setSchema(LayerDefinition lyrDef) throws SchemaEditionException{
|
|
110 | 115 |
try { |
111 | 116 |
featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef); |
112 |
|
|
117 |
|
|
113 | 118 |
String schemaPath = m_File.getName().replaceAll("\\.gml", ".xsd"); |
114 |
|
|
119 |
|
|
115 | 120 |
gmlFile = new GMLFileCreator(m_File,schemaPath); |
116 | 121 |
gmlFile.setAttibutes(lyrDef.getFieldsDesc()); |
117 |
|
|
122 |
|
|
118 | 123 |
schemaPath = m_File.getAbsolutePath().replaceAll("\\.gml", ".xsd"); |
119 |
|
|
124 |
|
|
120 | 125 |
gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath)); |
121 | 126 |
gmlSchemaFileCreator.createFile(lyrDef); |
122 | 127 |
} catch (Exception e) { |
123 |
// TODO Auto-generated catch block |
|
124 |
e.printStackTrace(); |
|
125 |
throw new EditionException(e.toString()); |
|
128 |
throw new SchemaEditionException(getName(),e); |
|
126 | 129 |
} |
127 | 130 |
} |
128 |
|
|
131 |
|
|
129 | 132 |
/** |
130 | 133 |
* Sets the geometry extend |
131 | 134 |
* @param extend |
... | ... | |
134 | 137 |
public void setBoundedBy(Rectangle2D extend,IProjection proj){ |
135 | 138 |
gmlFile.setBoundedBy(extend,proj); |
136 | 139 |
} |
137 |
|
|
140 |
|
|
138 | 141 |
/* |
139 | 142 |
* (non-Javadoc) |
140 | 143 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int) |
... | ... | |
157 | 160 |
*/ |
158 | 161 |
public void setFlatness(double flatness) { |
159 | 162 |
// TODO Auto-generated method stub |
160 |
|
|
163 |
|
|
161 | 164 |
} |
162 | 165 |
|
163 | 166 |
/* |
164 | 167 |
* (non-Javadoc) |
165 | 168 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess() |
166 | 169 |
*/ |
167 |
public void preProcess() throws EditionException {
|
|
170 |
public void preProcess() throws StartWriterVisitorException {
|
|
168 | 171 |
if (gmlFile == null){ |
169 |
new EditionException("The driver must be initialized using the setSchema method");
|
|
172 |
new StartWriterVisitorException(getName(),null);
|
|
170 | 173 |
} |
171 | 174 |
try { |
172 | 175 |
gmlFile.initialize(); |
173 |
|
|
176 |
|
|
174 | 177 |
} catch (IOException e) { |
175 |
// TODO Auto-generated catch block |
|
176 |
e.printStackTrace(); |
|
177 |
new EditionException(e.toString()); |
|
178 |
new StartWriterVisitorException(getName(),e); |
|
178 | 179 |
} |
179 | 180 |
} |
180 | 181 |
|
... | ... | |
182 | 183 |
* (non-Javadoc) |
183 | 184 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited) |
184 | 185 |
*/ |
185 |
public void process(IRowEdited row) throws EditionException {
|
|
186 |
public void process(IRowEdited row) throws ProcessWriterVisitorException {
|
|
186 | 187 |
Geometry geom = ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry(); |
187 |
try {
|
|
188 |
try { |
|
188 | 189 |
gmlFile.insertFeature(geom,row.getAttributes()); |
189 | 190 |
} catch (IOException e) { |
190 |
// TODO Auto-generated catch block |
|
191 |
e.printStackTrace(); |
|
192 |
throw new EditionException(e.toString()); |
|
193 |
} |
|
191 |
throw new ProcessWriterVisitorException(getName(),e); |
|
192 |
} |
|
194 | 193 |
} |
195 | 194 |
|
196 | 195 |
/* |
197 | 196 |
* (non-Javadoc) |
198 | 197 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess() |
199 | 198 |
*/ |
200 |
public void postProcess() throws EditionException {
|
|
199 |
public void postProcess() throws StopWriterVisitorException {
|
|
201 | 200 |
try { |
202 | 201 |
gmlFile.writeFile(); |
203 | 202 |
gmlSchemaFileCreator.writeFile(); |
204 | 203 |
} catch (IOException e) { |
205 |
// TODO Auto-generated catch block |
|
206 |
e.printStackTrace(); |
|
207 |
throw new EditionException(e.toString()); |
|
208 |
} |
|
204 |
throw new StopWriterVisitorException(getName(),e); |
|
205 |
} |
|
209 | 206 |
} |
210 | 207 |
|
211 | 208 |
/* |
212 | 209 |
* (non-Javadoc) |
213 | 210 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition) |
214 | 211 |
*/ |
215 |
public void initialize(ITableDefinition tableDefinition) throws EditionException {
|
|
212 |
public void initialize(ITableDefinition tableDefinition) throws InitializeWriterException {
|
|
216 | 213 |
super.initialize(tableDefinition); |
217 |
|
|
214 |
|
|
218 | 215 |
} |
219 | 216 |
|
220 | 217 |
/* |
... | ... | |
229 | 226 |
// TODO Auto-generated method stub |
230 | 227 |
return false; |
231 | 228 |
} |
232 |
|
|
229 |
|
|
233 | 230 |
public boolean canSaveEdits() { |
234 | 231 |
if (m_File.canWrite()) return true; |
235 | 232 |
return false; |
Also available in: Unified diff