Revision 34708 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/DefaultGeometryManager.java

View differences:

DefaultGeometryManager.java
68 68

  
69 69
/**
70 70
 * Default implementation for the {@link GeometryManager}. When the
71
 * application starts, this class is registered in the
72
 * {@link GeometryLocator} using the {@link DefaultGeometryLibrary}.
71
 * application starts, this class is registered in the {@link GeometryLocator}
72
 * using the {@link DefaultGeometryLibrary}.
73
 * 
73 74
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
74 75
 */
75 76

  
76 77
public class DefaultGeometryManager implements GeometryManager {
77
	private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
78
	private double flatness = 0.8;
79 78

  
80
	/** This list holds the unique name of all registered geometry operations.
81
	 * The index in which they are stored is also the operation code used to invoke each one of them */
82
	private List geometryOperations = new ArrayList();
79
    private static final Logger logger = LoggerFactory
80
        .getLogger(GeometryManager.class);
81
    private double flatness = 0.8;
83 82

  
84
	/** Common operations are registered here. Type specific operations are registered in the corresponding GeometryType instance */
85
	//private List commonOperations = new ArrayList();
83
    /**
84
     * This list holds the unique name of all registered geometry operations.
85
     * The index in which they are stored is also the operation code used to
86
     * invoke each one of them
87
     */
88
    private List geometryOperations = new ArrayList();
86 89

  
87
	/** This map holds the instances of all registered GeometryType. The key is the name of the specific Geometry subclass.
88
	 * In other words, the string "org.gvsig.fmap.geom.primitive.Point2D" is the hash key to obtain an instance of GeometryType holding the
89
	 * operations associated to the class org.gvsig.fmap.geom.primitive.Point2D.
90
	 */
91
	private Map geometryTypeName = new HashMap();
90
    /**
91
     * Common operations are registered here. Type specific operations are
92
     * registered in the corresponding GeometryType instance
93
     */
94
    // private List commonOperations = new ArrayList();
92 95

  
93
	/**
94
	 * Matrix of geometry types by type (row) and subtype (column). This matrix
95
	 * will contain null values in the cells where a GeometryType hasn't been
96
	 * registered.
97
	 */
98
	private GeometryType[][] geometryTypes;
96
    /**
97
     * This map holds the instances of all registered GeometryType. The key is
98
     * the name of the specific Geometry subclass.
99
     * In other words, the string "org.gvsig.fmap.geom.primitive.Point2D" is the
100
     * hash key to obtain an instance of GeometryType holding the
101
     * operations associated to the class org.gvsig.fmap.geom.primitive.Point2D.
102
     */
103
    private Map geometryTypeName = new HashMap();
99 104

  
100
	/** GeometryType index counter. Each time a new geometry type (not predefined) is registered it is assigned this counter's value as index and after that
101
	 * it is incremented by 1 */
102
	private int geometryTypeIndex = 0;//Geometry.EXTENDED_GEOMTYPE_OFFSET; //65536;//2^16
105
    /**
106
     * Matrix of geometry types by type (row) and subtype (column). This matrix
107
     * will contain null values in the cells where a GeometryType hasn't been
108
     * registered.
109
     */
110
    private GeometryType[][] geometryTypes;
103 111

  
104
	// Initially create a matrix of 17 x 6, which are the current default
105
	// types and subtypes. If another type or subtype is registered, the
106
	// matrix will grow as needed
107
	private static final int DEFAULT_TYPES_SIZE = 17;
108
	private static final int DEFAULT_SUBTYPES_SIZE = 6;
112
    /**
113
     * GeometryType index counter. Each time a new geometry type (not
114
     * predefined) is registered it is assigned this counter's value as index
115
     * and after that
116
     * it is incremented by 1
117
     */
118
    private int geometryTypeIndex = 0;// Geometry.EXTENDED_GEOMTYPE_OFFSET;
119
                                      // //65536;//2^16
109 120

  
110
	public DefaultGeometryManager() {
111
		this(DEFAULT_TYPES_SIZE, DEFAULT_SUBTYPES_SIZE);
112
	}
121
    // Initially create a matrix of 17 x 6, which are the current default
122
    // types and subtypes. If another type or subtype is registered, the
123
    // matrix will grow as needed
124
    private static final int DEFAULT_TYPES_SIZE = 17;
125
    private static final int DEFAULT_SUBTYPES_SIZE = 6;
113 126

  
114
	public DefaultGeometryManager(int initialTypesSize, int initialSubtypesSize) {
115
		geometryTypes = new GeometryType[initialTypesSize][initialSubtypesSize];
116
	}
127
    public DefaultGeometryManager() {
128
        this(DEFAULT_TYPES_SIZE, DEFAULT_SUBTYPES_SIZE);
129
    }
117 130

  
118
	/*
119
	 * (non-Javadoc)
120
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation, org.gvsig.fmap.geom.type.GeometryType)
121
	 */
122
	public int registerGeometryOperation(String geomOpName,
123
			GeometryOperation geomOp, GeometryType geomType) {
124
		if (geomOp == null) {
125
			throw new IllegalArgumentException("geomOp cannot be null.");
126
		}
127
		if (geomType == null) {
128
			throw new IllegalArgumentException("geomType cannot be null.");
129
		}
131
    public DefaultGeometryManager(int initialTypesSize, int initialSubtypesSize) {
132
        geometryTypes = new GeometryType[initialTypesSize][initialSubtypesSize];
133
    }
130 134

  
131
		int index = getGeometryOperationCode(geomOpName);
135
    /*
136
     * (non-Javadoc)
137
     * 
138
     * @see
139
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang
140
     * .String, org.gvsig.fmap.geom.operation.GeometryOperation,
141
     * org.gvsig.fmap.geom.type.GeometryType)
142
     */
143
    public int registerGeometryOperation(String geomOpName,
144
        GeometryOperation geomOp, GeometryType geomType) {
145
        if (geomOp == null) {
146
            throw new IllegalArgumentException("geomOp cannot be null.");
147
        }
148
        if (geomType == null) {
149
            throw new IllegalArgumentException("geomType cannot be null.");
150
        }
132 151

  
133
		geomType.setGeometryOperation(index, geomOp);
152
        int index = getGeometryOperationCode(geomOpName);
134 153

  
135
		return index;
136
	}
154
        geomType.setGeometryOperation(index, geomOp);
137 155

  
138
	/*
139
	 * (non-Javadoc)
140
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation)
141
	 */
142
	public int registerGeometryOperation(String geomOpName,
143
			GeometryOperation geomOp) {
144
		if (geomOpName == null) {
145
			throw new IllegalArgumentException("geomOpName cannot be null.");
146
		}
147
		if (geomOp == null) {
148
			throw new IllegalArgumentException("geomOp cannot be null.");
149
		}
156
        return index;
157
    }
150 158

  
151
		int index = getGeometryOperationCode(geomOpName);
159
    /*
160
     * (non-Javadoc)
161
     * 
162
     * @see
163
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang
164
     * .String, org.gvsig.fmap.geom.operation.GeometryOperation)
165
     */
166
    public int registerGeometryOperation(String geomOpName,
167
        GeometryOperation geomOp) {
168
        if (geomOpName == null) {
169
            throw new IllegalArgumentException("geomOpName cannot be null.");
170
        }
171
        if (geomOp == null) {
172
            throw new IllegalArgumentException("geomOp cannot be null.");
173
        }
152 174

  
153
		Iterator it = geometryTypeName.keySet().iterator();
154
		while (it.hasNext()){
155
			String className = (String)it.next();
156
			GeometryType geometryType = (GeometryType) geometryTypeName.get(className);
157
			registerGeometryOperation(geomOpName, geomOp, geometryType);
158
		}
175
        int index = getGeometryOperationCode(geomOpName);
159 176

  
160
		return index;
177
        Iterator it = geometryTypeName.keySet().iterator();
178
        while (it.hasNext()) {
179
            String className = (String) it.next();
180
            GeometryType geometryType =
181
                (GeometryType) geometryTypeName.get(className);
182
            registerGeometryOperation(geomOpName, geomOp, geometryType);
183
        }
161 184

  
162
	}
185
        return index;
163 186

  
164
	// /**
165
	// * Registers a GeometryOperation associated to a GeometryType.
166
	// * Returns an unique index that is used later to identify and invoke the
167
	// operation.<br>
168
	// *
169
	// * By convention, the return value should be stored in a public constant
170
	// within the class implementing
171
	// * the operation:<BR>
172
	// * <pre>
173
	// * public class MyOperation extends GeometryOperation {
174
	// * public static final int CODE =
175
	// * GeometryManager.getInstance()
176
	// * .registerGeometryOperation("MyOperation", new MyOperation(),
177
	// MyGeometry.class);
178
	// * }
179
	// * </pre>
180
	// *
181
	// * This method is only used if you have not a reference to the
182
	// GeometryType associated to the
183
	// * geometry class. If you have such reference then it is slightly faster
184
	// to use the method that receives
185
	// * the GeometryType.<br>
186
	// *
187
	// * @param geomOpName Operation's unique name
188
	// * @param geomOp Specific GeometryOperation's instance implementing this
189
	// operation
190
	// * @param geomClass Geometry implementation class
191
	// * @return Index assigned to this operation. This index is used later to
192
	// access the operation.
193
	// */
194
	// private int registerGeometryOperation(String geomOpName,
195
	// GeometryOperation geomOp, Class geomClass) {
196
	//
197
	// GeometryType geomType = getGeometryType(geomClass);
198
	// return registerGeometryOperation(geomOpName, geomOp, geomType);
199
	// }
187
    }
200 188

  
201
	// /**
202
	// * Registers a GeometryOperation associated to a GeometryType.
203
	// * Returns an unique index that is used later to identify and invoke the
204
	// operation.<br>
205
	// *
206
	// * By convention, the return value should be stored in a public constant
207
	// within the class implementing
208
	// * the operation:<BR>
209
	// * <pre>
210
	// * public class MyOperation extends GeometryOperation {
211
	// * public static final int CODE =
212
	// * GeometryManager.getInstance()
213
	// * .registerGeometryOperation("MyOperation", MyOperation.class,
214
	// myGeomType);
215
	// * }
216
	// * </pre>
217
	// *
218
	// * @param geomOpName Operation's unique name
219
	// * @param geomOpClass GeometryOperation class
220
	// * @param geomType GeometryType instance to which this operation should be
221
	// associated
222
	// * @return Index assigned to this operation. This index is used later to
223
	// access the operation.
224
	// * @throws IllegalAccessException, {@link InstantiationException} Either
225
	// exception maybe thrown when
226
	// * trying to instance the geometry operation class.
227
	// */
228
	// private int registerGeometryOperation(String geomOpName, Class
229
	// geomOpClass,
230
	// GeometryType geomType)
231
	// throws IllegalAccessException, InstantiationException {
232
	//
233
	// GeometryOperation geomOp = (GeometryOperation) geomOpClass.newInstance();
234
	// return registerGeometryOperation(geomOpName, geomOp, geomType);
235
	// }
189
    // /**
190
    // * Registers a GeometryOperation associated to a GeometryType.
191
    // * Returns an unique index that is used later to identify and invoke the
192
    // operation.<br>
193
    // *
194
    // * By convention, the return value should be stored in a public constant
195
    // within the class implementing
196
    // * the operation:<BR>
197
    // * <pre>
198
    // * public class MyOperation extends GeometryOperation {
199
    // * public static final int CODE =
200
    // * GeometryManager.getInstance()
201
    // * .registerGeometryOperation("MyOperation", new MyOperation(),
202
    // MyGeometry.class);
203
    // * }
204
    // * </pre>
205
    // *
206
    // * This method is only used if you have not a reference to the
207
    // GeometryType associated to the
208
    // * geometry class. If you have such reference then it is slightly faster
209
    // to use the method that receives
210
    // * the GeometryType.<br>
211
    // *
212
    // * @param geomOpName Operation's unique name
213
    // * @param geomOp Specific GeometryOperation's instance implementing this
214
    // operation
215
    // * @param geomClass Geometry implementation class
216
    // * @return Index assigned to this operation. This index is used later to
217
    // access the operation.
218
    // */
219
    // private int registerGeometryOperation(String geomOpName,
220
    // GeometryOperation geomOp, Class geomClass) {
221
    //
222
    // GeometryType geomType = getGeometryType(geomClass);
223
    // return registerGeometryOperation(geomOpName, geomOp, geomType);
224
    // }
236 225

  
237
	/* (non-Javadoc)
238
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation, int, int)
239
	 */
240
	public int registerGeometryOperation(String geomOpName,
241
			GeometryOperation geomOp, int type, int subType) throws GeometryTypeNotSupportedException, GeometryTypeNotValidException {
242
		GeometryType geometryType = getGeometryType(type, subType);
243
		return registerGeometryOperation(geomOpName, geomOp, geometryType);
244
	}
226
    // /**
227
    // * Registers a GeometryOperation associated to a GeometryType.
228
    // * Returns an unique index that is used later to identify and invoke the
229
    // operation.<br>
230
    // *
231
    // * By convention, the return value should be stored in a public constant
232
    // within the class implementing
233
    // * the operation:<BR>
234
    // * <pre>
235
    // * public class MyOperation extends GeometryOperation {
236
    // * public static final int CODE =
237
    // * GeometryManager.getInstance()
238
    // * .registerGeometryOperation("MyOperation", MyOperation.class,
239
    // myGeomType);
240
    // * }
241
    // * </pre>
242
    // *
243
    // * @param geomOpName Operation's unique name
244
    // * @param geomOpClass GeometryOperation class
245
    // * @param geomType GeometryType instance to which this operation should be
246
    // associated
247
    // * @return Index assigned to this operation. This index is used later to
248
    // access the operation.
249
    // * @throws IllegalAccessException, {@link InstantiationException} Either
250
    // exception maybe thrown when
251
    // * trying to instance the geometry operation class.
252
    // */
253
    // private int registerGeometryOperation(String geomOpName, Class
254
    // geomOpClass,
255
    // GeometryType geomType)
256
    // throws IllegalAccessException, InstantiationException {
257
    //
258
    // GeometryOperation geomOp = (GeometryOperation) geomOpClass.newInstance();
259
    // return registerGeometryOperation(geomOpName, geomOp, geomType);
260
    // }
245 261

  
246
	/* (non-Javadoc)
247
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation, int)
248
	 */
249
	public int registerGeometryOperation(String geomOpName,
250
			GeometryOperation geomOp, int type) {
251
		Iterator it = geometryTypeName.keySet().iterator();
252
		int code = -1;
253
		while (it.hasNext()){
254
			String className = (String)it.next();
255
			GeometryType geometryType = (GeometryType) geometryTypeName.get(className);
256
			if ((type == geometryType.getType())) {
257
				code = registerGeometryOperation(geomOpName, geomOp, geometryType);
258
			}
259
		}
260
		return code;
261
	}
262
    /*
263
     * (non-Javadoc)
264
     * 
265
     * @see
266
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang
267
     * .String, org.gvsig.fmap.geom.operation.GeometryOperation, int, int)
268
     */
269
    public int registerGeometryOperation(String geomOpName,
270
        GeometryOperation geomOp, int type, int subType)
271
        throws GeometryTypeNotSupportedException, GeometryTypeNotValidException {
272
        GeometryType geometryType = getGeometryType(type, subType);
273
        return registerGeometryOperation(geomOpName, geomOp, geometryType);
274
    }
262 275

  
263
	/* (non-Javadoc)
264
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryOperationBySubtype(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation, int)
265
	 */
266
	public int registerGeometryOperationBySubtype(String geomOpName,
267
			GeometryOperation geomOp, int subType) {
268
		Iterator it = geometryTypeName.keySet().iterator();
269
		int code = -1;
270
		while (it.hasNext()){
271
			String className = (String)it.next();
272
			GeometryType geometryType = (GeometryType) geometryTypeName.get(className);
273
			if ((subType == geometryType.getSubType())) {
274
				code = registerGeometryOperation(geomOpName, geomOp, geometryType);
275
			}
276
		}
277
		return code;
278
	}
276
    /*
277
     * (non-Javadoc)
278
     * 
279
     * @see
280
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryOperation(java.lang
281
     * .String, org.gvsig.fmap.geom.operation.GeometryOperation, int)
282
     */
283
    public int registerGeometryOperation(String geomOpName,
284
        GeometryOperation geomOp, int type) {
285
        Iterator it = geometryTypeName.keySet().iterator();
286
        int code = -1;
287
        while (it.hasNext()) {
288
            String className = (String) it.next();
289
            GeometryType geometryType =
290
                (GeometryType) geometryTypeName.get(className);
291
            if ((type == geometryType.getType())) {
292
                code =
293
                    registerGeometryOperation(geomOpName, geomOp, geometryType);
294
            }
295
        }
296
        return code;
297
    }
279 298

  
280
	/*
281
	 * (non-Javadoc)
282
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryType(java.lang.Class, java.lang.String, int)
283
	 */
284
	public GeometryType registerGeometryType(Class geomClass, String name, int type, int subType) {
285
		return registerGeometryType(geomClass, name, geometryTypeIndex++, type, subType);
286
	}
299
    /*
300
     * (non-Javadoc)
301
     * 
302
     * @see
303
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryOperationBySubtype
304
     * (java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperation, int)
305
     */
306
    public int registerGeometryOperationBySubtype(String geomOpName,
307
        GeometryOperation geomOp, int subType) {
308
        Iterator it = geometryTypeName.keySet().iterator();
309
        int code = -1;
310
        while (it.hasNext()) {
311
            String className = (String) it.next();
312
            GeometryType geometryType =
313
                (GeometryType) geometryTypeName.get(className);
314
            if ((subType == geometryType.getSubType())) {
315
                code =
316
                    registerGeometryOperation(geomOpName, geomOp, geometryType);
317
            }
318
        }
319
        return code;
320
    }
287 321

  
288
	/**
289
	 * Registers a Geometry implementation class with a predefined geometry type and returns the
290
	 * associated GeometryType instance. Available predefined types are defined in {@link Geometry.TYPES}
291
	 * If the class is already registered then this method throws an IllegalArgumentException.<br>
292
	 *
293
	 * How to register a geometry class with a predefined type:
294
	 * <pre>
295
	 *
296
	 * public class Point2D implements Point {
297
	 *   private static final GeometryType geomType = GeometryManager.getInstance()
298
	 *	   .registerBasicGeometryType(Point2D.class, "Point2D", Geometry.TYPES.POINT);
299
	 *
300
	 *   public static final int CODE = geomType.getId();
301
	 * ...
302
	 *   public int getType() {
303
	 *      return geomType.getType();
304
	 *   }
305
	 * }
306
	 * </pre>
307
	 *
308
	 * @param geomClass
309
	 *            Geometry subclass. It must not be null and must implement Geometry, otherwise an exception
310
	 *            is raised.
311
	 * @param name
312
	 * 			  Symbolic name for the geometry type, it can be null. If it is null then the symbolic name
313
	 * 		      will be the simple class name.
314
	 * @param id
315
	 * 			  Geometry identifier.
316
	 * @param type
317
	 * 			  Type of geometry. Must be a value defined in {@link Geometry.TYPES}
318
	 * @param subType
319
	 * SubType of geometry. Must be a value defined in {@link Geometry.SUBTYPES}
320
	 * @return Instance of GeometryType associated to the Geometry implementation class
321
	 *         geomClass
322
	 * @throws IllegalArgumentException
323
	 *             If geomClass is null or does not implement Geometry
324
	 */
325
	private GeometryType registerGeometryType(Class geomClass, String name, int id,
326
			int type, int subType){
327
		if (geomClass == null) {
328
			throw new IllegalArgumentException("geomClass cannot be null.");
329
		}
322
    /*
323
     * (non-Javadoc)
324
     * 
325
     * @see
326
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryType(java.lang.Class,
327
     * java.lang.String, int)
328
     */
329
    public GeometryType registerGeometryType(Class geomClass, String name,
330
        int type, int subType) {
331
        return registerGeometryType(geomClass, name, geometryTypeIndex++, type,
332
            subType);
333
    }
330 334

  
331
		if (!Geometry.class.isAssignableFrom(geomClass)) {
332
			throw new IllegalArgumentException(geomClass.getName()
333
					+ " must implement the Geometry interface");
334
		}
335
    /**
336
     * Registers a Geometry implementation class with a predefined geometry type
337
     * and returns the
338
     * associated GeometryType instance. Available predefined types are defined
339
     * in {@link Geometry.TYPES} If the class is already registered then this
340
     * method throws an IllegalArgumentException.<br>
341
     * 
342
     * How to register a geometry class with a predefined type:
343
     * 
344
     * <pre>
345
     * 
346
     * public class Point2D implements Point {
347
     *   private static final GeometryType geomType = GeometryManager.getInstance()
348
     *    .registerBasicGeometryType(Point2D.class, "Point2D", Geometry.TYPES.POINT);
349
     * 
350
     *   public static final int CODE = geomType.getId();
351
     * ...
352
     *   public int getType() {
353
     *      return geomType.getType();
354
     *   }
355
     * }
356
     * </pre>
357
     * 
358
     * @param geomClass
359
     *            Geometry subclass. It must not be null and must implement
360
     *            Geometry, otherwise an exception
361
     *            is raised.
362
     * @param name
363
     *            Symbolic name for the geometry type, it can be null. If it is
364
     *            null then the symbolic name
365
     *            will be the simple class name.
366
     * @param id
367
     *            Geometry identifier.
368
     * @param type
369
     *            Type of geometry. Must be a value defined in
370
     *            {@link Geometry.TYPES}
371
     * @param subType
372
     *            SubType of geometry. Must be a value defined in
373
     *            {@link Geometry.SUBTYPES}
374
     * @return Instance of GeometryType associated to the Geometry
375
     *         implementation class
376
     *         geomClass
377
     * @throws IllegalArgumentException
378
     *             If geomClass is null or does not implement Geometry
379
     */
380
    private GeometryType registerGeometryType(Class geomClass, String name,
381
        int id, int type, int subType) {
382
        if (geomClass == null) {
383
            throw new IllegalArgumentException("geomClass cannot be null.");
384
        }
335 385

  
336
		// Check if it is registered
337
		GeometryType geomType = null;
338
		if (type >= geometryTypes.length || subType >= geometryTypes[0].length
339
				|| (geomType = geometryTypes[type][subType]) == null) {
340
			geomType =
341
					new DefaultGeometryType(geomClass, name, id, type, subType);
342
			registerGeometryType(geomType);
343
			geometryTypeName.put(geomClass.getName(), geomType);
344
		}
386
        if (!Geometry.class.isAssignableFrom(geomClass)) {
387
            throw new IllegalArgumentException(geomClass.getName()
388
                + " must implement the Geometry interface");
389
        }
345 390

  
346
		logger.debug("Class {} registered with name {}", geomClass,
347
				geomType.getName());
391
        // Check if it is registered
392
        GeometryType geomType = null;
393
        if (type >= geometryTypes.length || subType >= geometryTypes[0].length
394
            || (geomType = geometryTypes[type][subType]) == null) {
395
            geomType =
396
                new DefaultGeometryType(geomClass, name, id, type, subType);
397
            registerGeometryType(geomType);
398
            geometryTypeName.put(geomClass.getName(), geomType);
399
        }
348 400

  
349
		return geomType;
350
	}
401
        logger.debug("Class {} registered with name {}", geomClass,
402
            geomType.getName());
351 403

  
352
	private void registerGeometryType(GeometryType geometryType) {
353
		if (geometryType.getType() >= geometryTypes.length
354
				|| geometryType.getSubType() >= geometryTypes[0].length) {
404
        return geomType;
405
    }
355 406

  
356
			// Recreate the geometry type matrix if the types
357
			// or subtypes don't fit
358
			int newTypesSize =
359
					geometryType.getType() < geometryTypes.length ? geometryTypes.length
360
							: geometryType.getType() + 1;
361
			int newSubTypesSize =
362
					geometryType.getSubType() < geometryTypes[0].length ? geometryTypes[0].length
363
							: geometryType.getSubType() + 1;
364
			GeometryType[][] newMatrix =
365
					new GeometryType[newTypesSize][newSubTypesSize];
407
    private void registerGeometryType(GeometryType geometryType) {
408
        if (geometryType.getType() >= geometryTypes.length
409
            || geometryType.getSubType() >= geometryTypes[0].length) {
366 410

  
367
			for (int i = 0; i < geometryTypes.length; i++) {
368
				System.arraycopy(geometryTypes[i], 0, newMatrix[i], 0,
369
						geometryTypes[i].length);
370
			}
371
			geometryTypes = newMatrix;
372
		}
411
            // Recreate the geometry type matrix if the types
412
            // or subtypes don't fit
413
            int newTypesSize =
414
                geometryType.getType() < geometryTypes.length
415
                    ? geometryTypes.length : geometryType.getType() + 1;
416
            int newSubTypesSize =
417
                geometryType.getSubType() < geometryTypes[0].length
418
                    ? geometryTypes[0].length : geometryType.getSubType() + 1;
419
            GeometryType[][] newMatrix =
420
                new GeometryType[newTypesSize][newSubTypesSize];
373 421

  
374
		geometryTypes[geometryType.getType()][geometryType.getSubType()] =
375
				geometryType;
376
	}
422
            for (int i = 0; i < geometryTypes.length; i++) {
423
                System.arraycopy(geometryTypes[i], 0, newMatrix[i], 0,
424
                    geometryTypes[i].length);
425
            }
426
            geometryTypes = newMatrix;
427
        }
377 428

  
378
	/*
379
	 * (non-Javadoc)
380
	 * @see org.gvsig.fmap.geom.GeometryManager#registerGeometryType(java.lang.Class, int)
381
	 */
382
	public GeometryType registerGeometryType(Class geomClass, int type, int subType) {
383
		return registerGeometryType(geomClass, null, type, subType);
384
	}
429
        geometryTypes[geometryType.getType()][geometryType.getSubType()] =
430
            geometryType;
431
    }
385 432

  
386
	// /**
387
	// * Returns an instance of GeometryType given the associated Geometry
388
	// implementation
389
	// * class.
390
	// *
391
	// * @param geomClass
392
	// * @return Instance of GeometryType associated to the Geometry
393
	// implementation class
394
	// */
395
	// private GeometryType getGeometryType(Class geomClass) {
396
	// logger.debug("getting " + geomClass.getName());
397
	// return (GeometryType) geometryTypeName.get(geomClass.getName());
398
	// }
433
    /*
434
     * (non-Javadoc)
435
     * 
436
     * @see
437
     * org.gvsig.fmap.geom.GeometryManager#registerGeometryType(java.lang.Class,
438
     * int)
439
     */
440
    public GeometryType registerGeometryType(Class geomClass, int type,
441
        int subType) {
442
        return registerGeometryType(geomClass, null, type, subType);
443
    }
399 444

  
400
	/*
401
	 * (non-Javadoc)
402
	 * @see org.gvsig.fmap.geom.GeometryManager#getGeometryType(java.lang.String)
403
	 */
404
	public GeometryType getGeometryType(String className) throws GeometryTypeNotSupportedException {
405
		if (!geometryTypeName.containsKey(className)){
406
			throw new GeometryTypeNotSupportedException(className);
407
		}
408
		return (GeometryType) geometryTypeName.get(className);
409
	}
445
    // /**
446
    // * Returns an instance of GeometryType given the associated Geometry
447
    // implementation
448
    // * class.
449
    // *
450
    // * @param geomClass
451
    // * @return Instance of GeometryType associated to the Geometry
452
    // implementation class
453
    // */
454
    // private GeometryType getGeometryType(Class geomClass) {
455
    // logger.debug("getting " + geomClass.getName());
456
    // return (GeometryType) geometryTypeName.get(geomClass.getName());
457
    // }
410 458

  
411
	/* (non-Javadoc)
412
	 * @see org.gvsig.fmap.geom.GeometryManager#getGeometryType(int, int)
413
	 */
414
	public GeometryType getGeometryType(int type, int subType) throws GeometryTypeNotSupportedException, GeometryTypeNotValidException {
415
		GeometryType gType = null;
416
		if (type >= geometryTypes.length || subType >= geometryTypes[0].length) {
417
			throw new GeometryTypeNotValidException(type, subType);
418
		}
459
    /*
460
     * (non-Javadoc)
461
     * 
462
     * @see
463
     * org.gvsig.fmap.geom.GeometryManager#getGeometryType(java.lang.String)
464
     */
465
    public GeometryType getGeometryType(String className)
466
        throws GeometryTypeNotSupportedException {
467
        if (!geometryTypeName.containsKey(className)) {
468
            throw new GeometryTypeNotSupportedException(className);
469
        }
470
        return (GeometryType) geometryTypeName.get(className);
471
    }
419 472

  
420
		gType = geometryTypes[type][subType];
473
    /*
474
     * (non-Javadoc)
475
     * 
476
     * @see org.gvsig.fmap.geom.GeometryManager#getGeometryType(int, int)
477
     */
478
    public GeometryType getGeometryType(int type, int subType)
479
        throws GeometryTypeNotSupportedException, GeometryTypeNotValidException {
480
        GeometryType gType = null;
481
        if (type >= geometryTypes.length || subType >= geometryTypes[0].length) {
482
            throw new GeometryTypeNotValidException(type, subType);
483
        }
421 484

  
422
		if (gType == null) {
423
			throw new GeometryTypeNotSupportedException(type, subType);
424
		}
485
        gType = geometryTypes[type][subType];
425 486

  
426
		return gType;
487
        if (gType == null) {
488
            throw new GeometryTypeNotSupportedException(type, subType);
489
        }
427 490

  
428
		// Iterator it = geometryTypeName.keySet().iterator();
429
		// while (it.hasNext()){
430
		// String className = (String)it.next();
431
		// GeometryType geometryType = getGeometryType(className);
432
		// if ((type == geometryType.getType()) &&
433
		// (subType == geometryType.getSubType())){
434
		// return geometryType;
435
		// }
436
		// if (subType == SUBTYPES.UNKNOWN){
437
		// throw new GeometryTypeNotValidException(type, subType);
438
		// }
439
		// }
440
		// throw new GeometryTypeNotSupportedException(type, subType);
441
	}
491
        return gType;
442 492

  
443
	/*
444
	 * (non-Javadoc)
445
	 * @see org.gvsig.fmap.geom.GeometryManager#create(org.gvsig.fmap.geom.type.GeometryType)
446
	 */
447
	public Geometry create(GeometryType geomType) throws CreateGeometryException{
448
		return geomType.create();
449
	}
493
        // Iterator it = geometryTypeName.keySet().iterator();
494
        // while (it.hasNext()){
495
        // String className = (String)it.next();
496
        // GeometryType geometryType = getGeometryType(className);
497
        // if ((type == geometryType.getType()) &&
498
        // (subType == geometryType.getSubType())){
499
        // return geometryType;
500
        // }
501
        // if (subType == SUBTYPES.UNKNOWN){
502
        // throw new GeometryTypeNotValidException(type, subType);
503
        // }
504
        // }
505
        // throw new GeometryTypeNotSupportedException(type, subType);
506
    }
450 507

  
451
	/*
452
	 * (non-Javadoc)
453
	 * @see org.gvsig.fmap.geom.GeometryManager#create(java.lang.String)
454
	 */
455
	public Geometry create(String name) throws CreateGeometryException{
456
		if (!geometryTypeName.containsKey(name)){
457
			throw new IllegalArgumentException(name + " has not been registered yet.");
458
		}
459
		return ((GeometryType)geometryTypeName.get(name)).create();
460
	}
508
    /*
509
     * (non-Javadoc)
510
     * 
511
     * @see org.gvsig.fmap.geom.GeometryManager#create(org.gvsig.fmap.geom.type.
512
     * GeometryType)
513
     */
514
    public Geometry create(GeometryType geomType)
515
        throws CreateGeometryException {
516
        return geomType.create();
517
    }
461 518

  
462
	/*
463
	 * (non-Javadoc)
464
	 * @see org.gvsig.fmap.geom.GeometryManager#create(int)
465
	 */
466
	public Geometry create(int type, int subType)
467
			throws CreateGeometryException {
468
		try {
469
			return getGeometryType(type, subType).create();
470
		} catch (GeometryException e) {
471
			throw new CreateGeometryException(type, subType, e);
472
		}
473
	}
519
    /*
520
     * (non-Javadoc)
521
     * 
522
     * @see org.gvsig.fmap.geom.GeometryManager#create(java.lang.String)
523
     */
524
    public Geometry create(String name) throws CreateGeometryException {
525
        if (!geometryTypeName.containsKey(name)) {
526
            throw new IllegalArgumentException(name
527
                + " has not been registered yet.");
528
        }
529
        return ((GeometryType) geometryTypeName.get(name)).create();
530
    }
474 531

  
532
    /*
533
     * (non-Javadoc)
534
     * 
535
     * @see org.gvsig.fmap.geom.GeometryManager#create(int)
536
     */
537
    public Geometry create(int type, int subType)
538
        throws CreateGeometryException {
539
        try {
540
            return getGeometryType(type, subType).create();
541
        } catch (GeometryException e) {
542
            throw new CreateGeometryException(type, subType, e);
543
        }
544
    }
475 545

  
476
	/* (non-Javadoc)
477
	 * @see org.gvsig.fmap.geom.GeometryManager#createCurve(org.gvsig.fmap.geom.primitive.GeneralPathX, int)
478
	 */
479
	public Curve createCurve(GeneralPathX generalPathX, int subType)
480
			throws CreateGeometryException {
481
		Curve curve = (Curve)create(TYPES.CURVE, subType);
482
		curve.setGeneralPath(generalPathX);
483
		return curve;
484
	}
546
    /*
547
     * (non-Javadoc)
548
     * 
549
     * @see
550
     * org.gvsig.fmap.geom.GeometryManager#createCurve(org.gvsig.fmap.geom.primitive
551
     * .GeneralPathX, int)
552
     */
553
    public Curve createCurve(GeneralPathX generalPathX, int subType)
554
        throws CreateGeometryException {
555
        Curve curve = (Curve) create(TYPES.CURVE, subType);
556
        curve.setGeneralPath(generalPathX);
557
        return curve;
558
    }
485 559

  
486
	/* (non-Javadoc)
487
	 * @see org.gvsig.fmap.geom.GeometryManager#createNullGeometry(int)
488
	 */
489
	public NullGeometry createNullGeometry(int subType)
490
			throws CreateGeometryException {
491
		NullGeometry nullGeom = (NullGeometry)create(TYPES.NULL, subType);
492
		return nullGeom;
493
	}
560
    /*
561
     * (non-Javadoc)
562
     * 
563
     * @see org.gvsig.fmap.geom.GeometryManager#createNullGeometry(int)
564
     */
565
    public NullGeometry createNullGeometry(int subType)
566
        throws CreateGeometryException {
567
        NullGeometry nullGeom = (NullGeometry) create(TYPES.NULL, subType);
568
        return nullGeom;
569
    }
494 570

  
495
	/* (non-Javadoc)
496
	 * @see org.gvsig.fmap.geom.GeometryManager#createPoint(double, double, int)
497
	 */
498
	public Point createPoint(double x, double y, int subType)
499
			throws CreateGeometryException {
500
		Point point = (Point)create(TYPES.POINT, subType);
501
		point.setX(x);
502
		point.setY(y);
503
		return point;
504
	}
571
    /*
572
     * (non-Javadoc)
573
     * 
574
     * @see org.gvsig.fmap.geom.GeometryManager#createPoint(double, double, int)
575
     */
576
    public Point createPoint(double x, double y, int subType)
577
        throws CreateGeometryException {
578
        Point point = (Point) create(TYPES.POINT, subType);
579
        point.setX(x);
580
        point.setY(y);
581
        return point;
582
    }
505 583

  
506
	/* (non-Javadoc)
507
	 * @see org.gvsig.fmap.geom.GeometryManager#createSurface(org.gvsig.fmap.geom.primitive.GeneralPathX, int)
508
	 */
509
	public Surface createSurface(GeneralPathX generalPathX, int subType)
510
			throws CreateGeometryException {
511
		Surface surface = (Surface)create(TYPES.SURFACE, subType);
512
		surface.setGeneralPath(generalPathX);
513
		return surface;
514
	}
584
    /*
585
     * (non-Javadoc)
586
     * 
587
     * @see
588
     * org.gvsig.fmap.geom.GeometryManager#createSurface(org.gvsig.fmap.geom
589
     * .primitive.GeneralPathX, int)
590
     */
591
    public Surface createSurface(GeneralPathX generalPathX, int subType)
592
        throws CreateGeometryException {
593
        Surface surface = (Surface) create(TYPES.SURFACE, subType);
594
        surface.setGeneralPath(generalPathX);
595
        return surface;
596
    }
515 597

  
516
	/* (non-Javadoc)
517
	 * @see org.gvsig.fmap.geom.GeometryManager#getGeometryOperation(int, int, int)
518
	 */
519
	public GeometryOperation getGeometryOperation(int opCode, int type,
520
			int subType) throws GeometryTypeNotSupportedException,
521
			GeometryOperationNotSupportedException, GeometryTypeNotValidException {
522
		GeometryType geometryType = getGeometryType(type, subType);
523
		return geometryType.getGeometryOperation(opCode);
524
	}
598
    /*
599
     * (non-Javadoc)
600
     * 
601
     * @see org.gvsig.fmap.geom.GeometryManager#getGeometryOperation(int, int,
602
     * int)
603
     */
604
    public GeometryOperation getGeometryOperation(int opCode, int type,
605
        int subType) throws GeometryTypeNotSupportedException,
606
        GeometryOperationNotSupportedException, GeometryTypeNotValidException {
607
        GeometryType geometryType = getGeometryType(type, subType);
608
        return geometryType.getGeometryOperation(opCode);
609
    }
525 610

  
526
	//	/*
527
	//	 * (non-Javadoc)
528
	//	 * @see org.gvsig.fmap.geom.GeometryManager#getGeometryOperation(java.lang.Class, int)
529
	//	 */
530
	//	private GeometryOperation getGeometryOperation(Class geomClass, int opCode) throws GeometryTypeNotSupportedException, GeometryOperationNotSupportedException {
531
	//
532
	//		GeometryOperation geomOp = null;
533
	//
534
	//		// Check if it is a common operation, and if so, get it from the common registry
535
	//		if (opCode >= COMMON_OPS_OFFSET) {
536
	//			geomOp = ((GeometryOperation)commonOperations.get(opCode - COMMON_OPS_OFFSET));
537
	//
538
	//			if (geomOp == null) {
539
	//				throw new GeometryOperationNotSupportedException(opCode);
540
	//			}
541
	//		} else {
542
	//			// If it is type specific, get it from its type	registry
543
	//			if (geomClass != null) {
544
	//				GeometryType geomType = getGeometryType(geomClass);
545
	//
546
	//				// If the geometry type is not registered, throw an exception
547
	//				if (geomType == null) {
548
	//					throw new GeometryTypeNotSupportedException(geomClass);
549
	//				}
550
	//
551
	//				// Get the operation
552
	//				geomOp = geomType.getGeometryOperation(opCode);
553
	//
554
	//				// If the operation is not registered throw an exception
555
	//				if (geomOp == null) {
556
	//					throw new GeometryOperationNotSupportedException(opCode, geomType);
557
	//				}
558
	//			}
559
	//		}
560
	//		return geomOp;
561
	//	}
611
    // /*
612
    // * (non-Javadoc)
613
    // * @see
614
    // org.gvsig.fmap.geom.GeometryManager#getGeometryOperation(java.lang.Class,
615
    // int)
616
    // */
617
    // private GeometryOperation getGeometryOperation(Class geomClass, int
618
    // opCode) throws GeometryTypeNotSupportedException,
619
    // GeometryOperationNotSupportedException {
620
    //
621
    // GeometryOperation geomOp = null;
622
    //
623
    // // Check if it is a common operation, and if so, get it from the common
624
    // registry
625
    // if (opCode >= COMMON_OPS_OFFSET) {
626
    // geomOp = ((GeometryOperation)commonOperations.get(opCode -
627
    // COMMON_OPS_OFFSET));
628
    //
629
    // if (geomOp == null) {
630
    // throw new GeometryOperationNotSupportedException(opCode);
631
    // }
632
    // } else {
633
    // // If it is type specific, get it from its type registry
634
    // if (geomClass != null) {
635
    // GeometryType geomType = getGeometryType(geomClass);
636
    //
637
    // // If the geometry type is not registered, throw an exception
638
    // if (geomType == null) {
639
    // throw new GeometryTypeNotSupportedException(geomClass);
640
    // }
641
    //
642
    // // Get the operation
643
    // geomOp = geomType.getGeometryOperation(opCode);
644
    //
645
    // // If the operation is not registered throw an exception
646
    // if (geomOp == null) {
647
    // throw new GeometryOperationNotSupportedException(opCode, geomType);
648
    // }
649
    // }
650
    // }
651
    // return geomOp;
652
    // }
562 653

  
563
	/*
564
	 * (non-Javadoc)
565
	 * @see org.gvsig.fmap.geom.GeometryManager#invokeOperation(int, org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
566
	 */
567
	public Object invokeOperation(int opCode, Geometry geom, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException {
568
		GeometryOperation geomOp = geom.getGeometryType().getGeometryOperation(opCode);
654
    /*
655
     * (non-Javadoc)
656
     * 
657
     * @see org.gvsig.fmap.geom.GeometryManager#invokeOperation(int,
658
     * org.gvsig.fmap.geom.Geometry,
659
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
660
     */
661
    public Object invokeOperation(int opCode, Geometry geom,
662
        GeometryOperationContext ctx)
663
        throws GeometryOperationNotSupportedException,
664
        GeometryOperationException {
665
        GeometryOperation geomOp =
666
            geom.getGeometryType().getGeometryOperation(opCode);
569 667

  
570
		if (geomOp != null) {
571
			return geomOp.invoke(geom, ctx);
572
		}
668
        if (geomOp != null) {
669
            return geomOp.invoke(geom, ctx);
670
        }
573 671

  
574
		throw new GeometryOperationNotSupportedException(opCode, geom.getGeometryType());
575
	}
672
        throw new GeometryOperationNotSupportedException(opCode,
673
            geom.getGeometryType());
674
    }
576 675

  
577
	/* (non-Javadoc)
578
	 * @see org.gvsig.fmap.geom.GeometryManager#invokeOperation(java.lang.String, org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
579
	 */
580
	public Object invokeOperation(String geomOpName, Geometry geom,
581
			GeometryOperationContext ctx)
582
	throws GeometryOperationNotSupportedException,
583
	GeometryOperationException {
584
		int index = geometryOperations.indexOf(geomOpName);
585
		if (index == -1){
586
			throw new GeometryOperationNotSupportedException(-1);
587
		}
588
		return invokeOperation(index, geom, ctx);
589
	}
590
	
591
	/*
592
	 * (non-Javadoc)
593
	 * @see org.gvsig.fmap.geom.GeometryManager#invokeOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperationContext)
594
	 */
595
	public Object invokeOperation(String geomOpName, GeometryOperationContext ctx) 
596
		throws GeometryOperationNotSupportedException, GeometryOperationException {
597
		int index = geometryOperations.indexOf(geomOpName);
598
		if (index == -1) 
599
			throw new GeometryOperationNotSupportedException(-1);
600
		DefaultGeometryType type = (DefaultGeometryType)geometryTypeName.get(DefaultNullGeometry.class.getName());
601
		if(type != null) {
602
			GeometryOperation geomOp = type.getGeometryOperation(index);
603
			return geomOp.invoke(null, ctx);
604
		}
605
		return null;
606
	}
676
    /*
677
     * (non-Javadoc)
678
     * 
679
     * @see
680
     * org.gvsig.fmap.geom.GeometryManager#invokeOperation(java.lang.String,
681
     * org.gvsig.fmap.geom.Geometry,
682
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
683
     */
684
    public Object invokeOperation(String geomOpName, Geometry geom,
685
        GeometryOperationContext ctx)
686
        throws GeometryOperationNotSupportedException,
687
        GeometryOperationException {
688
        int index = geometryOperations.indexOf(geomOpName);
689
        if (index == -1) {
690
            throw new GeometryOperationNotSupportedException(-1);
691
        }
692
        return invokeOperation(index, geom, ctx);
693
    }
607 694

  
608
	/*
609
	 * (non-Javadoc)
610
	 * @see org.gvsig.fmap.geom.GeometryManager#unregisterGeometryType(java.lang.Class)
611
	 */
612
	public GeometryType unregisterGeometryType(Class geomClass) {
613
		return (GeometryType) geometryTypeName.remove(geomClass.getName());
614
	}
695
    /*
696
     * (non-Javadoc)
697
     * 
698
     * @see
699
     * org.gvsig.fmap.geom.GeometryManager#invokeOperation(java.lang.String,
700
     * org.gvsig.fmap.geom.operation.GeometryOperationContext)
701
     */
702
    public Object invokeOperation(String geomOpName,
703
        GeometryOperationContext ctx)
704
        throws GeometryOperationNotSupportedException,
705
        GeometryOperationException {
706
        int index = geometryOperations.indexOf(geomOpName);
707
        if (index == -1)
708
            throw new GeometryOperationNotSupportedException(-1);
709
        DefaultGeometryType type =
710
            (DefaultGeometryType) geometryTypeName
711
                .get(DefaultNullGeometry.class.getName());
712
        if (type != null) {
713
            GeometryOperation geomOp = type.getGeometryOperation(index);
714
            return geomOp.invoke(null, ctx);
715
        }
716
        return null;
717
    }
615 718

  
616
	/* (non-Javadoc)
617
	 * @see org.gvsig.fmap.geom.GeometryManager#createEnvelope(int)
618
	 */
619
	public Envelope createEnvelope(int subType) {
620
		//TODO: register the envelopes!!!
621
		switch (subType){
622
		case SUBTYPES.GEOM2DZ:
623
		case SUBTYPES.GEOM3D:
624
			return new Envelope3D();
625
		default:
626
			return new Envelope2D();
627
		}
628
	}
719
    /*
720
     * (non-Javadoc)
721
     * 
722
     * @see
723
     * org.gvsig.fmap.geom.GeometryManager#unregisterGeometryType(java.lang.
724
     * Class)
725
     */
726
    public GeometryType unregisterGeometryType(Class geomClass) {
727
        return (GeometryType) geometryTypeName.remove(geomClass.getName());
728
    }
629 729

  
730
    /*
731
     * (non-Javadoc)
732
     * 
733
     * @see org.gvsig.fmap.geom.GeometryManager#createEnvelope(int)
734
     */
735
    public Envelope createEnvelope(int subType) {
736
        // TODO: register the envelopes!!!
737
        switch (subType) {
738
        case SUBTYPES.GEOM2DZ:
739
        case SUBTYPES.GEOM3D:
740
            return new Envelope3D();
741
        default:
742
            return new Envelope2D();
743
        }
744
    }
630 745

  
631
	/* (non-Javadoc)
632
	 * @see org.gvsig.fmap.geom.GeometryManager#createEnvelope(double, double, double, double)
633
	 */
634
	public Envelope createEnvelope(double minX, double minY, double maxX,
635
			double maxY, int subType) throws CreateEnvelopeException {
636
		org.gvsig.fmap.geom.primitive.Point min = null;
637
		org.gvsig.fmap.geom.primitive.Point max = null;
638
		try {
639
			GeometryType gType = getGeometryType(TYPES.POINT, subType);
640
			min = (Point) gType.create();
641
			min.setX(minX);
642
			min.setY(minY);
643
			max = (Point) gType.create();
644
			max.setX(maxX);
645
			max.setY(maxY);
646
			// min = createPoint(minX, minY, subType);
647
			// max = createPoint(maxX, maxY, subType);
648
		} catch (CreateGeometryException e) {
649
			throw new CreateEnvelopeException(subType, e);
650
		} catch (GeometryTypeNotSupportedException e) {
651
			throw new CreateEnvelopeException(subType, e);
652
		} catch (GeometryTypeNotValidException e) {
653
			throw new CreateEnvelopeException(subType, e);
654
		}
655
		switch (subType) {
656
		case SUBTYPES.GEOM2D:
657
		case SUBTYPES.GEOM2DM:
658
			// Small optimization to directly create an Envelope2D
659
			// return new Envelope2D(minX, minY, maxX, maxY);
660
			return new Envelope2D(min, max);
661
		default:
662
			Envelope envelope = createEnvelope(subType);
663
			envelope.setLowerCorner(min);
664
			envelope.setUpperCorner(max);
665
			return envelope;
666
		}
667
	}
746
    /*
747
     * (non-Javadoc)
748
     * 
749
     * @see org.gvsig.fmap.geom.GeometryManager#createEnvelope(double, double,
750
     * double, double)
751
     */
752
    public Envelope createEnvelope(double minX, double minY, double maxX,
753
        double maxY, int subType) throws CreateEnvelopeException {
754
        org.gvsig.fmap.geom.primitive.Point min = null;
755
        org.gvsig.fmap.geom.primitive.Point max = null;
756
        try {
757
            GeometryType gType = getGeometryType(TYPES.POINT, subType);
758
            min = (Point) gType.create();
759
            min.setX(minX);
760
            min.setY(minY);
761
            max = (Point) gType.create();
762
            max.setX(maxX);
763
            max.setY(maxY);
764
            // min = createPoint(minX, minY, subType);
765
            // max = createPoint(maxX, maxY, subType);
766
        } catch (CreateGeometryException e) {
767
            throw new CreateEnvelopeException(subType, e);
768
        } catch (GeometryTypeNotSupportedException e) {
769
            throw new CreateEnvelopeException(subType, e);
770
        } catch (GeometryTypeNotValidException e) {
771
            throw new CreateEnvelopeException(subType, e);
772
        }
773
        switch (subType) {
774
        case SUBTYPES.GEOM2D:
775
        case SUBTYPES.GEOM2DM:
776
            // Small optimization to directly create an Envelope2D
777
            // return new Envelope2D(minX, minY, maxX, maxY);
778
            return new Envelope2D(min, max);
779
        default:
780
            Envelope envelope = createEnvelope(subType);
781
            envelope.setLowerCorner(min);
782
            envelope.setUpperCorner(max);
783
            return envelope;
784
        }
785
    }
668 786

  
669
	public MultiCurve createMultiCurve(GeneralPathX generalPathX, int subType)
670
			throws CreateGeometryException {
671
		if (subType != SUBTYPES.GEOM2D){
672
			// FIXME Exception
673
			throw new UnsupportedOperationException();
674
		}
675
		MultiCurve multiCurve = (MultiCurve) create(TYPES.MULTICURVE, subType);
676
		PathIterator piter = generalPathX.getPathIterator(null);
677
		GeneralPathX tmpPath = null;
678
		Curve tmpCurve = null;
679
		double[] coords = new double[6];
680
		double[] first = new double[6];
681
		int type;
682
		while (!piter.isDone()) {
683
			type = piter.currentSegment(coords);
684
			switch (type) {
685
			case PathIterator.SEG_MOVETO:
686
				if (tmpPath != null){
687
					tmpCurve = createCurve(tmpPath, subType);
688
					multiCurve.addCurve(tmpCurve);
689
				}
690
				System.arraycopy(coords, 0, first, 0, 2);
691
				tmpPath =  new GeneralPathX(piter.getWindingRule());
692
				tmpPath.moveTo(coords[0], coords[1]);
693
				break;
787
    public MultiCurve createMultiCurve(GeneralPathX generalPathX, int subType)
788
        throws CreateGeometryException {
789
        if (subType != SUBTYPES.GEOM2D) {
790
            // FIXME Exception
791
            throw new UnsupportedOperationException();
792
        }
793
        MultiCurve multiCurve = (MultiCurve) create(TYPES.MULTICURVE, subType);
794
        PathIterator piter = generalPathX.getPathIterator(null);
795
        GeneralPathX tmpPath = null;
796
        Curve tmpCurve = null;
797
        double[] coords = new double[6];
798
        double[] first = new double[6];
799
        int type;
800
        while (!piter.isDone()) {
801
            type = piter.currentSegment(coords);
802
            switch (type) {
803
            case PathIterator.SEG_MOVETO:
804
                if (tmpPath != null) {
805
                    tmpCurve = createCurve(tmpPath, subType);
806
                    multiCurve.addCurve(tmpCurve);
807
                }
808
                System.arraycopy(coords, 0, first, 0, 2);
809
                tmpPath = new GeneralPathX(piter.getWindingRule());
810
                tmpPath.moveTo(coords[0], coords[1]);
811
                break;
694 812

  
813
            case PathIterator.SEG_LINETO:
814
                if (tmpPath == null) {
815
                    System.arraycopy(coords, 0, first, 0, 2);
816
                    tmpPath = new GeneralPathX(piter.getWindingRule());
817
                }
818
                tmpPath.lineTo(coords[0], coords[1]);
819
                break;
695 820

  
696
			case PathIterator.SEG_LINETO:
697
				if (tmpPath == null) {
698
					System.arraycopy(coords, 0, first, 0, 2);
699
					tmpPath = new GeneralPathX(piter.getWindingRule());
700
				}
701
				tmpPath.lineTo(coords[0], coords[1]);
702
				break;
821
            case PathIterator.SEG_QUADTO:
822
                if (tmpPath == null) {
823
                    System.arraycopy(coords, 0, first, 0, 2);
824
                    tmpPath = new GeneralPathX(piter.getWindingRule());
825
                }
826
                tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
827
                break;
703 828

  
829
            case PathIterator.SEG_CUBICTO:
830
                if (tmpPath == null) {
831
                    System.arraycopy(coords, 0, first, 0, 2);
832
                    tmpPath = new GeneralPathX(piter.getWindingRule());
833
                }
834
                tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3],
835
                    coords[4], coords[5]);
836
                break;
704 837

  
705
			case PathIterator.SEG_QUADTO:
706
				if (tmpPath == null) {
707
					System.arraycopy(coords, 0, first, 0, 2);
708
					tmpPath = new GeneralPathX(piter.getWindingRule());
709
				}
710
				tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
711
				break;
838
            case PathIterator.SEG_CLOSE:
839
                tmpPath.lineTo(first[0], first[1]);
840
                break;
712 841

  
713
			case PathIterator.SEG_CUBICTO:
714
				if (tmpPath == null) {
715
					System.arraycopy(coords, 0, first, 0, 2);
716
					tmpPath = new GeneralPathX(piter.getWindingRule());
717
				}
718
				tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3],
719
						coords[4], coords[5]);
720
				 break;
842
            } // end switch
721 843

  
722
			case PathIterator.SEG_CLOSE:
723
				tmpPath.lineTo(first[0], first[1]);
724
				 break;
844
            piter.next();
725 845

  
726
			} // end switch
846
        }
847
        if (tmpPath != null) {
848
            tmpCurve = createCurve(tmpPath, subType);
849
            multiCurve.addCurve(tmpCurve);
850
        }
727 851

  
728
			piter.next();
852
        return multiCurve;
729 853

  
730
		}
731
		if (tmpPath != null) {
732
			tmpCurve = createCurve(tmpPath, subType);
733
			multiCurve.addCurve(tmpCurve);
734
		}
854
    }
735 855

  
736
		return multiCurve;
856
    public MultiSurface createMultiSurface(GeneralPathX generalPathX,
857
        int subType) throws CreateGeometryException {
858
        if (subType != SUBTYPES.GEOM2D) {
859
            // FIXME Exception
860
            throw new UnsupportedOperationException();
861
        }
862
        MultiSurface multiSurface =
863
            (MultiSurface) create(TYPES.MULTISURFACE, subType);
864
        PathIterator piter = generalPathX.getPathIterator(null);
865
        GeneralPathX tmpPath = null;
866
        Surface tmpSurface = null;
867
        double[] coords = new double[6];
868
        double[] first = new double[6];
869
        int type;
870
        while (!piter.isDone()) {
871
            type = piter.currentSegment(coords);
872
            switch (type) {
873
            case PathIterator.SEG_MOVETO:
874
                if (tmpPath != null) {
875
                    tmpSurface = createSurface(tmpPath, subType);
876
                    multiSurface.addSurface(tmpSurface);
877
                }
878
                System.arraycopy(coords, 0, first, 0, 2);
879
                tmpPath = new GeneralPathX(piter.getWindingRule());
880
                tmpPath.moveTo(coords[0], coords[1]);
737 881

  
738
	}
882
            case PathIterator.SEG_LINETO:
883
                if (tmpPath == null) {
884
                    System.arraycopy(coords, 0, first, 0, 2);
885
                    tmpPath = new GeneralPathX(piter.getWindingRule());
886
                }
887
                tmpPath.lineTo(coords[0], coords[1]);
888
                break;
739 889

  
740
	public MultiSurface createMultiSurface(GeneralPathX generalPathX,
741
			int subType) throws CreateGeometryException {
742
		if (subType != SUBTYPES.GEOM2D) {
743
			// FIXME Exception
744
			throw new UnsupportedOperationException();
745
		}
746
		MultiSurface multiSurface = (MultiSurface) create(TYPES.MULTISURFACE,
747
				subType);
748
		PathIterator piter = generalPathX.getPathIterator(null);
749
		GeneralPathX tmpPath = null;
750
		Surface tmpSurface = null;
751
		double[] coords = new double[6];
752
		double[] first = new double[6];
753
		int type;
754
		while (!piter.isDone()) {
755
			type = piter.currentSegment(coords);
756
			switch (type) {
757
			case PathIterator.SEG_MOVETO:
758
				if (tmpPath != null) {
759
					tmpSurface = createSurface(tmpPath, subType);
760
					multiSurface.addSurface(tmpSurface);
761
				}
762
				System.arraycopy(coords, 0, first, 0, 2);
763
				tmpPath = new GeneralPathX(piter.getWindingRule());
764
				tmpPath.moveTo(coords[0], coords[1]);
890
            case PathIterator.SEG_QUADTO:
891
                if (tmpPath == null) {
892
                    System.arraycopy(coords, 0, first, 0, 2);
893
                    tmpPath = new GeneralPathX(piter.getWindingRule());
894
                }
895
                tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
896
                break;
765 897

  
766
			case PathIterator.SEG_LINETO:
767
				if (tmpPath == null) {
768
					System.arraycopy(coords, 0, first, 0, 2);
769
					tmpPath = new GeneralPathX(piter.getWindingRule());
770
				}
771
				tmpPath.lineTo(coords[0], coords[1]);
772
				break;
898
            case PathIterator.SEG_CUBICTO:
899
                if (tmpPath == null) {
900
                    System.arraycopy(coords, 0, first, 0, 2);
901
                    tmpPath = new GeneralPathX(piter.getWindingRule());
902
                }
903
                tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3],
904
                    coords[4], coords[5]);
905
                break;
773 906

  
907
            case PathIterator.SEG_CLOSE:
908
                tmpPath.lineTo(first[0], first[1]);
909
                break;
910
            } // end switch
774 911

  
775
			case PathIterator.SEG_QUADTO:
776
				if (tmpPath == null) {
777
					System.arraycopy(coords, 0, first, 0, 2);
778
					tmpPath = new GeneralPathX(piter.getWindingRule());
779
				}
780
				tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
781
				break;
912
            piter.next();
782 913

  
783
			case PathIterator.SEG_CUBICTO:
784
				if (tmpPath == null) {
785
					System.arraycopy(coords, 0, first, 0, 2);
786
					tmpPath = new GeneralPathX(piter.getWindingRule());
787
				}
788
				tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3],
789
						coords[4], coords[5]);
790
				break;
914
        }
915
        if (tmpPath != null) {
916
            tmpSurface = createSurface(tmpPath, subType);
917
            multiSurface.addSurface(tmpSurface);
918
        }
791 919

  
792
			case PathIterator.SEG_CLOSE:
793
				tmpPath.lineTo(first[0], first[1]);
794
				break;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff