Revision 11247 trunk/libraries/libGPE/src-test/org/gvsig/gpe/writers/GPEWriterBaseTest.java

View differences:

GPEWriterBaseTest.java
60 60
 *
61 61
 * $Id$
62 62
 * $Log$
63
 * Revision 1.3  2007-04-17 06:27:20  jorpiell
63
 * Revision 1.4  2007-04-19 07:23:20  jorpiell
64
 * Add the add methods to teh contenhandler and change the register mode
65
 *
66
 * Revision 1.3  2007/04/17 06:27:20  jorpiell
64 67
 * Changed the default filename
65 68
 *
66 69
 * Revision 1.2  2007/04/14 16:06:35  jorpiell
......
80 83
 */
81 84
public abstract class GPEWriterBaseTest extends TestCase{
82 85
	private String filename = "testdata/FILETEMP";
83
	private GPEWriterHandler handler = null;
86
	private GPEWriterHandler writerHandler = null;
84 87
	private GPEContentHandler contenHandler = null;
85 88
	private GPEErrorHandler errorHandler = null;
86 89
	private GPEParser parser = null;
......
91 94
	 */
92 95
	public void setUp() throws Exception{
93 96
		GPEDefaults.setProperty(GPEDefaults.DEFAULT_FILE_NAME, filename);
94
		GPERegister.addGpeDriver(getGPEParserName(), 
95
				new GPEContentHandlerTest(), 
96
				new GPEErrorHandlerTest());
97
		handler = GPERegister.getWriter(getFormat());
97
		//Register the parser
98
		GPERegister.addGpeParser(getGPEParserName(), 
99
				getGPEParserDescription(), 
100
				getGPEParserClass());
101
		//Register the writer
102
		GPERegister.addGpeWriterHandler(getGPEWriterHandlerName(),
103
				getGPEWriterHandlerDescription(),
104
				getGPEWriterHandlerClass());
98 105
	}
99 106
	
100 107
	/**
......
112 119
	 */
113 120
	public void testWriter() throws Exception{
114 121
		writeObjects();
115
		File outputFile = handler.getFile();
116
		parser = GPERegister.getParser(outputFile);
117
		parser.parse(outputFile);
122
		File outputFile = writerHandler.getOutputFile();
123
		//The file must exist
124
		parser = GPERegister.createParser(outputFile);
125
		parser.parse(getContenHandler(),getErrorHandler() ,outputFile);
118 126
		readObjects();
119 127
	}
120 128
	
121 129
	/**
122
	 * Gets the file format
123
	 * @return
124
	 */
125
	public abstract String getFormat();
126
	
127
	/**
128 130
	 * This method write somo objects into the writer handler
129 131
	 */
130 132
	public abstract void writeObjects();
......
140 142
	 * to register it before to start the parsing
141 143
	 * process
142 144
	 */
143
	public abstract String getGPEParserName();
145
	public String getGPEWriterHandlerName(){
146
		return "FORMAT VERSION";
147
	}
144 148
	
145 149
	/**
150
	 * Each test must to return its parser description
151
	 * to register it before to start the parsing
152
	 * process
153
	 */
154
	public String getGPEWriterHandlerDescription(){
155
		return "default writer handler description";
156
	}
157
	
158
	/**
159
	 * Each test must to return its parser class
160
	 * that will be used to create new parsers.
161
	 */
162
	public abstract Class getGPEWriterHandlerClass();
163
	
164
	
165
	/**
166
	 * Each test must to return its parser name
167
	 * to register it before to start the parsing
168
	 * process
169
	 */
170
	public String getGPEParserName(){
171
		return "FORMAT VERSION";
172
	}
173
	
174
	/**
175
	 * Each test must to return its parser description
176
	 * to register it before to start the parsing
177
	 * process
178
	 */
179
	public String getGPEParserDescription(){
180
		return "default parser description";
181
	}
182
	
183
	/**
184
	 * Each test must to return its parser class
185
	 * that will be used to create new parsers.
186
	 */
187
	public abstract Class getGPEParserClass();
188
	
189
	/**
190
	 * Gets the file format. The deafult writer
191
	 * format will be used by default
192
	 * @return
193
	 */
194
	public String getFormat(){
195
		return null;
196
	}
197
	
198
	/**
199
	 * Gets the file format. The deafult writer
200
	 * version will be used by default
201
	 * @return
202
	 */
203
	public String getVersion(){
204
		return null;
205
	}
206
	/**
146 207
	 * It creates a Random bbox coordinates. It return 
147 208
	 * 10 coordinates 
148 209
	 * @return
......
205 266
	 * @return the handler
206 267
	 */
207 268
	public GPEWriterHandler getWriterHandler() {
208
		return handler;
269
		if (writerHandler == null){
270
			try {
271
				writerHandler = GPERegister.createWriter(getGPEWriterHandlerName());
272
				writerHandler.setFormat(getFormat());
273
				writerHandler.setVersion(getVersion());
274
				writerHandler.setErrorHandler(getErrorHandler());
275
			} catch (Exception e) {
276
				//never throwed
277
				e.printStackTrace();
278
			}			
279
		}
280
		return writerHandler;
209 281
	}
210 282

  
211 283
	/**

Also available in: Unified diff