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

View differences:

DbfWriter.java
8 8
import java.sql.Types;
9 9
import java.util.ArrayList;
10 10

  
11
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
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.IRow;
12 16
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
13 17
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
14 18
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO;
15 19
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO;
16
import com.iver.cit.gvsig.fmap.edition.EditionException;
17
import com.iver.cit.gvsig.fmap.edition.IFieldManager;
18 20
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
19 21
import com.iver.cit.gvsig.fmap.edition.fieldmanagers.AddFieldCommand;
20 22
import com.iver.cit.gvsig.fmap.edition.fieldmanagers.FieldCommand;
......
40 42
	private FBitSet selection = null;
41 43

  
42 44
	private FieldDescription[] originalFields;
43
	
45

  
44 46
	public DbfWriter() {
45 47
		super();
46 48
		this.capabilities.setProperty("FieldNameMaxLength","10");
......
72 74
		return channel;
73 75
	}
74 76

  
75
	public void preProcess() throws EditionException {
77
	public void preProcess() throws StartWriterVisitorException {
76 78
		// Por ahora solo escribimos los primeros bytes
77 79
		// de las cabeceras. Luego en el postprocess los escribiremos
78 80
		// correctamente, con el fullExtent y el numero de
......
88 90
				numRows = 0;
89 91

  
90 92
			} catch (IOException e) {
91
				e.printStackTrace();
92
				throw new EditionException(e);
93
				throw new StartWriterVisitorException(getName(),e);
93 94
			}
94 95
		}
95 96

  
96 97
	}
97 98

  
98
	public void process(IRowEdited row) throws EditionException {
99
		IRow rowEdit = (IRow) row.getLinkedRow();
99
	public void process(IRowEdited row) throws ProcessWriterVisitorException {
100
		IRow rowEdit = row.getLinkedRow();
100 101
//		System.err.println("DBFWriter: " + row.getStatus() + " numRows = "
101 102
//				+ numRows);
102 103
		switch (row.getStatus()) {
......
111 112
				numRows++;
112 113

  
113 114
			} catch (IOException e) {
114
				e.printStackTrace();
115
				throw new EditionException(e);
115
				throw new ProcessWriterVisitorException(getName(),e);
116 116
			}
117 117

  
118 118
		}
119 119

  
120 120
	}
121 121

  
122
	public void postProcess() throws EditionException {
122
	public void postProcess() throws StopWriterVisitorException {
123 123
		try {
124 124
			myHeader.setNumRecords(numRows);
125 125
			dbfWrite = new DbaseFileWriterNIO(myHeader,
126 126
					(FileChannel) getWriteChannel(dbfPath));
127 127

  
128 128
		} catch (IOException e) {
129
			e.printStackTrace();
130
			throw new EditionException(e);
129
			throw new StopWriterVisitorException(getName(),e);
131 130
		}
132 131

  
133 132
	}
......
160 159
	}
161 160

  
162 161
	public void initialize(ITableDefinition tableDefinition)
163
			throws EditionException {
162
			throws InitializeWriterException {
164 163
		super.initialize(tableDefinition);
165 164
		originalFields = tableDefinition.getFieldsDesc();
166 165
		myHeader = DbaseFileHeaderNIO.createDbaseHeader(tableDefinition
167 166
				.getFieldsDesc());
168 167
		if (dbfPath == null) {
169
			throw new EditionException(
170
					"DBFWriter: You need to use setFile before initialize.");
168
			throw new InitializeWriterException(getName(),null);
171 169
		}
172 170

  
173 171
	}
......
176 174
		return originalFields;
177 175
	}
178 176

  
179
	public boolean alterTable() throws EditionException {
177
	public boolean alterTable() throws StartWriterVisitorException {
180 178
		FieldDescription[] fieldsDesc =getFields();
181 179

  
182 180
		myHeader = DbaseFileHeaderNIO.createDbaseHeader(fieldsDesc);
......
192 190
//
193 191
//			}
194 192
		} catch (IOException e) {
195
			throw new EditionException(e);
193
			throw new StartWriterVisitorException(getName(),e);
196 194
		}
197 195
		return true;
198 196
	}
......
221 219
	public void renameField(String antName, String newName) {
222 220
		RenameFieldCommand c = new RenameFieldCommand(antName, newName);
223 221
		fieldCommands.add(c);
224
		
222

  
225 223
	}
226 224

  
227 225
	public FieldDescription[] getFields() {
......
261 259
					}
262 260
				}
263 261

  
264
			}			
265
			
262
			}
263

  
266 264
		}
267 265
		return (FieldDescription[]) aux.toArray(new FieldDescription[0]);
268 266
	}
......
272 270
	}
273 271

  
274 272
	public boolean canSaveEdits() {
275
		File aux = new File(dbfPath);		
273
		File aux = new File(dbfPath);
276 274
		if (aux.canWrite()) return true;
277 275
		return false;
278 276
	}

Also available in: Unified diff