Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/shp/MultiShpWriter.java

View differences:

MultiShpWriter.java
4 4
import java.util.ArrayList;
5 5
import java.util.Properties;
6 6

  
7
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
8
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException;
9
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
10
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException;
11
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
12
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException;
13
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
7 14
import com.iver.cit.gvsig.fmap.core.FShape;
8 15
import com.iver.cit.gvsig.fmap.core.IFeature;
9 16
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
10 17
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
11 18
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
12 19
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
13
import com.iver.cit.gvsig.fmap.edition.EditionException;
14 20
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
15 21
import com.iver.cit.gvsig.fmap.edition.ISchemaManager;
16 22
import com.iver.cit.gvsig.fmap.edition.IWriter;
......
20 26
/**
21 27
 * This writer wraps three ShpWriters, one for points, one for lines and one for
22 28
 * polygons geometry types. <br>
23
 * 
29
 *
24 30
 * It allows you to save a FLyrVect with MULTI shape type in SHP file format
25 31
 * (that doesnt allow to mix different geometry types). To do that, this IWriter
26 32
 * creates a different SHP file for any geometry type, in a transparent manner
......
36 42
 * writer.process(feature);
37 43
 * writer.postProcess();
38 44
 * </code>
39
 * 
45
 *
40 46
 */
41 47
public class MultiShpWriter implements IWriter {
42 48
	/**
......
62 68

  
63 69
	File pointsFile;
64 70

  
65
	public void preProcess() throws EditionException {
71
	public void preProcess() throws StartWriterVisitorException {
66 72
	}
67 73

  
68 74
	/**
69 75
	 * Returns all ShpWriter's created by this wrapper (only those wich writes a
70 76
	 * type of the processed geometries)
71
	 * 
77
	 *
72 78
	 * @return
73 79
	 */
74 80
	public IWriter[] getWriters() {
......
85 91
		return solution;
86 92
	}
87 93

  
88
	public void postProcess() throws EditionException {
94
	public void postProcess() throws StopWriterVisitorException {
89 95
		if (polygons != null)
90 96
			polygons.postProcess();
91 97
		if (lines != null)
......
97 103
	/**
98 104
	 * Give access to the Writer that processes polygon geometries (and creates
99 105
	 * it if it hasnt yet)
100
	 * 
106
	 *
101 107
	 * @return
102 108
	 * @throws EditionException
103 109
	 */
104
	private IWriter getPolygonsWriter() throws EditionException {
110
	private IWriter getPolygonsWriter() throws VisitorException {
105 111
		if (polygons == null) {
106 112
			polygons = new ShpWriter();
107 113
			// TODO Hacer que LayerDefinition sea cloneable
......
112 118
			polygonsFile = new File(file + "_POL.shp");
113 119
			newDefinition.setFile(polygonsFile);
114 120
			((ShpWriter) polygons).setFile(polygonsFile);
115
			polygons.initialize(newDefinition);
121
			try {
122
				polygons.initialize(newDefinition);
123
			} catch (InitializeWriterException e) {
124
				throw new ProcessWriterVisitorException(getName(),e);
125
			}
116 126

  
117
			getSchemaManager(polygons, polygonsFile)
118
					.createSchema(newDefinition);
119
			
127
			try {
128
				getSchemaManager(polygons, polygonsFile)
129
						.createSchema(newDefinition);
130
			} catch (SchemaEditionException e) {
131
				throw new ProcessWriterVisitorException(getName(),e);
132
			}
133

  
120 134
			//AZABALA: no si si es neceario
121 135
			polygons.preProcess();
122 136
		}
......
127 141
	 * Given a Writer, and the file where we want to save persistent features,
128 142
	 * it returns an associated ISchemaManager (whose responsability is to
129 143
	 * create the new schema-for files create the new files)
130
	 * 
144
	 *
131 145
	 * @param writer
132 146
	 * @param file
133 147
	 * @return
......
143 157
	 * of the initial. It is useful to avoid local changes made by individual
144 158
	 * Writers to the definition affects the others writers (for example, change
145 159
	 * the shape type of the writer)
146
	 * 
160
	 *
147 161
	 * @param definition
148 162
	 * @return
149 163
	 */
......
162 176
	/**
163 177
	 * Give access to the Writer that processes line geometries (and creates it
164 178
	 * if it hasnt yet)
165
	 * 
179
	 *
166 180
	 * @return
167 181
	 * @throws EditionException
168 182
	 */
169
	private IWriter getLinesWriter() throws EditionException {
183
	private IWriter getLinesWriter() throws VisitorException {
170 184
		if (lines == null) {
171 185
			lines = new ShpWriter();
172 186
			SHPLayerDefinition newDefinition = (SHPLayerDefinition) cloneDef(layerDefinition);
......
176 190
			linesFile = new File(file + "_LIN.shp");
177 191
			newDefinition.setFile(linesFile);
178 192
			((ShpWriter) lines).setFile(linesFile);
179
			lines.initialize(newDefinition);
180
			getSchemaManager(lines, linesFile).createSchema(newDefinition);
181
			lines.preProcess();
193
			try {
194
				lines.initialize(newDefinition);
195
				getSchemaManager(lines, linesFile).createSchema(newDefinition);
196
				lines.preProcess();
197
			} catch (InitializeWriterException e) {
198
				throw new ProcessWriterVisitorException(getName(),e);
199
			} catch (SchemaEditionException e) {
200
				throw new ProcessWriterVisitorException(getName(),e);
201
			}
182 202
		}
183 203
		return lines;
184 204
	}
......
186 206
	/**
187 207
	 * Give access to the Writer that processes point geometries (and creates it
188 208
	 * if it hasnt yet)
189
	 * 
209
	 *
190 210
	 * @return
191 211
	 * @throws EditionException
192 212
	 */
193 213

  
194
	private IWriter getPointsWriter() throws EditionException {
214
	private IWriter getPointsWriter() throws VisitorException{
195 215
		if (points == null) {
196 216
			points = new ShpWriter();
197 217
			SHPLayerDefinition newDefinition = (SHPLayerDefinition) cloneDef(layerDefinition);
......
201 221
			pointsFile = new File(file + "_PT.shp");
202 222
			newDefinition.setFile(pointsFile);
203 223
			((ShpWriter) points).setFile(pointsFile);
204
			points.initialize(newDefinition);
205

  
206
			getSchemaManager(points, pointsFile).createSchema(newDefinition);
207
			points.preProcess();
224
			try {
225
				points.initialize(newDefinition);
226
				getSchemaManager(points, pointsFile).createSchema(newDefinition);
227
			} catch (InitializeWriterException e) {
228
				throw new ProcessWriterVisitorException(getName(),e);
229
			} catch (SchemaEditionException e) {
230
				throw new ProcessWriterVisitorException(getName(),e);
231
			}
232
				points.preProcess();
208 233
		}
209 234
		return points;
210 235
	}
......
213 238
	 * Giving an edited row, writes it with the Writer associated to its
214 239
	 * geometry type
215 240
	 */
216
	public void process(IRowEdited row) throws EditionException {
241
	public void process(IRowEdited row) throws VisitorException {
217 242
		IFeature feature = (IFeature) row.getLinkedRow();
218 243
		int geometryType = feature.getGeometry().getGeometryType();
219 244
		switch (geometryType) {
......
235 260

  
236 261
	/**
237 262
	 * Sets the file where save the results
238
	 * 
263
	 *
239 264
	 * @param f
240 265
	 */
241 266
	public void setFile(File f) {
......
258 283
	}
259 284

  
260 285
	public void initialize(ITableDefinition layerDefinition)
261
			throws EditionException {
286
			throws InitializeWriterException {
262 287
		this.layerDefinition = (ILayerDefinition) layerDefinition;
263 288
	}
264 289

  
......
273 298
	public boolean canAlterTable() {
274 299
		return true;
275 300
	}
276
	public boolean canSaveEdits() {
277
		try {
278
			if (getPointsWriter().canSaveEdits())
301
	public boolean canSaveEdits() throws VisitorException {
302
		if (getPointsWriter().canSaveEdits())
279 303
			{
280 304
				if (getLinesWriter().canSaveEdits())
281 305
				{
......
283 307
						return true;
284 308
				}
285 309
			}
286
		} catch (EditionException e) {
287
			e.printStackTrace();
288
		}
289 310
		return false;
290 311
	}
291
	
312

  
292 313
	public boolean isWriteAll() {
293 314
		return true;
294 315
	}

Also available in: Unified diff