Revision 20953 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/GeometryManager.java
GeometryManager.java | ||
---|---|---|
46 | 46 |
import java.util.Map; |
47 | 47 |
|
48 | 48 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
49 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
49 | 50 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
50 | 51 |
import org.gvsig.fmap.geom.type.GeometryType; |
51 | 52 |
|
... | ... | |
55 | 56 |
|
56 | 57 |
/** Índice con el nombre único de cada operación */ |
57 | 58 |
private List geometryOperations = new ArrayList(); |
58 |
|
|
59 |
|
|
60 |
/** Las operaciones que son comunes a todos los tipos de geometría se registran aquí, el resto están en cada tipo de geometría */ |
|
61 |
private List commonOperations = new ArrayList(); |
|
62 |
|
|
63 |
/** Las operaciones comunes tienen un indice asignado a partir de este valor, se almacenan en una estructura distinta que las operaciones |
|
64 |
* que dependen del tipo y comparando con este valor sabemos a qué estructura acceder */ |
|
65 |
private static final int COMMON_OPS_OFFSET = 1000; |
|
66 |
|
|
59 | 67 |
/** Mapa con las instancias de cada tipo de geometría, la clave es el nombre de la clase de geometría. |
60 | 68 |
* Es decir para "org.gvsig.fmap.geom.Point2D" se obtiene una instancia de GeometryType que contiene las |
61 | 69 |
* operaciones asociadas a Point2D. |
62 | 70 |
*/ |
63 | 71 |
private Map geometryTypes = new HashMap(); |
64 |
private int typeIndex = 128; |
|
72 |
|
|
73 |
/** Contador de registro de tipos de geometría, se asigna en el momento de su registro */ |
|
74 |
private int geomTypeIndex = 100; |
|
65 | 75 |
|
66 | 76 |
/** |
67 | 77 |
* Constructor privado (singleton) |
... | ... | |
81 | 91 |
} |
82 | 92 |
|
83 | 93 |
/** |
94 |
* Registra el nombre de una operación. Este nombre es único en la aplicación. |
|
95 |
* @param geomOpName |
|
96 |
* @return |
|
97 |
*/ |
|
98 |
private int registerGeometryOperationName(String geomOpName) { |
|
99 |
if (geomOpName == null) |
|
100 |
throw new IllegalArgumentException("geomOpName cannot be null."); |
|
101 |
|
|
102 |
int index = geometryOperations.indexOf(geomOpName); |
|
103 |
if (index == -1) { |
|
104 |
geometryOperations.add(geomOpName); |
|
105 |
index = geometryOperations.indexOf(geomOpName); |
|
106 |
} |
|
107 |
return index; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
84 | 111 |
* Método para registrar una operación asociada a un tipo de geometría. |
85 | 112 |
* |
86 | 113 |
* @param geomOpName Nombre de la operación, este nombre es único |
... | ... | |
91 | 118 |
*/ |
92 | 119 |
public int registerGeometryOperation(String geomOpName, |
93 | 120 |
GeometryOperation geomOp, GeometryType geomType) { |
94 |
if (geomOpName == null) |
|
95 |
throw new IllegalArgumentException("geomOpName cannot be null."); |
|
96 | 121 |
if (geomOp == null) |
97 | 122 |
throw new IllegalArgumentException("geomOp cannot be null."); |
98 | 123 |
if (geomType == null) |
99 | 124 |
throw new IllegalArgumentException("geomType cannot be null."); |
100 | 125 |
|
101 |
int index = geometryOperations.indexOf(geomOpName); |
|
102 |
if (index == -1) { |
|
103 |
geometryOperations.add(geomOpName); |
|
104 |
index = geometryOperations.indexOf(geomOpName); |
|
105 |
} |
|
106 |
|
|
126 |
int index = registerGeometryOperationName(geomOpName); |
|
127 |
|
|
107 | 128 |
geomType.setGeometryOperation(index, geomOp); |
108 | 129 |
|
109 | 130 |
return index; |
110 | 131 |
} |
111 | 132 |
|
133 |
/** |
|
134 |
* Registra una operación que será común a todos los tipos de geometría. |
|
135 |
* @param geomOpName |
|
136 |
* @param geomOp |
|
137 |
* @return |
|
138 |
*/ |
|
112 | 139 |
public int registerGeometryOperation(String geomOpName, |
113 | 140 |
GeometryOperation geomOp) { |
114 |
// FIXME Registrar operacion para todas las geom |
|
115 |
return -1; |
|
141 |
if (geomOpName == null) |
|
142 |
throw new IllegalArgumentException("geomOpName cannot be null."); |
|
143 |
if (geomOp == null) |
|
144 |
throw new IllegalArgumentException("geomOp cannot be null."); |
|
145 |
|
|
146 |
int index = registerGeometryOperationName(geomOpName); |
|
147 |
|
|
148 |
commonOperations.add(index, geomOp); |
|
116 | 149 |
|
150 |
|
|
151 |
return index + COMMON_OPS_OFFSET; |
|
152 |
|
|
117 | 153 |
} |
118 | 154 |
|
119 | 155 |
public int registerGeometryOperation(String geomOpName, |
... | ... | |
135 | 171 |
public int registerGeometryOperation(String geomOpName, Class geomOpClass, |
136 | 172 |
GeometryType geomType) |
137 | 173 |
throws IllegalAccessException, InstantiationException { |
138 |
|
|
139 |
if (geomOpName == null) |
|
140 |
throw new IllegalArgumentException("geomOpName cannot be null."); |
|
141 |
if (geomOpClass == null) |
|
142 |
throw new IllegalArgumentException("geomOpClass cannot be null."); |
|
143 |
if (geomType == null) |
|
144 |
throw new IllegalArgumentException("geomType cannot be null."); |
|
145 |
|
|
146 |
int index = geometryOperations.indexOf(geomOpName); |
|
147 |
if (index == -1) { |
|
148 |
geometryOperations.add(geomOpName); |
|
149 |
index = geometryOperations.indexOf(geomOpName); |
|
150 |
} |
|
151 |
geomType.setGeometryOperation(index, (GeometryOperation) geomOpClass.newInstance()); |
|
152 | 174 |
|
153 |
return index; |
|
175 |
GeometryOperation geomOp = (GeometryOperation) geomOpClass.newInstance(); |
|
176 |
return registerGeometryOperation(geomOpName, geomOp, geomType); |
|
154 | 177 |
} |
155 | 178 |
|
156 | 179 |
/** |
... | ... | |
185 | 208 |
|
186 | 209 |
// Si no está registrada, registrarla |
187 | 210 |
if (geomType == null) { |
188 |
geomType = new GeometryType(geomClass, name, typeIndex++);
|
|
211 |
geomType = new GeometryType(geomClass, name, geomTypeIndex++);
|
|
189 | 212 |
geometryTypes.put(geomClass.getName(), geomType); |
190 | 213 |
} |
191 | 214 |
|
... | ... | |
233 | 256 |
} |
234 | 257 |
return null; |
235 | 258 |
} |
259 |
|
|
260 |
/** |
|
261 |
* Invoca una operación dado su índice, la geometría y el contexto. |
|
262 |
* @param index |
|
263 |
* @param geom |
|
264 |
* @param ctx |
|
265 |
* @return |
|
266 |
*/ |
|
267 |
public Object invokeOperation(int index, Geometry geom, GeometryOperationContext ctx) { |
|
268 |
if (index < COMMON_OPS_OFFSET) { |
|
269 |
return geom.getGeometryType().getGeometryOperation(index).invoke(geom, ctx); |
|
270 |
} else { |
|
271 |
return ((GeometryOperation)commonOperations.get(index - COMMON_OPS_OFFSET)).invoke(geom, ctx); |
|
272 |
} |
|
273 |
} |
|
236 | 274 |
} |
Also available in: Unified diff