Statistics
| Revision:

root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.prov / org.gvsig.gpe.prov.gml / src / main / java / org / gvsig / gpe / prov / gml / GmlLibrary.java @ 263

History | View | Annotate | Download (6.67 KB)

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.prov.gml;
29

    
30
import org.gvsig.compat.CompatLibrary;
31
import org.gvsig.gpe.lib.api.GPELibrary;
32
import org.gvsig.gpe.lib.api.GPELocator;
33
import org.gvsig.gpe.lib.api.GPEManager;
34
import org.gvsig.gpe.lib.api.exceptions.ParserNotRegisteredException;
35
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerNotRegisteredException;
36
import org.gvsig.gpe.lib.spi.GPEProviderLocator;
37
import org.gvsig.gpe.lib.spi.GPEProviderManager;
38
import org.gvsig.tools.library.AbstractLibrary;
39
import org.gvsig.tools.library.LibraryException;
40
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
41
import org.gvsig.xmlpull.lib.api.XmlPullLibrary;
42
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator;
43
import org.gvsig.xmlschema.lib.api.XMLSchemaManager;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

    
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
49
 */
50
public class GmlLibrary extends AbstractLibrary  {
51
        private static final Logger logger = LoggerFactory.getLogger(GmlLibrary.class);
52
        private static final String GMLFORMAT = "gml";
53
        
54
        public void doRegistration() {
55
                registerAsServiceOf(GPELibrary.class);
56
                require(CompatLibrary.class);
57
                require(XmlPullLibrary.class);
58
        }
59

    
60
        protected void doInitialize() throws LibraryException {
61
                // Nothing to do
62
        }
63

    
64
        protected void doPostInitialize() throws LibraryException {
65
                // Validate there is any implementation registered.
66
                GPEManager gpeManager = GPELocator.getGPEManager();
67
                if (gpeManager == null) {
68
                        throw new ReferenceNotRegisteredException(
69
                                        GPELocator.GPE_MANAGER_NAME, GPELocator.getInstance());
70
                }
71

    
72
                GPEProviderManager gpeProviderManager = GPEProviderLocator.getGPEProviderManager();
73
                if (gpeProviderManager == null) {
74
                        throw new ReferenceNotRegisteredException(
75
                                        GPEProviderLocator.GPE_PROVIDER_MANAGER_NAME, GPEProviderLocator.getInstance());
76
                }
77

    
78
                gpeManager.setProperty(GmlProperties.DECIMAL, ".");
79
                gpeManager.setProperty(GmlProperties.COORDINATES_SEPARATOR, ",");
80
                gpeManager.setProperty(GmlProperties.TUPLES_SEPARATOR, " ");
81
                gpeManager.setProperty(GmlProperties.DEFAULT_FEATURECOLLECTION, "FeatureCollection");
82
                gpeManager.setProperty(GmlProperties.DEFAULT_FEATURE, "Feature");
83
                gpeManager.setProperty(GmlProperties.SRS_BASED_ON_XML, new Boolean(true));
84

    
85
                try {
86
                        gpeProviderManager.addGpeParser("GMLSFP0", "Parser for GML", org.gvsig.gpe.prov.gml.parser.GPEGmlSFP0Parser.class);                        
87
                } catch (ParserNotRegisteredException e) {
88
                        logger.error("Impossible to register a GML parser");
89
                }
90
                try {                        
91
                        gpeProviderManager.addGpeWriterHandlerImplementor("GMLSFP0", "Writer for GML", org.gvsig.gpe.prov.gml.writer.GPEGmlSFP0WriterHandlerImplementor.class);
92
                } catch (WriterHandlerNotRegisteredException e) {
93
                        logger.error("Impossible to register a GML writer");
94
                }
95

    
96
                XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager();
97
                if (xmlSchemaManager != null) {
98
                        //Register dataTypes
99
                        xmlSchemaManager.registerFormat("text/xml; subtype=gml/2.0.0", GMLFORMAT);
100
                        xmlSchemaManager.registerFormat("text/xml; subtype=gml/2.1.0", GMLFORMAT);
101
                        xmlSchemaManager.registerFormat("text/xml; subtype=gml/3.2", GMLFORMAT);
102

    
103
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Point", XMLSchemaManager.POINT);
104
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LineString", XMLSchemaManager.LINESTRING);
105
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LinearRing", XMLSchemaManager.POLYGON);
106
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Polygon", XMLSchemaManager.POLYGON);
107
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiGeometry", XMLSchemaManager.MULTIGEOMETRY);
108
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPoint", XMLSchemaManager.MULTIPOINT);
109
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiLineString", XMLSchemaManager.MULTILINESTRING);
110
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPolygon", XMLSchemaManager.MULTIPOLYGON);
111
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiCurve", XMLSchemaManager.MULTILINESTRING);
112
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiSurface", XMLSchemaManager.MULTIPOLYGON);
113
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Curve", XMLSchemaManager.LINESTRING);
114
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Surface", XMLSchemaManager.POLYGON);
115
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "PointPropertyType", XMLSchemaManager.POINT);
116
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LineStringPropertyType", XMLSchemaManager.LINESTRING);
117
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LinearRingPropertyType", XMLSchemaManager.POLYGON);
118
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "PolygonPropertyType", XMLSchemaManager.POLYGON);
119
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiGeometryPropertyType", XMLSchemaManager.MULTIGEOMETRY);
120
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPointPropertyType", XMLSchemaManager.MULTIPOINT);
121
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiLineStringPropertyType", XMLSchemaManager.MULTILINESTRING);
122
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPolygonPropertyType", XMLSchemaManager.MULTIPOLYGON);
123
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiCurvePropertyType", XMLSchemaManager.MULTILINESTRING);
124
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiSurfacePropertyType", XMLSchemaManager.MULTIPOLYGON);
125
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "CurvePropertyType", XMLSchemaManager.LINESTRING);
126
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "SurfacePropertyType", XMLSchemaManager.POLYGON);
127
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "GeometryPropertyType", XMLSchemaManager.GEOMETRY);
128
                        xmlSchemaManager.addParserGeometryType(GMLFORMAT, "GeometryAssociationType", XMLSchemaManager.GEOMETRY);
129
                }
130
        }
131
}
132