Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / impl / DefaultGeometryLibrary.java @ 37322

History | View | Annotate | Download (9.51 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.fmap.geom.impl;
29

    
30
import org.gvsig.fmap.geom.DataTypes;
31
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
32
import org.gvsig.fmap.geom.Geometry.TYPES;
33
import org.gvsig.fmap.geom.GeometryLibrary;
34
import org.gvsig.fmap.geom.GeometryLocator;
35
import org.gvsig.fmap.geom.GeometryManager;
36
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive2D;
37
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2D;
38
import org.gvsig.fmap.geom.aggregate.impl.MultiCurve2DZ;
39
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D;
40
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2DZ;
41
import org.gvsig.fmap.geom.aggregate.impl.MultiSolid2DZ;
42
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface2D;
43
import org.gvsig.fmap.geom.aggregate.impl.MultiSurface3D;
44
import org.gvsig.fmap.geom.impl.coerce.CoerceToByteArray;
45
import org.gvsig.fmap.geom.impl.coerce.CoerceToEnvelope;
46
import org.gvsig.fmap.geom.impl.coerce.CoerceToGeometry;
47
import org.gvsig.fmap.geom.impl.coerce.CoerceToString;
48
import org.gvsig.fmap.geom.operation.GeometryOperation;
49
import org.gvsig.fmap.geom.primitive.impl.Arc2D;
50
import org.gvsig.fmap.geom.primitive.impl.Arc2DZ;
51
import org.gvsig.fmap.geom.primitive.impl.Circle2D;
52
import org.gvsig.fmap.geom.primitive.impl.Circle2DZ;
53
import org.gvsig.fmap.geom.primitive.impl.Curve2D;
54
import org.gvsig.fmap.geom.primitive.impl.Curve2DZ;
55
import org.gvsig.fmap.geom.primitive.impl.DefaultEnvelope;
56
import org.gvsig.fmap.geom.primitive.impl.DefaultNullGeometry;
57
import org.gvsig.fmap.geom.primitive.impl.Ellipse2D;
58
import org.gvsig.fmap.geom.primitive.impl.Ellipse2DZ;
59
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2D;
60
import org.gvsig.fmap.geom.primitive.impl.EllipticArc2DZ;
61
import org.gvsig.fmap.geom.primitive.impl.Envelope2D;
62
import org.gvsig.fmap.geom.primitive.impl.Envelope3D;
63
import org.gvsig.fmap.geom.primitive.impl.Point2D;
64
import org.gvsig.fmap.geom.primitive.impl.Point2DZ;
65
import org.gvsig.fmap.geom.primitive.impl.Solid2DZ;
66
import org.gvsig.fmap.geom.primitive.impl.Spline2D;
67
import org.gvsig.fmap.geom.primitive.impl.Spline2DZ;
68
import org.gvsig.fmap.geom.primitive.impl.Surface2D;
69
import org.gvsig.fmap.geom.primitive.impl.Surface2DZ;
70
import org.gvsig.fmap.geom.type.persistence.GeometryTypePersistenceFactory;
71
import org.gvsig.tools.ToolsLocator;
72
import org.gvsig.tools.dataTypes.DataTypesManager;
73
import org.gvsig.tools.library.AbstractLibrary;
74
import org.gvsig.tools.library.LibraryException;
75
import org.gvsig.tools.persistence.PersistenceManager;
76

    
77
/**
78
 * Registers the default implementation for {@link GeometryManager}
79
 * 
80
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
81
 */
82
public class DefaultGeometryLibrary extends AbstractLibrary {
83

    
84
    public void doRegistration() {
85
        registerAsImplementationOf(GeometryLibrary.class);
86
    }
87

    
88
    protected void doInitialize() throws LibraryException {
89
        // Register the default GeometryManager
90
        GeometryLocator.registerGeometryManager(DefaultGeometryManager.class);
91
    }
92

    
93
    protected void doPostInitialize() throws LibraryException {
94
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
95

    
96
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
97

    
98
        dataTypesManager
99
        .setCoercion(DataTypes.GEOMETRY, new CoerceToGeometry());
100
        dataTypesManager
101
        .setCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope());
102
        dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString(
103
            dataTypesManager.getCoercion(DataTypes.STRING)));
104
        dataTypesManager.setCoercion(
105
            DataTypes.BYTEARRAY,
106
            new CoerceToByteArray(dataTypesManager
107
                .getCoercion(DataTypes.BYTEARRAY)));
108

    
109
        GeometryOperation.OPERATION_INTERSECTS_CODE =
110
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
111
                GeometryOperation.OPERATION_INTERSECTS_NAME);
112

    
113
        GeometryOperation.OPERATION_CONTAINS_CODE =
114
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
115
                GeometryOperation.OPERATION_CONTAINS_NAME);
116

    
117
        // Register the geometries in 2D
118
        geometryManager.registerGeometryType(DefaultNullGeometry.class, "Null",
119
            TYPES.NULL, SUBTYPES.GEOM2D);
120

    
121
        //Register points in 2D
122
        geometryManager.registerGeometryType(Point2D.class, "Point2D",
123
            TYPES.POINT, SUBTYPES.GEOM2D);
124

    
125
        //Register curves in 2D
126
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
127
            TYPES.CURVE, SUBTYPES.GEOM2D);
128
        geometryManager.registerGeometryType(Arc2D.class, "Arc2D", 
129
            TYPES.ARC, SUBTYPES.GEOM2D, TYPES.CURVE);
130
        geometryManager.registerGeometryType(Spline2D.class, "Spline2D",
131
            TYPES.SPLINE, SUBTYPES.GEOM2D, TYPES.CURVE);
132

    
133
        //Register surfaces in 2D
134
        geometryManager.registerGeometryType(Surface2D.class, "Surface2D",
135
            TYPES.SURFACE, SUBTYPES.GEOM2D, TYPES.SURFACE);
136
        geometryManager.registerGeometryType(Circle2D.class, "Circle2D",
137
            TYPES.CIRCLE, SUBTYPES.GEOM2D, TYPES.SURFACE);      
138
        geometryManager.registerGeometryType(Ellipse2D.class, "Ellipse2D",
139
            TYPES.ELLIPSE, SUBTYPES.GEOM2D, TYPES.SURFACE);
140
        geometryManager.registerGeometryType(EllipticArc2D.class,"EllipticArc2D", 
141
            TYPES.ELLIPTICARC, SUBTYPES.GEOM2D, TYPES.SURFACE);
142

    
143
        //Register multigeometries in 2D
144
        geometryManager.registerGeometryType(BaseMultiPrimitive2D.class, "MultiPrimitive2D", 
145
            TYPES.AGGREGATE, SUBTYPES.GEOM2D);
146
        geometryManager.registerGeometryType(MultiPoint2D.class, "MultiPoint2D",
147
            TYPES.MULTIPOINT, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
148
        geometryManager.registerGeometryType(MultiCurve2D.class, "MultiCurve2D",
149
            TYPES.MULTICURVE, SUBTYPES.GEOM2D, TYPES.AGGREGATE); 
150
        geometryManager.registerGeometryType(MultiSurface2D.class,"MultiSurface2D",
151
            TYPES.MULTISURFACE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
152

    
153
        // Register the geometries in 3D
154
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
155
            TYPES.NULL, SUBTYPES.GEOM3D);
156

    
157
        //Register points in 3D
158
        geometryManager.registerGeometryType(Point2DZ.class, "Point3D",
159
            TYPES.POINT, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
160

    
161
        //Register curves in 3D
162
        geometryManager.registerGeometryType(Curve2DZ.class, "Curve3D", 
163
            TYPES.CURVE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
164
        geometryManager.registerGeometryType(Arc2DZ.class, "Arc3D", 
165
            TYPES.ARC, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
166
        geometryManager.registerGeometryType(Spline2DZ.class, "Spline3D", 
167
            TYPES.SPLINE, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
168

    
169
        //Register surfaces in 2D
170
        geometryManager.registerGeometryType(Surface2DZ.class, "Surface3D", 
171
            TYPES.SURFACE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
172
        geometryManager.registerGeometryType(Circle2DZ.class, "Circle3D",
173
            TYPES.CIRCLE, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
174
        geometryManager.registerGeometryType(Ellipse2DZ.class, "Ellipse3D", 
175
            TYPES.ELLIPSE,SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
176
        geometryManager.registerGeometryType(EllipticArc2DZ.class, "EllipticArc3D",
177
            TYPES.ELLIPTICARC, SUBTYPES.GEOM3D, TYPES.SURFACE, SUBTYPES.GEOM2D);
178

    
179
        //Register multigeometries in 3D
180
        geometryManager.registerGeometryType(MultiPoint2DZ.class, "Multipoint3D", 
181
            TYPES.MULTIPOINT, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
182
        geometryManager.registerGeometryType(MultiCurve2DZ.class,"MultiCurve3D",
183
            TYPES.MULTICURVE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
184
        geometryManager.registerGeometryType(MultiSurface3D.class,"MultiSurface3D",
185
            TYPES.MULTISURFACE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
186

    
187
        //Register solids
188
        geometryManager.registerGeometryType(Solid2DZ.class, "Solid3D",
189
            TYPES.SOLID, SUBTYPES.GEOM3D);
190
        geometryManager.registerGeometryType(MultiSolid2DZ.class,"MultiSolid3D",
191
            TYPES.MULTISOLID, SUBTYPES.GEOM3D, TYPES.AGGREGATE);
192

    
193
        // Persistence
194
        DefaultEnvelope.registerPersistent();
195
        Envelope2D.registerPersistent();
196
        Envelope3D.registerPersistent();
197

    
198
        PersistenceManager persistenceManager =
199
            ToolsLocator.getPersistenceManager();
200

    
201
        persistenceManager.registerFactory(new GeometryPersistenceFactory());
202
        persistenceManager
203
            .registerFactory(new GeometryTypePersistenceFactory());
204
    }
205
}