Revision 39157

View differences:

tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/gpe/GPELibraryExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe;
29

  
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.andami.plugins.Extension;
32
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
33
import org.gvsig.fmap.mapcontext.MapContextLocator;
34

  
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class GPELibraryExtension extends Extension{
40
		
41
	public void execute(String actionCommand) {
42
	}
43

  
44
	public void initialize() {
45
		IconThemeHelper.registerIcon("layer", "layer-icon-gpe", this);
46
	}	
47

  
48
	public void postInitialize() {
49
		MapContextLocator.getMapContextManager().registerIconLayer(GPEStoreProvider.NAME, "layer-icon-gpe");
50
	}
51

  
52
	public boolean isEnabled() {
53
		return false;
54
	}
55

  
56
	public boolean isVisible() {
57
		return false;
58
	}
59

  
60
}
61

  
0 62

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/GPEStoreParameters.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.dal.store.gpe;
29

  
30
import java.io.File;
31

  
32
import org.cresques.cts.IProjection;
33
import org.gvsig.fmap.dal.DataStoreParameters;
34
import org.gvsig.fmap.dal.FileHelper;
35
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
36
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
37
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
38
import org.gvsig.fmap.geom.primitive.Envelope;
39
import org.gvsig.tools.dynobject.DelegatedDynObject;
40
import org.gvsig.tools.dynobject.DynStruct;
41

  
42
/**
43
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
44
 */
45
public class GPEStoreParameters extends AbstractDataParameters implements
46
DataStoreParameters, FilesystemStoreParameters {
47

  
48
    public static final String PARAMETERS_DEFINITION_NAME = "GPEStoreParameters";
49

  
50
    private static final String FILE_PARAMETER_NAME = "File";
51
    private static final String CRS_PARAMETER_NAME = "CRS";
52
    private static final String ENVELOPE_PARAMETER_NAME = "Envelope";
53

  
54
    private DelegatedDynObject parameters;
55

  
56
    public GPEStoreParameters() {
57
        this(PARAMETERS_DEFINITION_NAME);
58
    }
59

  
60
    protected GPEStoreParameters(String parametersDefinitionName) {
61
        this(parametersDefinitionName, GPEStoreProvider.NAME);
62
    }
63

  
64
    public GPEStoreParameters(String parametersDefinitionName, String name) {
65
        super();
66
        this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
67
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);       
68
    }
69

  
70
    protected static void registerParametersDefinition(){ 
71
        DynStruct dynStruct = FileHelper.registerParametersDefinition(
72
            GPEStoreParameters.PARAMETERS_DEFINITION_NAME,
73
            GPEStoreParameters.class, "GPEParameters.xml");
74
        dynStruct.addDynFieldObject("Envelope").setClassOfValue(Envelope.class).setMandatory(false);
75
    }
76

  
77
    protected DelegatedDynObject getDelegatedDynObject() {
78
        return parameters;
79
    }
80

  
81
    public String getDataStoreName() {
82
        return GPEStoreProvider.NAME;
83
    }
84

  
85
    public String getDescription() {
86
        return GPEStoreProvider.DESCRIPTION;
87
    }
88

  
89
    public boolean isValid() {
90
        return (this.getFile() != null);
91
    }
92

  
93
    public File getFile() {
94
        return (File) this.getDynValue(FILE_PARAMETER_NAME);
95
    }
96

  
97
    public void setFile(File file) {
98
        this.setDynValue(FILE_PARAMETER_NAME, file);
99
    }	
100

  
101
    public String getFileName() {
102
        return this.getFile().getAbsolutePath();
103
    }
104

  
105
    public void setFileName(String fileName) {
106
        this.setDynValue(FILE_PARAMETER_NAME, fileName);
107
    }
108

  
109
    public IProjection getCRS() {
110
        return (IProjection) this.getDynValue(CRS_PARAMETER_NAME);
111
    }
112

  
113
    public void setCRS(IProjection srs) {
114
        this.setDynValue(CRS_PARAMETER_NAME, srs);
115
    }
116

  
117
    public void setCRS(String srs) {
118
        this.setDynValue(CRS_PARAMETER_NAME, srs);
119
    }
120

  
121
    public Envelope getEnvelope() {
122
        return (Envelope) this.getDynValue(ENVELOPE_PARAMETER_NAME);
123
    }
124

  
125
    public void setEnvelope(Envelope envelope) {
126
        this.setDynValue(ENVELOPE_PARAMETER_NAME, envelope);
127
    }
128
}
0 129

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/handlers/FmapErrorHandler.java
1
package org.gvsig.fmap.dal.store.gpe.handlers;
2

  
3
import org.gvsig.gpe.lib.impl.parser.GPEErrorHandler;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id$
48
 * $Log$
49
 *
50
 */
51
/**
52
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
53
 */
54
public class FmapErrorHandler extends GPEErrorHandler{
55

  
56
}
0 57

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/handlers/FmapContentHandler.java
1
package org.gvsig.fmap.dal.store.gpe.handlers;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.Iterator;
8
import java.util.List;
9
import java.util.Map;
10

  
11
import org.cresques.cts.IProjection;
12
import org.gvsig.fmap.dal.DataTypes;
13
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
14
import org.gvsig.fmap.dal.feature.EditableFeatureType;
15
import org.gvsig.fmap.dal.feature.Feature;
16
import org.gvsig.fmap.dal.feature.FeatureType;
17
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
18
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
19
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
20
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
21
import org.gvsig.fmap.dal.store.gpe.model.GPEElement;
22
import org.gvsig.fmap.dal.store.gpe.model.GPEFeature;
23
import org.gvsig.fmap.geom.Geometry;
24
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
25
import org.gvsig.fmap.geom.Geometry.TYPES;
26
import org.gvsig.fmap.geom.GeometryLocator;
27
import org.gvsig.fmap.geom.GeometryManager;
28
import org.gvsig.fmap.geom.aggregate.MultiCurve;
29
import org.gvsig.fmap.geom.aggregate.MultiPoint;
30
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
31
import org.gvsig.fmap.geom.aggregate.MultiSurface;
32
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34
import org.gvsig.fmap.geom.primitive.Curve;
35
import org.gvsig.fmap.geom.primitive.Envelope;
36
import org.gvsig.fmap.geom.primitive.GeneralPathX;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.geom.primitive.Primitive;
39
import org.gvsig.fmap.geom.primitive.Surface;
40
import org.gvsig.gpe.lib.api.parser.IAttributesIterator;
41
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
42
import org.gvsig.gpe.lib.api.parser.IGPEErrorHandler;
43
import org.gvsig.gpe.lib.impl.parser.GPEContentHandler;
44
import org.jfree.util.Log;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
48
 *
49
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
50
 *
51
 * This program is free software; you can redistribute it and/or
52
 * modify it under the terms of the GNU General Public License
53
 * as published by the Free Software Foundation; either version 2
54
 * of the License, or (at your option) any later version.
55
 *
56
 * This program is distributed in the hope that it will be useful,
57
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
58
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59
 * GNU General Public License for more details.
60
 *
61
 * You should have received a copy of the GNU General Public License
62
 * along with this program; if not, write to the Free Software
63
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
64
 *
65
 * For more information, contact:
66
 *
67
 *  Generalitat Valenciana
68
 *   Conselleria d'Infraestructures i Transport
69
 *   Av. Blasco Ib??ez, 50
70
 *   46010 VALENCIA
71
 *   SPAIN
72
 *
73
 *      +34 963862235
74
 *   gvsig@gva.es
75
 *      www.gvsig.gva.es
76
 *
77
 *    or
78
 *
79
 *   IVER T.I. S.A
80
 *   Salamanca 50
81
 *   46005 Valencia
82
 *   Spain
83
 *
84
 *   +34 963163400
85
 *   dac@iver.es
86
 */
87
/* CVS MESSAGES:
88
 *
89
 * $Id$
90
 * $Log$
91
 *
92
 */
93
/**
94
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
95
 */
96
public class FmapContentHandler extends GPEContentHandler {
97
    private static final Logger LOG = LoggerFactory.getLogger(FmapContentHandler.class);
98

  
99
    private HashMap featureSet = null;
100
    private EditableFeatureType featureType = null;
101
    private FeatureStoreProviderServices store = null;
102
    private GPEStoreProvider storeProvider = null;
103
    private GeometryManager geomManager = GeometryLocator.getGeometryManager();
104
    private int featureId = 0;
105
    private Envelope envelope = null;
106
    private File file = null;
107
    private IProjection srs = null;
108
    private int geometryType = 0;
109

  
110
    public FmapContentHandler(IGPEErrorHandler errorHandler, FeatureStoreProviderServices store,
111
        GPEStoreProvider storeProvider, File file, IProjection srs, int geometryType) {
112
        super();
113
        setErrorHandler(errorHandler);
114
        this.store = store;
115
        this.storeProvider = storeProvider;
116
        this.file = file;
117
        this.srs = srs;
118
        this.geometryType = geometryType;
119
    }
120

  
121
    public int getFeaturesCount(){
122
        return featureSet.size();
123
    }
124

  
125
    public Feature getFeatureAt(int index){
126
        return (Feature)featureSet.get(new Integer(index));
127
    }
128

  
129
    public EditableFeatureType getFeatureType(){
130
        return featureType;
131
    }
132

  
133

  
134
    /**
135
     * @return the featureSet
136
     */
137
    public HashMap getFeatureSet() {
138
        return featureSet;
139
    }
140

  
141
    /*
142
     * (non-Javadoc)
143
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLayer(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object, java.lang.Object)
144
     */
145
    public Object startLayer(String id, String namespace, String name,
146
        String description, String srs, IAttributesIterator iterator, Object parentLayer, Object box) {
147
        if (featureSet == null){
148
            featureSet = new HashMap();
149
        }
150
        if (envelope == null){
151
            try {
152
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
153
            } catch (CreateEnvelopeException e) {
154
                Log.error("Error creating the envelope", e);
155
            }
156
        }
157
        return featureSet;
158
    }
159

  
160
    /*
161
     * (non-Javadoc)
162
     * @see org.gvsig.gpe.IGPEContentHandler#endLayer(java.lang.Object)
163
     */
164
    public void endLayer(Object layer) {
165
        if (featureType == null){
166
            createFeatureType(null);
167
        }
168
        storeProvider.setEnvelope(envelope);
169
    }
170

  
171
    /*
172
     * (non-Javadoc)
173
     * @see org.gvsig.gpe.parser.GPEContentHandler#startPoint(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
174
     */
175
    public Object startPoint(String id, ICoordinateIterator coords, String srs) {
176
        return createPoint(coords);
177
    }
178

  
179
    private Point createPoint(ICoordinateIterator coords){
180
        double[] buffer = new double[coords.getDimension()];
181
        try {
182
            coords.hasNext();
183
            coords.next(buffer);
184
            Point point = null;
185
            if (coords.getDimension() == 2){
186
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
187
            }else if (coords.getDimension() == 3){
188
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
189
            }
190
            for (int i=0 ; i<buffer.length ; i++){
191
                point.setCoordinateAt(i, buffer[i]);
192
            }
193
            return point;
194
        } catch (IOException e) {
195
            getErrorHandler().addError(e);
196
        } catch (CreateGeometryException e) {
197
            getErrorHandler().addError(e);
198
        }
199
        return null;
200
    }
201

  
202
    private Point createPoint(double[] buffer){
203
        try {
204
            Point point = null;
205
            if (buffer.length == 2){
206
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
207
            }else if (buffer.length == 3){
208
                point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
209
            }
210
            for (int i=0 ; i<buffer.length ; i++){
211
                point.setCoordinateAt(i, buffer[i]);
212
            }
213
            return point;
214
        }catch (CreateGeometryException e) {
215
            getErrorHandler().addError(e);
216
        }
217
        return null;
218
    }
219

  
220

  
221
    /* (non-Javadoc)
222
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLineString(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
223
     */
224
    public Object startLineString(String id, ICoordinateIterator coords,
225
        String srs) {
226
        return createCurve(coords);
227
    }
228

  
229
    private Curve createCurve(ICoordinateIterator coords){
230
        GeneralPathX gp = createGeneralPathX(coords);
231
        try {
232
            Curve curve = null;
233
            if (coords.getDimension() == 2){
234
                curve = (Curve) geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
235
            }else if (coords.getDimension() == 3){
236
                curve = (Curve) geomManager.create(TYPES.CURVE, SUBTYPES.GEOM3D);
237
            }
238
            curve.setGeneralPath(gp);
239
            return curve;
240
        } catch (CreateGeometryException e) {
241
            getErrorHandler().addError(e);
242
        }
243
        return null;
244
    }
245

  
246
    private GeneralPathX createGeneralPathX(ICoordinateIterator coords){
247
        GeneralPathX gp = new GeneralPathX();
248
        if (coords == null){
249
            return gp;
250
        }
251
        double[] buffer = new double[coords.getDimension()];
252
        try {
253
            if (coords.hasNext()){
254
                coords.next(buffer);
255
                gp.moveTo(buffer[0], buffer[1]);
256
            }
257
            while(coords.hasNext()){
258
                coords.next(buffer);
259
                gp.lineTo(buffer[0], buffer[1]);
260
            }
261
        } catch (IOException e) {
262
            getErrorHandler().addError(e);
263
        }
264
        return gp;
265
    }
266

  
267
    /* (non-Javadoc)
268
     * @see org.gvsig.gpe.parser.GPEContentHandler#startPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
269
     */
270

  
271
    public Object startPolygon(String id, ICoordinateIterator coords, String srs) {
272
        return createSurface(coords);
273
    }
274

  
275
    private Surface createSurface(ICoordinateIterator coords){
276
        GeneralPathX gp = createGeneralPathX(coords);
277
        try {
278
            Surface surface = null;
279
            if (coords.getDimension() == 2){
280
                surface = (Surface) geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
281
            }else if (coords.getDimension() == 3){
282
                surface = (Surface) geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM3D);
283
            }
284
            surface.setGeneralPath(gp);
285
            return surface;
286
        } catch (CreateGeometryException e) {
287
            getErrorHandler().addError(e);
288
        }
289
        return null;
290
    }
291

  
292

  
293
    /* (non-Javadoc)
294
     * @see org.gvsig.gpe.parser.GPEContentHandler#startInnerPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
295
     */
296
    public Object startInnerPolygon(String id, ICoordinateIterator coords,
297
        String srs) {
298
        return createSurface(coords);
299
    }
300

  
301
    /*
302
     * (non-Javadoc)
303
     * @see org.gvsig.gpe.IGPEContentHandler#addGeometryToFeature(java.lang.Object, java.lang.Object)
304
     */
305
    public void addGeometryToFeature(Object geometry, Object feature) {
306
        ((GPEFeature)feature).setGeometry((Geometry)geometry);
307
    }
308

  
309
    /*
310
     * (non-Javadoc)
311
     * @see org.gvsig.gpe.IGPEContentHandler#addBboxToLayer(java.lang.Object, java.lang.Object)
312
     */
313
    public void addBboxToLayer(Object bbox, Object layer) {
314
        //		if (layer != null){
315
        //		GPEBBox gpeBBox = (GPEBBox)bbox;
316
        //		if (gpeBBox.getSrs() != null){
317
        //		IProjection projection = null;
318
        //		try{
319
        //		CRSFactory.getCRS(gpeBBox.getSrs());
320
        //		}catch(Exception e){
321
        //		//If the CRS factory has an error.
322
        //		}
323
        //		if ((projection != null) && (!(projection.equals(((FLayer)layer).getProjection())))){
324
        //		//TODO reproyectar la bbox y asignarsela a la capa
325
        //		}
326
        //		}
327
        //		((IGPEDriver)layer).setExtent(gpeBBox.getBbox2D());
328
        //		}
329
    }
330

  
331
    /*
332
     * (non-Javadoc)
333
     * @see org.gvsig.gpe.IGPEContentHandler#addElementToFeature(java.lang.Object, java.lang.Object)
334
     */
335
    public void addElementToFeature(Object element, Object feature) {
336
        GPEElement gpeElement = (GPEElement)element;
337
        ((GPEFeature)feature).addElement(gpeElement);
338
    }
339

  
340
    /*
341
     * (non-Javadoc)
342
     * @see org.gvsig.gpe.IGPEContentHandler#addFeatureToLayer(java.lang.Object, java.lang.Object)
343
     */
344
    public void addFeatureToLayer(Object feature, Object layer) {
345
        GPEFeature gpefeature = (GPEFeature)feature;
346
        Envelope currentEnvelope = gpefeature.getEnvelope();
347
        if (featureType == null){
348
            createFeatureType(gpefeature);
349

  
350
            //Initialize the envelope
351
            try {
352
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
353
            } catch (CreateEnvelopeException e) {
354
                getErrorHandler().addError(e);
355
            }
356
            //Calculates the envelope
357
            envelope = currentEnvelope;
358
        }else{
359
            //Calculates the envelope
360
            if (currentEnvelope != null){
361
                envelope.add(currentEnvelope);
362
            }
363
        }
364
        //If it is null is a multilayer: not supported yet
365
        if (layer != null){
366
            FeatureProvider data = new DefaultFeatureProvider(featureType.getNotEditableCopy(), storeProvider.createNewOID());
367
            Map elements = gpefeature.getelements();
368
            Iterator keys = elements.keySet().iterator();
369
            String gid = gpefeature.getId();              
370
            data.setOID(gid);              
371
            while (keys.hasNext()){
372
                String elementName = (String)keys.next();
373
                data.set(elementName, ((GPEElement)elements.get(elementName)).getValue());
374
            }
375
            data.setDefaultGeometry(gpefeature.getGeometry());
376
            data.set(featureType.getDefaultGeometryAttributeIndex(), gpefeature.getGeometry());
377
            ((HashMap)layer).put(gid, data);
378
        }
379
    }
380

  
381
    private void createFeatureType(GPEFeature gpefeature){
382
        featureType = store.createFeatureType();
383
        
384
        //Adding the Geometry field
385
        EditableFeatureAttributeDescriptor attributeDescriptor = featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(geometryType);
386
        attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM2D);
387
        attributeDescriptor.setSRS(srs);
388
        featureType.setDefaultGeometryAttributeName("the_geom");
389
        
390
        //Adding the ID
391
        EditableFeatureAttributeDescriptor ed = featureType.add("gid", DataTypes.LONG);
392
        ed.setSize(10);
393

  
394
        featureType.setHasOID(true);
395

  
396
        if (gpefeature != null){
397
            Map elements = gpefeature.getelements();
398
            Iterator keys = elements.keySet().iterator();
399
            while (keys.hasNext()){
400
                String elementName = (String)keys.next();
401
                if (!elementName.equals("the_geom")){
402
                    ed = featureType.add(elementName, DataTypes.STRING);
403
                    ed.setSize(80);
404
                }
405
            }
406
        }
407

  
408
        FeatureType defaultType = featureType.getNotEditableCopy();
409
        List types = new ArrayList(1);
410
        types.add(defaultType);
411
        this.store.setFeatureTypes(types, defaultType);
412
    }
413

  
414
    /*
415
     * (non-Javadoc)
416
     * @see org.gvsig.gpe.IGPEContentHandler#addInnerPolygonToPolygon(java.lang.Object, java.lang.Object)
417
     */
418
    public void addInnerPolygonToPolygon(Object innerPolygon, Object Polygon) {
419
        //((Geometry)Polygon).addGeometry((GPEGeometry)innerPolygon);
420
    }
421

  
422
    /*
423
     * (non-Javadoc)
424
     * @see org.gvsig.gpe.IGPEContentHandler#addNameToFeature(java.lang.String, java.lang.Object)
425
     */
426
    public void addNameToFeature(String name, Object feature) {
427

  
428
    }
429

  
430
    /*
431
     * (non-Javadoc)
432
     * @see org.gvsig.gpe.IGPEContentHandler#addParentElementToElement(java.lang.Object, java.lang.Object)
433
     */
434
    public void addParentElementToElement(Object parent, Object element) {
435

  
436
    }
437

  
438
    /*
439
     * (non-Javadoc)
440
     * @see org.gvsig.gpe.IGPEContentHandler#addSrsToLayer(java.lang.String, java.lang.Object)
441
     */
442
    public void addSrsToLayer(String srs, Object Layer) {
443
        //		this.srs = srs;
444
    }
445

  
446

  
447
    /* (non-Javadoc)
448
     * @see org.gvsig.gpe.parser.GPEContentHandler#startBbox(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
449
     */
450
    public Object startBbox(String id, ICoordinateIterator coords, String srs) {
451
        Envelope envelope = null;
452
        try {
453
            if (coords.getDimension() == 2){
454
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
455
            }else if (coords.getDimension() == 3){
456
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
457
            }
458
            double[] buffer = new double[coords.getDimension()];
459

  
460
            if (coords.hasNext()){
461
                coords.next(buffer);
462
                envelope.setLowerCorner(createPoint(buffer));
463
            }
464
            if (coords.hasNext()){
465
                coords.next(buffer);
466
                envelope.setUpperCorner(createPoint(buffer));
467
            }
468
        } catch (IOException e) {
469
            getErrorHandler().addError(e);
470
        } catch (CreateEnvelopeException e) {
471
            getErrorHandler().addError(e);
472
        }
473
        return envelope;
474
    }
475

  
476
    /*
477
     * (non-Javadoc)
478
     * @see org.gvsig.gpe.parser.GPEContentHandler#startElement(java.lang.String, java.lang.String, java.lang.Object, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
479
     */
480
    public Object startElement(String namespace, String name, Object value,
481
        IAttributesIterator attributesIterator,	Object parentElement) {
482
        return new GPEElement(name, value, (GPEElement)parentElement);
483
    }
484

  
485
    /*
486
     * (non-Javadoc)
487
     * @see org.gvsig.gpe.parser.GPEContentHandler#startFeature(java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
488
     */
489
    public Object startFeature(String id, String namespace, String name,
490
        IAttributesIterator attributes, Object layer){
491
        String sId;
492
        if (id == null){
493
            sId = new String(new Long(featureId).toString());			
494
        }else{
495
            sId = id;
496
        }
497
        featureId++;
498
        //Check the xml schema...
499
        //		for (int i=0 ; i<schemas.size() ; i++){
500
        //			IXSSchema schema = schemas.get(i);
501
        //			IXSElementDeclaration element = schema.getElementDeclarationByName(namespace, name);
502
        //			if (element != null){
503
        //				featureType = store.createFeatureType();
504
        //				IXSTypeDefinition type = element.getTypeDefinition();
505
        //				if (type instanceof IXSComplexTypeDefinition){
506
        //					IXSComplexTypeDefinition complexType = (IXSComplexTypeDefinition)type;
507
        //					complexType.getContentType().
508
        //				}
509
        //
510
        //				featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(TYPES.GEOMETRY);
511
        //				featureType.setDefaultGeometryAttributeName("the_geom");
512
        //				featureType.setHasOID(true);
513
        //				while (keys.hasNext()){
514
        //					String elementName = (String)keys.next();
515
        //					featureType.add(elementName, DataTypes.STRING);
516
        //				}
517
        //				FeatureType defaultType = featureType.getNotEditableCopy();
518
        //				List types = new ArrayList(1);
519
        //				types.add(defaultType);
520
        //				this.store.setFeatureTypes(types, defaultType);
521
        //
522
        //				//Initialize the envelope
523
        //				try {
524
        //					envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
525
        //				} catch (CreateEnvelopeException e) {
526
        //					getErrorHandler().addError(e);
527
        //				}
528
        //			}
529
        //		}
530
        return new GPEFeature(sId,
531
            name, name);
532
    }
533

  
534
    /* (non-Javadoc)
535
     * @see org.gvsig.gpe.parser.GPEContentHandler#startLinearRing(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
536
     */
537
    public Object startLinearRing(String id, ICoordinateIterator coords,
538
        String srs) {
539
        return createSurface(coords);
540
    }
541

  
542
    /*
543
     * (non-Javadoc)
544
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPoint(java.lang.String, java.lang.String)
545
     */
546
    public Object startMultiPoint(String id, String srs) {
547
        try {
548
            return geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
549
        } catch (CreateGeometryException e) {
550
            getErrorHandler().addError(e);
551
        }
552
        return null;
553
    }
554

  
555
    /*
556
     * (non-Javadoc)
557
     * @see org.gvsig.gpe.IGPEContentHandler#addPointToMultiPoint(java.lang.Object, java.lang.Object)
558
     */
559
    public void addPointToMultiPoint(Object point, Object multiPoint) {
560
        ((MultiPoint)multiPoint).addPoint((Point)point);
561
    }
562

  
563
    /*
564
     * (non-Javadoc)
565
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiLineString(java.lang.String, java.lang.String)
566
     */
567
    public Object startMultiLineString(String id, String srs) {
568
        super.startMultiLineString(id, srs);
569
        try {
570
            return geomManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
571
        } catch (CreateGeometryException e) {
572
            getErrorHandler().addError(e);
573
        }
574
        return null;
575
    }
576

  
577
    /*
578
     * (non-Javadoc)
579
     * @see org.gvsig.gpe.IGPEContentHandler#addLineStringToMultiLineString(java.lang.Object, java.lang.Object)
580
     */
581
    public void addLineStringToMultiLineString(Object lineString, Object multiLineString) {
582
        ((MultiCurve)multiLineString).addCurve((Curve)lineString);
583
    }
584

  
585
    /*
586
     * (non-Javadoc)
587
     * @see org.gvsig.gpe.IGPEContentHandler#startMultiPolygon(java.lang.String, java.lang.String)
588
     */
589
    public Object startMultiPolygon(String id, String srs) {
590
        super.startMultiPolygon(id, srs);
591
        try {
592
            return geomManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
593
        } catch (CreateGeometryException e) {
594
            getErrorHandler().addError(e);
595
        }
596
        return null;
597
    }
598

  
599
    /*
600
     * (non-Javadoc)
601
     * @see org.gvsig.gpe.IGPEContentHandler#addPolygonToMultiPolygon(java.lang.Object, java.lang.Object)
602
     */
603
    public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) {
604
        ((MultiSurface)multiPolygon).addSurface((Surface)polygon);
605
    }
606

  
607
    /* (non-Javadoc)
608
     * @see org.gvsig.gpe.GPEContentHandler#addCurveToMultiCurve(java.lang.Object, java.lang.Object)
609
     */
610
    public void addCurveToMultiCurve(Object curve, Object multiCurve) {
611
        ((MultiCurve)multiCurve).addCurve((Curve)curve);
612
    }
613

  
614
    /* (non-Javadoc)
615
     * @see org.gvsig.gpe.GPEContentHandler#addSegmentToCurve(java.lang.Object, java.lang.Object)
616
     */
617
    public void addSegmentToCurve(Object segment, Object curve) {
618
        ((Curve)curve).addVertex((Point)segment);
619
    }
620

  
621
    /* (non-Javadoc)
622
     * @see org.gvsig.gpe.parser.GPEContentHandler#startCurve(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
623
     */
624
    public Object startCurve(String id, ICoordinateIterator coords, String srs) {
625
        return createCurve(coords);
626
    }
627

  
628
    /* (non-Javadoc)
629
     * @see org.gvsig.gpe.GPEContentHandler#startCurve(java.lang.String, java.lang.String)
630
     */
631
    public Object startCurve(String id, String srs) {
632
        return createCurve(null);
633
    }
634

  
635
    /* (non-Javadoc)
636
     * @see org.gvsig.gpe.GPEContentHandler#startMultiCurve(java.lang.String, java.lang.String)
637
     */
638
    public Object startMultiCurve(String id, String srs) {
639
        try {
640
            return geomManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
641
        } catch (CreateGeometryException e) {
642
            getErrorHandler().addError(e);
643
        }
644
        return null;
645
    }
646

  
647
    /* (non-Javadoc)
648
     * @see org.gvsig.gpe.GPEContentHandler#addGeometryToMultiGeometry(java.lang.Object, java.lang.Object)
649
     */
650
    public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) {
651
        ((MultiPrimitive)multiGeometry).addPrimitive((Primitive)geometry);
652
    }
653

  
654
    /* (non-Javadoc)
655
     * @see org.gvsig.gpe.GPEContentHandler#startMultiGeometry(java.lang.String, java.lang.String)
656
     */
657
    public Object startMultiGeometry(String id, String srs) {
658
        try {
659
            return geomManager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D);
660
        } catch (CreateGeometryException e) {
661
            getErrorHandler().addError(e);
662
        }
663
        return null;
664
    }
665

  
666
    /**
667
     * @return a new OID
668
     */
669
    public Object createNewOID() {
670
        featureId++;
671
        return String.valueOf(featureId);
672
    }	
673

  
674
    /**
675
     * @param envelope the envelope to set
676
     */
677
    public void setEnvelope(Envelope envelope) {
678
        this.envelope = envelope;
679
    }
680

  
681
    /**
682
     * @param featureType the featureType to set
683
     */
684
    public void setFeatureType(EditableFeatureType featureType) {
685
        this.featureType = featureType;
686
    }
687
}
0 688

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/handlers/FmapContentHandlerCreationException.java
1
package org.gvsig.fmap.dal.store.gpe.handlers;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
import org.gvsig.tools.exception.BaseException;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 *
53
 */
54
/**
55
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
56
 */
57
public class FmapContentHandlerCreationException extends BaseException{
58
	private static final long serialVersionUID = -6021604626521668293L;
59
	
60
	public FmapContentHandlerCreationException(){
61
		initialize();
62
	}
63
	
64
	public FmapContentHandlerCreationException(Throwable e){
65
		initialize();
66
		initCause(e);
67
	}
68
	
69
	protected Map values() {
70
		return new HashMap();
71
	}
72
	
73
	/**
74
	 * Initialize the properties
75
	 */
76
	private void initialize() {
77
		messageKey = "gpe_lgvsig_contentHandler_error";
78
		formatString = "Error creating the contentHandler for" +
79
				"Fmap";
80
		code = serialVersionUID;
81
	}
82

  
83
}
0 84

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/model/GPEElement.java
1
package org.gvsig.fmap.dal.store.gpe.model;
2

  
3
import java.util.HashMap;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id$
48
 * $Log$
49
 *
50
 */
51
/**
52
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
53
 */
54
public class GPEElement {
55
	private String name = null;
56
	private Object value = null;
57
	private HashMap subElements = null;
58
	
59
	public GPEElement(String name, Object value) {
60
		super();
61
		this.name = name;
62
		this.value = value;
63
		subElements = new HashMap();
64
	}
65
	
66
	public GPEElement(String name, Object value, GPEElement parentElement) {
67
		this(name,value);
68
		//If it is a complex value
69
		if (parentElement != null){
70
			parentElement.addChildElement(this);			
71
		}
72
	}	
73
	
74
	/**
75
	 * It adds a new child element
76
	 * @param children
77
	 * The element to add
78
	 */
79
	public void addChildElement(GPEElement children){
80
		subElements.put(children.getName(), children);
81
	}
82
	
83
	/**
84
	 * @return the name
85
	 */
86
	public String getName() {
87
		return name;
88
	}
89
	
90
	/**
91
	 * @return the value
92
	 */
93
	public Object getValue() {
94
		if (subElements.size() > 0){
95
//			ComplexValue cValue = ValueFactory.createComplexValue(name);
96
//			Iterator it = subElements.keySet().iterator();
97
//			while(it.hasNext()){
98
//				GPEElement element = (GPEElement)subElements.get(it.next());
99
//				cValue.put(element.getName(), element.getValue());
100
//			}
101
//			return cValue;
102
		}
103
		return value;		
104
	}
105
}
0 106

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/model/GPEFeature.java
1
package org.gvsig.fmap.dal.store.gpe.model;
2

  
3
import java.util.LinkedHashMap;
4

  
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.geom.GeometryLocator;
7
import org.gvsig.fmap.geom.GeometryManager;
8
import org.gvsig.fmap.geom.exception.CreateGeometryException;
9
import org.gvsig.fmap.geom.primitive.Envelope;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

  
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id$
56
 * $Log$
57
 *
58
 */
59
/**
60
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
61
 */
62
public class GPEFeature {
63
	private static final GeometryManager GEOMETRY_MANAGER = GeometryLocator.getGeometryManager();
64
	private static final Logger LOG = LoggerFactory.getLogger(GPEFeature.class);
65
	
66
    private static int idFeature = 0;
67
	private Geometry geometry = null;
68
	private LinkedHashMap elements = null;
69
	private String id = null;
70
	private String name = null;
71
	private String typeName = null;
72
	
73
	public GPEFeature(String id, String name, String typeName) {
74
		this();
75
		this.id = id;		
76
		this.name = name;
77
		this.typeName = typeName;		
78
	}	
79

  
80
	public GPEFeature(){
81
		elements = new LinkedHashMap();		
82
	}
83

  
84
	/**
85
	 * @return the id
86
	 */
87
	public String getId() {
88
		return id;
89
	}
90

  
91
	/**
92
	 * @param id the id to set
93
	 */
94
	public void setId(String id) {
95
		this.id = id;
96
	}
97

  
98
	/**
99
	 * @return the geometry
100
	 */
101
	public Geometry getGeometry() {
102
		if (geometry == null){
103
		    try {
104
	            this.geometry = GEOMETRY_MANAGER.create(Geometry.TYPES.NULL, Geometry.SUBTYPES.GEOM3D);
105
	        } catch (CreateGeometryException e) {
106
	            LOG.error("Not possible to create a geometry", e);
107
	        }
108
		}
109
	    return geometry;
110
	}
111

  
112
	/**
113
	 * @param geometry the geometry to set
114
	 */
115
	public void setGeometry(Geometry geometry) {
116
		this.geometry = geometry;
117
	}
118

  
119
	/**
120
	 * @return the elements
121
	 */
122
	public LinkedHashMap getelements() {
123
		return elements;
124
	}
125

  
126
	/**
127
	 * @param elements the elements to set
128
	 */
129
	public void setElements(LinkedHashMap elements) {
130
		this.elements = elements;
131
	}
132
	
133
	/**
134
	 * It adds a new element
135
	 * @param element
136
	 * The element to add
137
	 */
138
	public void addElement(GPEElement element){
139
		elements.put(element.getName(), element);
140
	}
141

  
142
	/**
143
	 * @return the name
144
	 */
145
	public String getName() {
146
		return name;
147
	}
148

  
149
	/**
150
	 * @return the typeName
151
	 */
152
	public String getTypeName() {
153
		return typeName;
154
	}
155
	
156
	/**
157
	 * Initialize the feature id
158
	 */
159
	public static void initIdFeature(){
160
		idFeature = 0;
161
	}
162

  
163
	public Envelope getEnvelope() {
164
		if (geometry == null){
165
			return null;
166
		}
167
		return geometry.getEnvelope();
168
	}
169
}
0 170

  
tags/v2_0_0_Build_2057/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/DALGPELibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.dal.store.gpe;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.gvsig.fmap.dal.DALFileLibrary;
34
import org.gvsig.fmap.dal.DALFileLocator;
35
import org.gvsig.fmap.dal.DALLibrary;
36
import org.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.DataTypes;
38
import org.gvsig.fmap.dal.FileHelper;
39
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.fmap.geom.GeometryLocator;
42
import org.gvsig.fmap.geom.GeometryManager;
43
import org.gvsig.fmap.geom.operation.writegml2.CurveWriteGml2Operation;
44
import org.gvsig.fmap.geom.operation.writegml2.MultiCurveWriteGml2Operation;
45
import org.gvsig.fmap.geom.operation.writegml2.MultiPointWriteGml2Operation;
46
import org.gvsig.fmap.geom.operation.writegml2.MultiSurfaceWriteGml2Operation;
47
import org.gvsig.fmap.geom.operation.writegml2.PointWriteGml2Operation;
48
import org.gvsig.fmap.geom.operation.writegml2.SurfaceWriteGml2Operation;
49
import org.gvsig.fmap.geom.operation.writegml2.WriteGml2Operation;
50
import org.gvsig.metadata.exceptions.MetadataException;
51
import org.gvsig.tools.library.AbstractLibrary;
52
import org.gvsig.tools.library.LibraryException;
53
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
54
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator;
55
import org.gvsig.xmlschema.lib.api.XMLSchemaManager;
56

  
57
/**
58
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
59
 */
60
public class DALGPELibrary extends AbstractLibrary {
61
	
62
    @Override
63
    public void doRegistration() {
64
        registerAsServiceOf(DALLibrary.class);
65
        require(DALFileLibrary.class);
66
    }
67

  
68
	protected void doInitialize() throws LibraryException {
69
		// Do nothing
70
	}
71

  
72
	protected void doPostInitialize() throws LibraryException {
73

  
74
		List exs = new ArrayList();
75

  
76
		GPEStoreParameters.registerParametersDefinition();
77
		
78
		try {
79
			FileHelper.registerMetadataDefinition(
80
					GPEStoreProvider.METADATA_DEFINITION_NAME,
81
					GPEStoreProvider.class, "GPEMetadata.xml");
82
		} catch (MetadataException e) {
83
			exs.add(e);
84
		}
85

  
86

  
87
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
88
		.getDataManager();
89

  
90
		if (!dataman.getStoreProviders().contains(GPEStoreProvider.NAME)) {
91
			dataman.registerStoreProvider(GPEStoreProvider.NAME,
92
					GPEStoreProvider.class, GPEStoreParameters.class);
93
		}
94

  
95
		DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
96
				GPEStoreProvider.NAME, GPEStoreProvider.DESCRIPTION,
97
				GPEFileSystemServerProvider.class);
98
		
99
		// Validate there is any implementation registered.
100
		XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager();
101
		if (xmlSchemaManager == null) {
102
			exs.add(new ReferenceNotRegisteredException(
103
					XMLSchemaLocator.XMLSCHEMA_MANAGER_NAME, XMLSchemaLocator
104
							.getInstance()));
105
		}
106
		
107
		//Register the application types in gpe. GPE uses the DAL types like internal types
108
		xmlSchemaManager.registerAppDataType(DataTypes.UNKNOWN, DataTypes.UNKNOWN);
109
		xmlSchemaManager.registerAppDataType(DataTypes.BOOLEAN, DataTypes.BOOLEAN);
110
		xmlSchemaManager.registerAppDataType(DataTypes.BYTE, DataTypes.BYTE);
111
		xmlSchemaManager.registerAppDataType(DataTypes.CHAR, DataTypes.CHAR);
112
		xmlSchemaManager.registerAppDataType(DataTypes.INT, DataTypes.INT);
113
		xmlSchemaManager.registerAppDataType(DataTypes.LONG, DataTypes.LONG);
114
		xmlSchemaManager.registerAppDataType(DataTypes.FLOAT, DataTypes.FLOAT);
115
		xmlSchemaManager.registerAppDataType(DataTypes.DOUBLE, DataTypes.DOUBLE);
116
		xmlSchemaManager.registerAppDataType(DataTypes.STRING, DataTypes.STRING);
117
		xmlSchemaManager.registerAppDataType(DataTypes.DATE, DataTypes.DATE);
118
		xmlSchemaManager.registerAppDataType(DataTypes.TIME, DataTypes.TIME);
119
		xmlSchemaManager.registerAppDataType(DataTypes.TIMESTAMP, DataTypes.TIMESTAMP);
120
		xmlSchemaManager.registerAppDataType(DataTypes.GEOMETRY, DataTypes.GEOMETRY);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff