Statistics
| Revision:

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

History | View | Annotate | Download (9.77 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.Geometry2D;
64
import org.gvsig.fmap.geom.primitive.impl.Geometry2DZ;
65
import org.gvsig.fmap.geom.primitive.impl.Point2DGeometryType;
66
import org.gvsig.fmap.geom.primitive.impl.Point3DGeometryType;
67
import org.gvsig.fmap.geom.primitive.impl.Solid2DZ;
68
import org.gvsig.fmap.geom.primitive.impl.Spline2D;
69
import org.gvsig.fmap.geom.primitive.impl.Spline2DZ;
70
import org.gvsig.fmap.geom.primitive.impl.Surface2D;
71
import org.gvsig.fmap.geom.primitive.impl.Surface2DZ;
72
import org.gvsig.fmap.geom.type.persistence.GeometryTypePersistenceFactory;
73
import org.gvsig.tools.ToolsLocator;
74
import org.gvsig.tools.dataTypes.DataTypesManager;
75
import org.gvsig.tools.library.AbstractLibrary;
76
import org.gvsig.tools.library.LibraryException;
77
import org.gvsig.tools.persistence.PersistenceManager;
78

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

    
86
    public void doRegistration() {
87
        registerAsImplementationOf(GeometryLibrary.class);
88
    }
89

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

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

    
98
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
99

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

    
111
        GeometryOperation.OPERATION_INTERSECTS_CODE =
112
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
113
                GeometryOperation.OPERATION_INTERSECTS_NAME);
114

    
115
        GeometryOperation.OPERATION_CONTAINS_CODE =
116
            GeometryLocator.getGeometryManager().getGeometryOperationCode(
117
                GeometryOperation.OPERATION_CONTAINS_NAME);
118

    
119
        // Register the geometries in 2D
120
        geometryManager.registerGeometryType(DefaultNullGeometry.class, "Null",
121
            TYPES.NULL, SUBTYPES.GEOM2D);
122
        
123
        geometryManager.registerGeometryType(Geometry2D.class, "Geometry2D",
124
                TYPES.GEOMETRY, SUBTYPES.GEOM2D);
125
        geometryManager.registerGeometryType(Geometry2DZ.class, "Geometry3D",
126
            TYPES.GEOMETRY, SUBTYPES.GEOM3D);
127

    
128
        //Register points in 2D
129
        geometryManager.registerGeometryType(new Point2DGeometryType());
130

    
131
        //Register curves in 2D
132
        geometryManager.registerGeometryType(Curve2D.class, "Curve2D",
133
            TYPES.CURVE, SUBTYPES.GEOM2D);
134
        geometryManager.registerGeometryType(Arc2D.class, "Arc2D", 
135
            TYPES.ARC, SUBTYPES.GEOM2D, TYPES.CURVE);
136
        geometryManager.registerGeometryType(Spline2D.class, "Spline2D",
137
            TYPES.SPLINE, SUBTYPES.GEOM2D, TYPES.CURVE);
138

    
139
        //Register surfaces in 2D
140
        geometryManager.registerGeometryType(Surface2D.class, "Surface2D",
141
            TYPES.SURFACE, SUBTYPES.GEOM2D, TYPES.SURFACE);
142
        geometryManager.registerGeometryType(Circle2D.class, "Circle2D",
143
            TYPES.CIRCLE, SUBTYPES.GEOM2D, TYPES.SURFACE);      
144
        geometryManager.registerGeometryType(Ellipse2D.class, "Ellipse2D",
145
            TYPES.ELLIPSE, SUBTYPES.GEOM2D, TYPES.SURFACE);
146
        geometryManager.registerGeometryType(EllipticArc2D.class,"EllipticArc2D", 
147
            TYPES.ELLIPTICARC, SUBTYPES.GEOM2D, TYPES.SURFACE);
148

    
149
        //Register multigeometries in 2D
150
        geometryManager.registerGeometryType(BaseMultiPrimitive2D.class, "MultiPrimitive2D", 
151
            TYPES.AGGREGATE, SUBTYPES.GEOM2D);
152
        geometryManager.registerGeometryType(MultiPoint2D.class, "MultiPoint2D",
153
            TYPES.MULTIPOINT, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
154
        geometryManager.registerGeometryType(MultiCurve2D.class, "MultiCurve2D",
155
            TYPES.MULTICURVE, SUBTYPES.GEOM2D, TYPES.AGGREGATE); 
156
        geometryManager.registerGeometryType(MultiSurface2D.class,"MultiSurface2D",
157
            TYPES.MULTISURFACE, SUBTYPES.GEOM2D, TYPES.AGGREGATE);
158

    
159
        // Register the geometries in 3D
160
        geometryManager.registerGeometryType(DefaultNullGeometry.class,
161
            TYPES.NULL, SUBTYPES.GEOM3D);
162

    
163
        //Register points in 3D
164
        geometryManager.registerGeometryType(new Point3DGeometryType());
165

    
166
        //Register curves in 3D
167
        geometryManager.registerGeometryType(Curve2DZ.class, "Curve3D", 
168
            TYPES.CURVE, SUBTYPES.GEOM3D, new int[0], new int[]{SUBTYPES.GEOM2D});
169
        geometryManager.registerGeometryType(Arc2DZ.class, "Arc3D", 
170
            TYPES.ARC, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
171
        geometryManager.registerGeometryType(Spline2DZ.class, "Spline3D", 
172
            TYPES.SPLINE, SUBTYPES.GEOM3D, TYPES.CURVE, SUBTYPES.GEOM2D);
173

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

    
184
        //Register multigeometries in 3D
185
        geometryManager.registerGeometryType(MultiPoint2DZ.class, "Multipoint3D", 
186
            TYPES.MULTIPOINT, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
187
        geometryManager.registerGeometryType(MultiCurve2DZ.class,"MultiCurve3D",
188
            TYPES.MULTICURVE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
189
        geometryManager.registerGeometryType(MultiSurface3D.class,"MultiSurface3D",
190
            TYPES.MULTISURFACE, SUBTYPES.GEOM3D, TYPES.AGGREGATE, SUBTYPES.GEOM2D);
191

    
192
        //Register solids
193
        geometryManager.registerGeometryType(Solid2DZ.class, "Solid3D",
194
            TYPES.SOLID, SUBTYPES.GEOM3D);
195
        geometryManager.registerGeometryType(MultiSolid2DZ.class,"MultiSolid3D",
196
            TYPES.MULTISOLID, SUBTYPES.GEOM3D, TYPES.AGGREGATE);
197

    
198
        // Persistence
199
        DefaultEnvelope.registerPersistent();
200
        Envelope2D.registerPersistent();
201
        Envelope3D.registerPersistent();
202

    
203
        PersistenceManager persistenceManager =
204
            ToolsLocator.getPersistenceManager();
205

    
206
        persistenceManager.registerFactory(new GeometryPersistenceFactory());
207
        persistenceManager
208
            .registerFactory(new GeometryTypePersistenceFactory());
209
    }
210
}