Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/shp/ShpWriter.java
ShpWriter.java | ||
---|---|---|
9 | 9 |
import java.nio.charset.Charset; |
10 | 10 |
import java.sql.Types; |
11 | 11 |
|
12 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
12 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
|
13 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
14 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
15 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException; |
|
16 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
|
17 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
|
13 | 18 |
import com.iver.cit.gvsig.fmap.core.FShape; |
14 | 19 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
15 | 20 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
... | ... | |
19 | 24 |
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO; |
20 | 25 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPFileWrite; |
21 | 26 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException; |
22 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
23 | 27 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
24 | 28 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
25 | 29 |
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter; |
... | ... | |
27 | 31 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
28 | 32 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
29 | 33 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
30 |
import com.iver.utiles.xmlEntity.generate.Property; |
|
31 | 34 |
|
32 | 35 |
public class ShpWriter extends AbstractWriter implements ISpatialWriter { |
33 | 36 |
private String shpPath; |
... | ... | |
129 | 132 |
* @throws IOException |
130 | 133 |
* @throws DriverException |
131 | 134 |
*/ |
132 |
public void initialize(FLayer layer) throws EditionException{
|
|
135 |
public void initialize(FLayer layer) throws InitializeWriterException{
|
|
133 | 136 |
if (layer instanceof FLyrVect) |
134 | 137 |
{ |
135 | 138 |
FLyrVect lyrVect = (FLyrVect) layer; |
... | ... | |
138 | 141 |
myHeader = DbaseFileHeaderNIO.createDbaseHeader(sds); |
139 | 142 |
initialize(shpFile, lyrVect.getShapeType()); |
140 | 143 |
} catch (IOException e) { |
141 |
e.printStackTrace(); |
|
142 |
throw new EditionException(e); |
|
143 |
} catch (DriverException e) { |
|
144 |
e.printStackTrace(); |
|
145 |
throw new EditionException(e); |
|
144 |
throw new InitializeWriterException(getName(),e); |
|
145 |
} catch (ReadDriverException e) { |
|
146 |
throw new InitializeWriterException(getName(),e); |
|
146 | 147 |
} |
147 | 148 |
} |
148 | 149 |
else |
149 | 150 |
{ |
150 |
throw new EditionException("No se puede usar una capa que no es vectorial como modelo para escribir un shp.");
|
|
151 |
throw new InitializeWriterException(getName(),null);
|
|
151 | 152 |
} |
152 | 153 |
} |
153 | 154 |
/** |
154 | 155 |
* Useful to create a layer from scratch |
155 | 156 |
* Call setFile before using this function |
156 | 157 |
* @param lyrDef |
158 |
* @throws InitializeWriterException |
|
157 | 159 |
* @throws EditionException |
158 | 160 |
*/ |
159 |
public void initialize(ITableDefinition lyrDef) throws EditionException
|
|
161 |
public void initialize(ITableDefinition lyrDef) throws InitializeWriterException
|
|
160 | 162 |
{ |
161 | 163 |
super.initialize(lyrDef); |
162 | 164 |
myHeader = DbaseFileHeaderNIO.createDbaseHeader(lyrDef.getFieldsDesc()); |
163 | 165 |
try { |
164 | 166 |
initialize(shpFile, ((ILayerDefinition)lyrDef).getShapeType()); |
165 | 167 |
} catch (IOException e) { |
166 |
e.printStackTrace(); |
|
167 |
throw new EditionException(e); |
|
168 |
throw new InitializeWriterException(getName(),e); |
|
168 | 169 |
} |
169 | 170 |
} |
170 | 171 |
|
... | ... | |
209 | 210 |
} |
210 | 211 |
} |
211 | 212 |
|
212 |
public void preProcess() throws EditionException {
|
|
213 |
public void preProcess() throws StartWriterVisitorException {
|
|
213 | 214 |
// Por ahora solo escribimos los primeros bytes |
214 | 215 |
// de las cabeceras. Luego en el postprocess los escribiremos |
215 | 216 |
// correctamente, con el fullExtent y el numero de |
... | ... | |
235 | 236 |
fullExtent = null; |
236 | 237 |
|
237 | 238 |
} catch (IOException e) { |
238 |
e.printStackTrace(); |
|
239 |
throw new EditionException(e); |
|
239 |
throw new StartWriterVisitorException(getName(),e); |
|
240 | 240 |
} |
241 | 241 |
} |
242 | 242 |
|
243 | 243 |
|
244 | 244 |
} |
245 | 245 |
|
246 |
public void process(IRowEdited row) throws EditionException {
|
|
246 |
public void process(IRowEdited row) throws ProcessWriterVisitorException {
|
|
247 | 247 |
|
248 | 248 |
if (row.getStatus() == IRowEdited.STATUS_DELETED) return; |
249 | 249 |
|
... | ... | |
280 | 280 |
} |
281 | 281 |
|
282 | 282 |
} catch (IOException e) { |
283 |
e.printStackTrace(); |
|
284 |
throw new EditionException(e); |
|
283 |
throw new ProcessWriterVisitorException(getName(),e); |
|
285 | 284 |
} catch (ShapefileException e) { |
286 |
e.printStackTrace(); |
|
287 |
throw new EditionException(e); |
|
285 |
throw new ProcessWriterVisitorException(getName(),e); |
|
288 | 286 |
} |
289 | 287 |
|
290 | 288 |
} |
291 | 289 |
|
292 |
public void postProcess() throws EditionException {
|
|
290 |
public void postProcess() throws StopWriterVisitorException {
|
|
293 | 291 |
try { |
294 | 292 |
myHeader.setNumRecords(numRows); |
295 | 293 |
if (fullExtent == null) |
... | ... | |
300 | 298 |
dbfWrite = new DbaseFileWriterNIO(myHeader, |
301 | 299 |
(FileChannel) getWriteChannel(dbfPath)); |
302 | 300 |
} catch (IOException e) { |
303 |
e.printStackTrace(); |
|
304 |
throw new EditionException(e); |
|
301 |
throw new StopWriterVisitorException(getName(),e); |
|
305 | 302 |
} |
306 | 303 |
|
307 | 304 |
|
Also available in: Unified diff