svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / type / impl / DefaultGeometryType.java @ 38596
History | View | Annotate | Download (6.1 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.type.impl; |
29 |
|
30 |
import java.lang.reflect.Constructor; |
31 |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryManager; |
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
35 |
import org.gvsig.fmap.geom.type.AbstractGeometryType; |
36 |
import org.gvsig.fmap.geom.type.GeometryType; |
37 |
|
38 |
/**
|
39 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
40 |
*/
|
41 |
public class DefaultGeometryType extends AbstractGeometryType { |
42 |
|
43 |
/**
|
44 |
* Geometry type name
|
45 |
*/
|
46 |
private String name; |
47 |
|
48 |
/** Class that implements this class type */
|
49 |
private Class geometryClass; |
50 |
|
51 |
/**
|
52 |
* The type of the geometry. The type is an abstract representation
|
53 |
* of the object (Point, Curve...) but it is not a concrete
|
54 |
* representation (Point2D, Point3D...). To do that comparation
|
55 |
* the id field is used.
|
56 |
*/
|
57 |
private int type; |
58 |
|
59 |
/**
|
60 |
* The subtype of the geometry. The subtype represents a set of
|
61 |
* geometries with a dimensional relationship (2D, 3D, 2DM...)
|
62 |
*/
|
63 |
private int subType; |
64 |
|
65 |
/**
|
66 |
* Super types of a geometry. e.g: the super type of an
|
67 |
* arc is a curve, the super type of a circle is a surface...
|
68 |
* The supertypes are defined in the ISO 19107
|
69 |
*
|
70 |
* @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
|
71 |
* >ISO 19107< /a>
|
72 |
*/
|
73 |
private int[] superTypes = null; |
74 |
|
75 |
/**
|
76 |
* Super SubTypes of a geometry. e.g: the super SubType of a
|
77 |
* geometry 3D is a geometry 2D, because the 3D extends the
|
78 |
* behavior of a geometry 2D
|
79 |
*/
|
80 |
private int[] superSubTypes = null; |
81 |
|
82 |
private Constructor constructor; |
83 |
private final Object[] parameters = { this }; |
84 |
|
85 |
/**
|
86 |
* This constructor is used by the {@link GeometryManager} when it
|
87 |
* register a new GeometryType. It has not be used from other
|
88 |
* parts.
|
89 |
* @param geomClass
|
90 |
* Geometry class (e.g: Point2D.class)
|
91 |
* @param name
|
92 |
* Symbolic Geometry name that is used to persist the geometry type. In some
|
93 |
* cases, it is better to use this name because the id can change for different
|
94 |
* application executions.
|
95 |
* @param id
|
96 |
* Geometry id
|
97 |
* @param typeName
|
98 |
* The geometry type name
|
99 |
* @param type
|
100 |
* The geometry abstract type
|
101 |
* @param superTypes
|
102 |
* The superTypes of the geometry type
|
103 |
* @param superSubTypes
|
104 |
* The superSubtypes of the geometry type
|
105 |
*/
|
106 |
public DefaultGeometryType(Class geomClass, String name, int type, int subType, |
107 |
int[] superTypes, int[] superSubTypes) { |
108 |
this.geometryClass = geomClass;
|
109 |
if (name == null) { |
110 |
this.name = geomClass.getName();
|
111 |
} else {
|
112 |
this.name = name;
|
113 |
} |
114 |
this.type = type;
|
115 |
this.subType = subType;
|
116 |
this.superTypes = superTypes;
|
117 |
this.superSubTypes = superSubTypes;
|
118 |
|
119 |
Class[] parameterTypes = { GeometryType.class }; |
120 |
try {
|
121 |
constructor = geometryClass.getConstructor(parameterTypes); |
122 |
} catch (NoSuchMethodException e) { |
123 |
throw new RuntimeException( |
124 |
"Error constructor of the geometry class " + geomClass
|
125 |
+ " with one parameter of type GeometryType not found", e);
|
126 |
} |
127 |
} |
128 |
|
129 |
/**
|
130 |
* This constructor is used by the {@link GeometryManager} when it
|
131 |
* register a new GeometryType. It has not be used from other
|
132 |
* parts.
|
133 |
* @param geomClass
|
134 |
* Geometry class (e.g: Point2D.class)
|
135 |
* @param name
|
136 |
* Symbolic Geometry name that is used to persist the geometry type. In some
|
137 |
* cases, it is better to use this name because the id can change for different
|
138 |
* application executions.
|
139 |
* @param id
|
140 |
* Geometry id
|
141 |
* @param typeName
|
142 |
* The geometry type name
|
143 |
* @param type
|
144 |
* The geometry abstract type
|
145 |
*/
|
146 |
public DefaultGeometryType(Class geomClass, String name, int type, int subType) { |
147 |
this(geomClass, name, type, subType, new int[0], new int[0]); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* This method creates a {@link Geometry} with the type specified
|
152 |
* by this GeometryType. The geometry has to have a constructor
|
153 |
* without arguments.
|
154 |
*
|
155 |
* @return A new geometry
|
156 |
* @throws CreateGeometryException
|
157 |
*/
|
158 |
public Geometry create() throws CreateGeometryException{ |
159 |
try {
|
160 |
return (Geometry) constructor.newInstance(parameters);
|
161 |
} catch (Exception e) { |
162 |
throw new CreateGeometryException(type, subType, e); |
163 |
} |
164 |
} |
165 |
|
166 |
public Class getGeometryClass() { |
167 |
return geometryClass;
|
168 |
} |
169 |
|
170 |
public String getName() { |
171 |
return name;
|
172 |
} |
173 |
|
174 |
public int getType() { |
175 |
return type;
|
176 |
} |
177 |
|
178 |
public int getSubType() { |
179 |
return subType;
|
180 |
} |
181 |
|
182 |
public boolean isTypeOf(int geometryType) { |
183 |
if (type == geometryType){
|
184 |
return true; |
185 |
} |
186 |
for (int i=0 ; i<superTypes.length ; i++){ |
187 |
if(superTypes[i] == geometryType){
|
188 |
return true; |
189 |
} |
190 |
} |
191 |
return Geometry.TYPES.GEOMETRY == geometryType;
|
192 |
} |
193 |
|
194 |
public boolean isSubTypeOf(int geometrySubType) { |
195 |
if (subType == geometrySubType){
|
196 |
return true; |
197 |
} |
198 |
for (int i=0 ; i<superSubTypes.length ; i++){ |
199 |
if(superSubTypes[i] == geometrySubType){
|
200 |
return true; |
201 |
} |
202 |
} |
203 |
return false; |
204 |
} |
205 |
|
206 |
} |
207 |
|