Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extGPE-gvSIG / src-test / org / gvsig / fmap / drivers / gpe / writer / v2 / GPEWriterTest.java @ 18292

History | View | Annotate | Download (6.1 KB)

1
package org.gvsig.fmap.drivers.gpe.writer.v2;
2

    
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6

    
7
import junit.framework.TestCase;
8

    
9
import org.cresques.cts.IProjection;
10
import org.gvsig.fmap.drivers.gpe.writer.ExportTask;
11
import org.gvsig.gpe.GPEErrorHandler;
12
import org.gvsig.gpe.GPEErrorHandlerTest;
13
import org.gvsig.gpe.GPERegister;
14
import org.gvsig.gpe.exceptions.GPEWriterHandlerCreationException;
15
import org.gvsig.gpe.exceptions.GPEWriterHandlerRegisterException;
16
import org.gvsig.gpe.writers.GPEWriterHandler;
17

    
18
import com.iver.cit.gvsig.fmap.MapContext;
19
import com.iver.cit.gvsig.fmap.ViewPort;
20
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
21
import com.iver.cit.gvsig.fmap.layers.FLayer;
22

    
23
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
24
 *
25
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
26
 *
27
 * This program is free software; you can redistribute it and/or
28
 * modify it under the terms of the GNU General Public License
29
 * as published by the Free Software Foundation; either version 2
30
 * of the License, or (at your option) any later version.
31
 *
32
 * This program is distributed in the hope that it will be useful,
33
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35
 * GNU General Public License for more details.
36
 *
37
 * You should have received a copy of the GNU General Public License
38
 * along with this program; if not, write to the Free Software
39
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
40
 *
41
 * For more information, contact:
42
 *
43
 *  Generalitat Valenciana
44
 *   Conselleria d'Infraestructures i Transport
45
 *   Av. Blasco Ib??ez, 50
46
 *   46010 VALENCIA
47
 *   SPAIN
48
 *
49
 *      +34 963862235
50
 *   gvsig@gva.es
51
 *      www.gvsig.gva.es
52
 *
53
 *    or
54
 *
55
 *   IVER T.I. S.A
56
 *   Salamanca 50
57
 *   46005 Valencia
58
 *   Spain
59
 *
60
 *   +34 963163400
61
 *   dac@iver.es
62
 */
63
/* CVS MESSAGES:
64
 *
65
 * $Id$
66
 * $Log$
67
 *
68
 */
69
/**
70
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
71
 */
72
public abstract class GPEWriterTest extends TestCase {
73
        private String gpeWritersFile = "config" + File.separatorChar +
74
        "writer.properties";
75
        private String gpeParsersFile = "config" + File.separatorChar +
76
        "parser.properties";
77
        private MapContext mapContext = null;
78
        private GPEWriterHandler writerHandler = null;
79
        private GPEErrorHandler errorHandler = null;
80
        private String fileName = "testdata" + File.separatorChar + "output";
81
                        
82
        /*
83
         * (non-Javadoc)
84
         * @see junit.framework.TestCase#setUp()
85
         */
86
        public void setUp() throws FileNotFoundException, IOException, GPEWriterHandlerRegisterException{
87
//                LayerFactory.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
88
//                LayerFactory.setWritersPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
89
//                System.out.println("****************READERS****************");
90
//                for (int i=0 ; i<LayerFactory.getDM().getDriverNames().length ; i++){
91
//                        System.out.println(LayerFactory.getDM().getDriverNames()[i]);
92
//                }
93
//                System.out.println("****************WRITERS****************");
94
//                for (int i=0 ; i<LayerFactory.getWM().getWriterNames().length ; i++){
95
//                        System.out.println(LayerFactory.getWM().getWriterNames()[i]);
96
//                }
97
                System.out.println("*************** GPE register *************");
98
                GPERegister.addParsersFile(new File(gpeParsersFile));
99
                GPERegister.addWritersFile(new File(gpeWritersFile));
100
                //Register the writer that is going to be used
101
                GPERegister.addGpeWriterHandler(getGPEWriterHandlerName(),
102
                                getGPEWriterHandlerDescription(),
103
                                getGPEWriterHandlerClass());
104
        }
105
        
106
        public void testWrite() throws Exception{
107
                FLayer layer = getLayerToWrite();                                
108
                ExportTask task = new ExportTask(getLayerToWrite(),
109
                                getWriterHandler(),
110
                                getMapContext());
111
                task.run();
112
        }
113
        
114
        /*
115
         * (non-Javadoc)
116
         * @see junit.framework.TestCase#tearDown()
117
         */
118
        public void tearDown(){
119
                GPEErrorHandler error = getErrorHandler();
120
                for (int i=0 ; i<error.getErrorsSize() ; i++){
121
                        System.out.println(error.getErrorAt(i));
122
                }
123
                assertEquals(error.getErrorsSize(),0);
124
                for (int i=0 ; i<error.getWarningsSize() ; i++){
125
                        System.out.println(error.getWarningAt(i));
126
                }
127
        }
128
        
129
        /**
130
         * @return the writer handler to use
131
         */
132
        protected abstract Class getGPEWriterHandlerClass();
133

    
134
        protected GPEWriterHandler getWriterHandler() throws GPEWriterHandlerCreationException, FileNotFoundException{
135
                if (writerHandler == null){
136
                        writerHandler = GPERegister.createWriter(getGPEWriterHandlerName());
137
                        writerHandler.setFormat(getFormat());
138
                        writerHandler.setVersion(getVersion());
139
                        writerHandler.setErrorHandler(getErrorHandler());
140
                        writerHandler.setFileName(fileName);
141
                }
142
                return writerHandler;
143
        }
144
        
145
        /**
146
         * Each test must to return its parser name
147
         * to register it before to start the parsing
148
         * process
149
         */
150
        public String getGPEWriterHandlerName(){
151
                return "FORMAT VERSION";
152
        }
153
        
154
        /**
155
         * Each test must to return its parser description
156
         * to register it before to start the parsing
157
         * process
158
         */
159
        public String getGPEWriterHandlerDescription(){
160
                return "default writer handler description";
161
        }
162
        
163
        /**
164
         * Create the layer that will be written
165
         * @return
166
         * The Layer
167
         * @throws Exception
168
         */
169
        protected abstract FLayer getLayerToWrite() throws Exception;
170
        
171
        /**
172
         * @return the mapContext
173
         */
174
        protected MapContext getMapContext() {
175
                if (mapContext == null){
176
                        IProjection proj = CRSFactory.getCRS(getSRS());
177
                        ViewPort vp = new ViewPort(proj);
178
                        mapContext = new MapContext(vp);
179
                }
180
                return mapContext;
181
        }
182
                
183
        /**
184
         * @return the mapcontext SRS. If you want to cahnge it
185
         * you have to override this method
186
         */
187
        protected String getSRS(){
188
                return "EPSG:23030";
189
        }        
190
        
191
        /**
192
         * Gets the file format. The deafult writer
193
         * format will be used by default
194
         * @return
195
         */
196
        public String getFormat(){
197
                return null;
198
        }
199
        
200
        /**
201
         * Gets the file format. The deafult writer
202
         * version will be used by default
203
         * @return
204
         */
205
        public String getVersion(){
206
                return null;
207
        }
208
        
209
        /**
210
         * @return the errorHandler
211
         */
212
        public GPEErrorHandler getErrorHandler() {
213
                if (errorHandler == null){
214
                        errorHandler = new GPEErrorHandlerTest();
215
                }
216
                return errorHandler;
217
        }
218
        
219
}