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 @ 1103
History | View | Annotate | Download (6.75 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.Locator; |
41 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
42 |
import org.gvsig.xmlpull.lib.api.XmlPullLibrary; |
43 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
44 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
/**
|
49 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
50 |
*/
|
51 |
public class GmlLibrary extends AbstractLibrary { |
52 |
private static final Logger logger = LoggerFactory.getLogger(GmlLibrary.class); |
53 |
private static final String GMLFORMAT = "gml"; |
54 |
|
55 |
@Override
|
56 |
public void doRegistration() { |
57 |
registerAsServiceOf(GPELibrary.class); |
58 |
require(CompatLibrary.class); |
59 |
require(XmlPullLibrary.class); |
60 |
} |
61 |
|
62 |
@Override
|
63 |
protected void doInitialize() throws LibraryException { |
64 |
// Nothing to do
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
protected void doPostInitialize() throws LibraryException { |
69 |
// Validate there is any implementation registered.
|
70 |
GPEManager gpeManager = GPELocator.getGPEManager(); |
71 |
if (gpeManager == null) { |
72 |
throw new ReferenceNotRegisteredException( |
73 |
GPELocator.GPE_MANAGER_NAME, GPELocator.getInstance()); |
74 |
} |
75 |
|
76 |
GPEProviderManager gpeProviderManager = GPEProviderLocator.getGPEProviderManager(); |
77 |
if (gpeProviderManager == null) { |
78 |
throw new ReferenceNotRegisteredException( |
79 |
GPEProviderLocator.GPE_PROVIDER_MANAGER_NAME, GPEProviderLocator.getInstance()); |
80 |
} |
81 |
|
82 |
gpeManager.setProperty(GmlProperties.DECIMAL, ".");
|
83 |
gpeManager.setProperty(GmlProperties.COORDINATES_SEPARATOR, ",");
|
84 |
gpeManager.setProperty(GmlProperties.TUPLES_SEPARATOR, " ");
|
85 |
gpeManager.setProperty(GmlProperties.DEFAULT_FEATURECOLLECTION, "FeatureCollection");
|
86 |
gpeManager.setProperty(GmlProperties.DEFAULT_FEATURE, "Feature");
|
87 |
gpeManager.setProperty(GmlProperties.SRS_BASED_ON_XML, true);
|
88 |
|
89 |
try {
|
90 |
gpeProviderManager.addGpeParser("GMLSFP0", "Parser for GML", org.gvsig.gpe.prov.gml.parser.GPEGmlSFP0Parser.class); |
91 |
} catch (ParserNotRegisteredException e) {
|
92 |
logger.error("Impossible to register a GML parser");
|
93 |
} |
94 |
try {
|
95 |
gpeProviderManager.addGpeWriterHandlerImplementor("GMLSFP0", "Writer for GML", org.gvsig.gpe.prov.gml.writer.GPEGmlSFP0WriterHandlerImplementor.class); |
96 |
} catch (WriterHandlerNotRegisteredException e) {
|
97 |
logger.error("Impossible to register a GML writer");
|
98 |
} |
99 |
|
100 |
XMLSchemaManager xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
101 |
if (xmlSchemaManager != null) { |
102 |
//Register dataTypes
|
103 |
xmlSchemaManager.registerFormat("text/xml; subtype=gml/2.0.0", GMLFORMAT);
|
104 |
xmlSchemaManager.registerFormat("text/xml; subtype=gml/2.1.0", GMLFORMAT);
|
105 |
xmlSchemaManager.registerFormat("text/xml; subtype=gml/3.2", GMLFORMAT);
|
106 |
|
107 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Point", XMLSchemaManager.POINT);
|
108 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LineString", XMLSchemaManager.LINESTRING);
|
109 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LinearRing", XMLSchemaManager.POLYGON);
|
110 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Polygon", XMLSchemaManager.POLYGON);
|
111 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiGeometry", XMLSchemaManager.MULTIGEOMETRY);
|
112 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPoint", XMLSchemaManager.MULTIPOINT);
|
113 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiLineString", XMLSchemaManager.MULTILINESTRING);
|
114 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPolygon", XMLSchemaManager.MULTIPOLYGON);
|
115 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiCurve", XMLSchemaManager.MULTILINESTRING);
|
116 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiSurface", XMLSchemaManager.MULTIPOLYGON);
|
117 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Curve", XMLSchemaManager.LINESTRING);
|
118 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "Surface", XMLSchemaManager.POLYGON);
|
119 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "PointPropertyType", XMLSchemaManager.POINT);
|
120 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LineStringPropertyType", XMLSchemaManager.LINESTRING);
|
121 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "LinearRingPropertyType", XMLSchemaManager.POLYGON);
|
122 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "PolygonPropertyType", XMLSchemaManager.POLYGON);
|
123 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiGeometryPropertyType", XMLSchemaManager.MULTIGEOMETRY);
|
124 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPointPropertyType", XMLSchemaManager.MULTIPOINT);
|
125 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiLineStringPropertyType", XMLSchemaManager.MULTILINESTRING);
|
126 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiPolygonPropertyType", XMLSchemaManager.MULTIPOLYGON);
|
127 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiCurvePropertyType", XMLSchemaManager.MULTILINESTRING);
|
128 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "MultiSurfacePropertyType", XMLSchemaManager.MULTIPOLYGON);
|
129 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "CurvePropertyType", XMLSchemaManager.LINESTRING);
|
130 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "SurfacePropertyType", XMLSchemaManager.POLYGON);
|
131 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "GeometryPropertyType", XMLSchemaManager.GEOMETRY);
|
132 |
xmlSchemaManager.addParserGeometryType(GMLFORMAT, "GeometryAssociationType", XMLSchemaManager.GEOMETRY);
|
133 |
} |
134 |
} |
135 |
} |
136 |
|