Revision 42283 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/DefaultGeometryType.java
DefaultGeometryType.java | ||
---|---|---|
21 | 21 |
* For any additional information, do not hesitate to contact us |
22 | 22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
23 | 23 |
*/ |
24 |
|
|
24 |
|
|
25 | 25 |
package org.gvsig.fmap.geom.jts; |
26 | 26 |
|
27 | 27 |
import java.lang.reflect.Constructor; |
... | ... | |
36 | 36 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
37 | 37 |
*/ |
38 | 38 |
public class DefaultGeometryType extends AbstractGeometryType { |
39 |
|
|
40 |
/**
|
|
39 |
|
|
40 |
/** |
|
41 | 41 |
* Geometry type name |
42 | 42 |
*/ |
43 | 43 |
private String name; |
44 |
|
|
44 |
|
|
45 | 45 |
/** Class that implements this class type */ |
46 | 46 |
private Class geometryClass; |
47 |
|
|
47 |
|
|
48 | 48 |
/** |
49 | 49 |
* The type of the geometry. The type is an abstract representation |
50 |
* of the object (Point, Curve...) but it is not a concrete
|
|
50 |
* of the object (Point, Curve...) but it is not a concrete |
|
51 | 51 |
* representation (Point2D, Point3D...). To do that comparation |
52 | 52 |
* the id field is used. |
53 | 53 |
*/ |
54 | 54 |
private int type; |
55 |
|
|
55 |
|
|
56 | 56 |
/** |
57 |
* The subtype of the geometry. The subtype represents a set of
|
|
57 |
* The subtype of the geometry. The subtype represents a set of |
|
58 | 58 |
* geometries with a dimensional relationship (2D, 3D, 2DM...) |
59 | 59 |
*/ |
60 |
private int subType;
|
|
61 |
|
|
60 |
private int subType; |
|
61 |
|
|
62 | 62 |
/** |
63 | 63 |
* Super types of a geometry. e.g: the super type of an |
64 | 64 |
* arc is a curve, the super type of a circle is a surface... |
65 |
* The supertypes are defined in the ISO 19107
|
|
66 |
*
|
|
65 |
* The supertypes are defined in the ISO 19107 |
|
66 |
* |
|
67 | 67 |
* @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012" |
68 | 68 |
* >ISO 19107< /a> |
69 | 69 |
*/ |
70 | 70 |
private int[] superTypes = null; |
71 |
|
|
71 |
|
|
72 | 72 |
/** |
73 | 73 |
* Super SubTypes of a geometry. e.g: the super SubType of a |
74 | 74 |
* geometry 3D is a geometry 2D, because the 3D extends the |
75 | 75 |
* behavior of a geometry 2D |
76 | 76 |
*/ |
77 | 77 |
private int[] superSubTypes = null; |
78 |
|
|
79 |
private Constructor constructor; |
|
78 |
|
|
79 |
private Constructor constructorWithGeometryType = null; |
|
80 |
private Constructor constructorWithoutParameters = null; |
|
80 | 81 |
private final Object[] parameters = { this }; |
81 | 82 |
|
82 | 83 |
/** |
... | ... | |
88 | 89 |
* @param name |
89 | 90 |
* Symbolic Geometry name that is used to persist the geometry type. In some |
90 | 91 |
* cases, it is better to use this name because the id can change for different |
91 |
* application executions.
|
|
92 |
* application executions. |
|
92 | 93 |
* @param id |
93 |
* Geometry id
|
|
94 |
* Geometry id |
|
94 | 95 |
* @param typeName |
95 | 96 |
* The geometry type name |
96 | 97 |
* @param type |
97 |
* The geometry abstract type
|
|
98 |
* The geometry abstract type |
|
98 | 99 |
* @param superTypes |
99 | 100 |
* The superTypes of the geometry type |
100 | 101 |
* @param superSubTypes |
101 |
* The superSubtypes of the geometry type
|
|
102 |
* The superSubtypes of the geometry type |
|
102 | 103 |
*/ |
103 |
public DefaultGeometryType(Class geomClass, String name, int type, int subType,
|
|
104 |
public DefaultGeometryType(Class geomClass, String name, int type, int subType, |
|
104 | 105 |
int[] superTypes, int[] superSubTypes) { |
105 | 106 |
this.geometryClass = geomClass; |
106 | 107 |
if (name == null) { |
... | ... | |
108 | 109 |
} else { |
109 | 110 |
this.name = name; |
110 | 111 |
} |
111 |
this.type = type;
|
|
112 |
this.type = type; |
|
112 | 113 |
this.subType = subType; |
113 | 114 |
this.superTypes = superTypes; |
114 | 115 |
this.superSubTypes = superSubTypes; |
115 | 116 |
|
116 | 117 |
Class[] parameterTypes = { GeometryType.class }; |
117 | 118 |
try { |
118 |
constructor = geometryClass.getConstructor(parameterTypes); |
|
119 |
constructorWithGeometryType = geometryClass.getConstructor(parameterTypes);
|
|
119 | 120 |
} catch (NoSuchMethodException e) { |
120 |
throw new RuntimeException( |
|
121 |
"Error constructor of the geometry class " + geomClass |
|
122 |
+ " with one parameter of type GeometryType not found", e); |
|
121 |
try { |
|
122 |
constructorWithoutParameters = geometryClass.getConstructor(); |
|
123 |
} catch (NoSuchMethodException e1) { |
|
124 |
throw new RuntimeException( |
|
125 |
"Error constructor of the geometry class " + geomClass |
|
126 |
+ " with one parameter of type GeometryType not found", e); |
|
127 |
} |
|
128 |
// throw new RuntimeException( |
|
129 |
// "Error constructor of the geometry class " + geomClass |
|
130 |
// + " with one parameter of type GeometryType not found", e); |
|
123 | 131 |
} |
124 |
}
|
|
125 |
|
|
132 |
} |
|
133 |
|
|
126 | 134 |
/** |
127 | 135 |
* This constructor is used by the {@link GeometryManager} when it |
128 | 136 |
* register a new GeometryType. It has not be used from other |
... | ... | |
132 | 140 |
* @param name |
133 | 141 |
* Symbolic Geometry name that is used to persist the geometry type. In some |
134 | 142 |
* cases, it is better to use this name because the id can change for different |
135 |
* application executions.
|
|
143 |
* application executions. |
|
136 | 144 |
* @param id |
137 |
* Geometry id
|
|
145 |
* Geometry id |
|
138 | 146 |
* @param typeName |
139 | 147 |
* The geometry type name |
140 | 148 |
* @param type |
141 |
* The geometry abstract type
|
|
149 |
* The geometry abstract type |
|
142 | 150 |
*/ |
143 | 151 |
public DefaultGeometryType(Class geomClass, String name, int type, int subType) { |
144 | 152 |
this(geomClass, name, type, subType, new int[0], new int[0]); |
145 | 153 |
} |
146 |
|
|
154 |
|
|
147 | 155 |
/** |
148 |
* This method creates a {@link Geometry} with the type specified
|
|
156 |
* This method creates a {@link Geometry} with the type specified |
|
149 | 157 |
* by this GeometryType. The geometry has to have a constructor |
150 | 158 |
* without arguments. |
151 |
*
|
|
159 |
* |
|
152 | 160 |
* @return A new geometry |
153 |
* @throws CreateGeometryException
|
|
161 |
* @throws CreateGeometryException |
|
154 | 162 |
*/ |
155 | 163 |
public Geometry create() throws CreateGeometryException{ |
156 | 164 |
try { |
157 |
return (Geometry) constructor.newInstance(parameters); |
|
165 |
if(constructorWithGeometryType!=null){ |
|
166 |
return (Geometry) constructorWithGeometryType.newInstance(parameters); |
|
167 |
} else { |
|
168 |
return (Geometry) constructorWithoutParameters.newInstance(); |
|
169 |
} |
|
158 | 170 |
} catch (Exception e) { |
159 | 171 |
throw new CreateGeometryException(type, subType, e); |
160 |
}
|
|
172 |
} |
|
161 | 173 |
} |
162 |
|
|
174 |
|
|
163 | 175 |
public Class getGeometryClass() { |
164 | 176 |
return geometryClass; |
165 | 177 |
} |
166 |
|
|
178 |
|
|
167 | 179 |
public String getName() { |
168 | 180 |
return name; |
169 | 181 |
} |
Also available in: Unified diff