Revision 19644

View differences:

trunk/libraries/libTopology/src/org/gvsig/topology/Topology.java
43 43
 */
44 44
/* CVS MESSAGES:
45 45
 *
46
 * $Id:
47
 * $Log:
46
 * $Id: 
47
 * $Log: 
48 48
 */
49 49
package org.gvsig.topology;
50 50

  
......
91 91
import com.iver.utiles.swing.threads.CancellableProgressTask;
92 92

  
93 93
/**
94
 *
95
 * This class represents a Topology, as a group of vectorial layers
96
 * and topology rules that checks geometries and their spatial relationships of
97
 * these layers.
98
 *
99
 * It extends FLayers to reuse all already existent code related with
100
 * groups of layers (TOC related, etc.)
101
 *
102
 * TODO Study if we must syncronize writing methods (validate, markAsException, addError,
103
 * ruleId++, etc)
104
 *
105
 *
94
 * 
95
 * This class represents a Topology, as a group of vectorial layers and topology
96
 * rules that checks geometries and their spatial relationships of these layers.
97
 * 
98
 * It extends FLayers to reuse all already existent code related with groups of
99
 * layers (TOC related, etc.)
100
 * 
101
 * TODO Study if we must syncronize writing methods (validate, markAsException,
102
 * addError, ruleId++, etc)
103
 * 
104
 * 
106 105
 * @author azabala
107
 *
106
 * 
108 107
 */
109
public class Topology extends FLayers implements ITopologyStatus, ITopologyErrorContainer, Cloneable {
108
public class Topology extends FLayers implements ITopologyStatus,
109
		ITopologyErrorContainer, Cloneable {
110 110

  
111 111
	private static Logger logger = Logger.getLogger(Topology.class.getName());
112 112

  
113
	private final static ImageIcon NOT_VALIDATED_TOC_ICON =
114
		new ImageIcon(Topology.class.getResource("images/topoicon.png"));
113
	private final static ImageIcon NOT_VALIDATED_TOC_ICON = new ImageIcon(
114
			Topology.class.getResource("images/topoicon.png"));
115 115

  
116
	private final static ImageIcon VALIDATED_TOC_ICON =
117
		new ImageIcon(Topology.class.getResource("images/topoicon_validated.png"));
116
	private final static ImageIcon VALIDATED_TOC_ICON = new ImageIcon(
117
			Topology.class.getResource("images/topoicon_validated.png"));
118 118

  
119
	private final static ImageIcon VALIDATED_WITH_ERRORS_TOC_ICON =
120
		new ImageIcon(Topology.class.getResource("images/topoicon_validated_with_errors.png"));
119
	private final static ImageIcon VALIDATED_WITH_ERRORS_TOC_ICON = new ImageIcon(
120
			Topology.class
121
					.getResource("images/topoicon_validated_with_errors.png"));
121 122

  
122
	private final static ImageIcon EMPTY_TOC_ICON =
123
		new ImageIcon(Topology.class.getResource("images/topoicon_empty.png"));
123
	private final static ImageIcon EMPTY_TOC_ICON = new ImageIcon(
124
			Topology.class.getResource("images/topoicon_empty.png"));
124 125

  
125
	private final static ImageIcon VALIDATED_WITH_DIRTY_ZONES_TOC_ICON =
126
		new ImageIcon(Topology.class.getResource("images/topoicon_validated_with_dirty_zones.png"));
126
	private final static ImageIcon VALIDATED_WITH_DIRTY_ZONES_TOC_ICON = new ImageIcon(
127
			Topology.class
128
					.getResource("images/topoicon_validated_with_dirty_zones.png"));
127 129

  
128
	private final static ImageIcon VALIDATING_TOC_ICON =
129
		new ImageIcon(Topology.class.getResource("images/topoicon_validating.png"));
130
	private final static ImageIcon VALIDATING_TOC_ICON = new ImageIcon(
131
			Topology.class.getResource("images/topoicon_validating.png"));
130 132

  
131 133
	private ImageIcon statusIcon = EMPTY_TOC_ICON;
132 134

  
......
145 147
	 */
146 148
	private byte status = EMPTY;
147 149

  
148

  
149 150
	/**
150 151
	 * If during validation process a topoly exceeds this parameters, validation
151 152
	 * will be stopped.
152
	 *
153
	 * 
153 154
	 */
154 155
	private int maxNumberOfErrors = -1;
155 156

  
156

  
157 157
	/**
158 158
	 * topology rules of the topology
159 159
	 */
160 160
	private List<ITopologyRule> rules;
161 161

  
162

  
163 162
	/**
164 163
	 * Each layer of a topology must have a cluster tolerance rule
165 164
	 */
166 165
	private List<MustBeLargerThanClusterTolerance> clusterToleranceRules;
167 166

  
168

  
169 167
	/**
170 168
	 * Regions of the topology to be validated
171 169
	 */
......
178 176
	private ITopologyErrorContainer errorContainer;
179 177

  
180 178
	/**
181
	 * Collection of error layers created from topology errors in topology
182
	 * error container.
179
	 * Collection of error layers created from topology errors in topology error
180
	 * container.
183 181
	 */
184 182
	private FLayer errorLayer;
185 183

  
......
188 186
	 */
189 187
	private List<ITopologyStatusListener> statusListeners;
190 188

  
191

  
192 189
	/**
193 190
	 * Map that relates a FLyrVect of the Topology with its rank (weight when we
194 191
	 * are going to snap many coordinates)
......
201 198
	private int ruleId = 0;
202 199

  
203 200
	/**
204
	 * Interface for all of these classes interested in listening topology change status
205
	 * events.
201
	 * Interface for all of these classes interested in listening topology
202
	 * change status events.
203
	 * 
206 204
	 * @author Alvaro Zabala
207
	 *
205
	 * 
208 206
	 */
209
	public interface ITopologyStatusListener{
207
	public interface ITopologyStatusListener {
210 208
		public void statusChange(TopologyStatusEvent event);
211 209
	}
212 210

  
213 211
	/**
214 212
	 * Topology change status event. It contains old and new topology status.
213
	 * 
215 214
	 * @author Alvaro Zabala
216
	 *
215
	 * 
217 216
	 */
218
	public class TopologyStatusEvent{
217
	public class TopologyStatusEvent {
219 218
		int newStatus;
220 219
		int prevStatus;
221 220
	}
222 221

  
223 222
	/**
224 223
	 * Default constructor for a topology as a FLayers
225
	 *
224
	 * 
226 225
	 * @param fmap
227 226
	 * @param parent
228 227
	 */
229
	public Topology(MapContext fmap,
230
					FLayers parent,
231
					double clusterTolerance,
232
					int numberOfErrors,
233
					ITopologyErrorContainer errorContainer) {
228
	public Topology(MapContext fmap, FLayers parent, double clusterTolerance,
229
			int numberOfErrors, ITopologyErrorContainer errorContainer) {
234 230
		super.setMapContext(fmap);
235 231
		super.setParentLayer(parent);
236 232
		this.clusterTolerance = clusterTolerance;
......
244 240
		layerRanks = new HashMap<FLyrVect, XYZLayerRank>();
245 241

  
246 242
		statusListeners = new ArrayList<ITopologyStatusListener>();
247
		//This listener updates the icon status returneb by this kind of layer
248
		statusListeners.add(new ITopologyStatusListener(){
243
		// This listener updates the icon status returneb by this kind of layer
244
		statusListeners.add(new ITopologyStatusListener() {
249 245
			public void statusChange(TopologyStatusEvent event) {
250
				switch(event.newStatus){
246
				switch (event.newStatus) {
251 247
				case ITopologyStatus.VALIDATED:
252 248
					statusIcon = VALIDATED_TOC_ICON;
253 249
					break;
......
268 264
					statusIcon = VALIDATING_TOC_ICON;
269 265
					break;
270 266
				}
271
			}});
267
			}
268
		});
272 269
	}
273 270

  
274
	public Topology(MapContext mapContext, FLayers layers){
271
	public Topology(MapContext mapContext, FLayers layers) {
275 272
		this(mapContext, layers, 0d, 1000, new SimpleTopologyErrorContainer());
276 273
	}
277 274

  
278

  
279
	public void addStatusListener(ITopologyStatusListener statusListener){
275
	public void addStatusListener(ITopologyStatusListener statusListener) {
280 276
		this.statusListeners.add(statusListener);
281 277
	}
282 278

  
283 279
	/**
284 280
	 * Creates a topology from its XML representation
281
	 * 
285 282
	 * @param xmlEntity
286 283
	 * @return
287 284
	 */
288
	public static Topology createFromXML(MapContext mapContext, XMLEntity xmlEntity){
285
	public static Topology createFromXML(MapContext mapContext,
286
			XMLEntity xmlEntity) {
289 287
		FLayers rootLyr = mapContext.getLayers();
290 288
		Topology solution = new Topology(mapContext, rootLyr);
291 289

  
292 290
		try {
293 291
			solution.setXMLEntity(xmlEntity);
294
			if(solution.getErrorContainer() == null){
292
			if (solution.getErrorContainer() == null) {
295 293
				solution.setErrorContainer(new SimpleTopologyErrorContainer());
296 294
			}
297 295
		} catch (XMLException e) {
298
			logger.error("Error al reconstruir la topologia desde fichero xml", e);
296
			logger.error("Error al reconstruir la topologia desde fichero xml",
297
					e);
299 298
		}
300 299
		return solution;
301 300
	}
......
310 309

  
311 310
	/**
312 311
	 * Changes the cluster tolerance of the topology
313
	 *
314
	 *
315
	 * This operation resets the status of the topology (it clears
316
	 * errors and dirty zones)
317
	 *
312
	 * 
313
	 * 
314
	 * This operation resets the status of the topology (it clears errors and
315
	 * dirty zones)
316
	 * 
318 317
	 * @param clusterTolerance
319 318
	 */
320 319
	public void setClusterTolerance(double clusterTolerance) {
321
		if(status == VALIDATING)
322
			return;//maybe we could launch an exception??
320
		if (status == VALIDATING)
321
			return;// maybe we could launch an exception??
323 322
		this.clusterTolerance = clusterTolerance;
324 323
		resetStatus();
325
		Iterator<MustBeLargerThanClusterTolerance> rulesIt = this.clusterToleranceRules.iterator();
326
		while(rulesIt.hasNext()){
324
		Iterator<MustBeLargerThanClusterTolerance> rulesIt = this.clusterToleranceRules
325
				.iterator();
326
		while (rulesIt.hasNext()) {
327 327
			MustBeLargerThanClusterTolerance rule = rulesIt.next();
328 328
			rule.setClusterTolerance(clusterTolerance);
329 329
		}
......
334 334
		return clusterTolerance;
335 335
	}
336 336

  
337
	public void resetStatus(){
337
	public void resetStatus() {
338 338
		setStatus(NOT_VALIDATED);
339 339
		this.clear();
340 340
		this.dirtyZones.clear();
......
343 343

  
344 344
	/**
345 345
	 * Adds a new topology rule to the topology.
346
	 *
346
	 * 
347 347
	 * The layers referenced by the rule must exist in the topology.
348
	 *
349
	 * The state of the topology changes to "NON_VALIDATED", and a new dirty zone
350
	 * is added for the scope of the new rule (envelope of one or two layers).
351
	 *
352
	 *
348
	 * 
349
	 * The state of the topology changes to "NON_VALIDATED", and a new dirty
350
	 * zone is added for the scope of the new rule (envelope of one or two
351
	 * layers).
352
	 * 
353
	 * 
353 354
	 * @throws TopologyRuleDefinitionException
354 355
	 */
355 356
	public void addRule(ITopologyRule rule) throws RuleNotAllowedException,
356 357
			TopologyRuleDefinitionException {
357 358

  
358
		if(status == VALIDATING)
359
			throw new RuleNotAllowedException("No se puede a?adir una regla si la topologia est? siendo validada");
359
		if (status == VALIDATING)
360
			throw new RuleNotAllowedException(
361
					"No se puede a?adir una regla si la topologia est? siendo validada");
360 362

  
361

  
362 363
		Rectangle2D ruleScope = null;
363 364
		try {
364 365
			if (rule instanceof IOneLyrRule) {
......
391 392
		rule.setTopology(this);
392 393
		rules.add(rule);
393 394

  
394
//   Si se a?ade una nueva regla, no es posible conservar los errores
395
//   y las zonas sucias previas
396
//		if(status == EMPTY)
397
//			status = NOT_VALIDATED;
398
//		else if(status == VALIDATED ){
399
//			status = VALIDATED_WITH_DIRTY_ZONES;
400
//			addDirtyZone(ruleScope);
401
//		}else if(status == VALIDATED_WITH_ERRORS){
402
//			//we dont change the status, but add a new dirty zone
403
//			addDirtyZone(ruleScope);
404
//		}
395
		// Si se a?ade una nueva regla, no es posible conservar los errores
396
		// y las zonas sucias previas
397
		// if(status == EMPTY)
398
		// status = NOT_VALIDATED;
399
		// else if(status == VALIDATED ){
400
		// status = VALIDATED_WITH_DIRTY_ZONES;
401
		// addDirtyZone(ruleScope);
402
		// }else if(status == VALIDATED_WITH_ERRORS){
403
		// //we dont change the status, but add a new dirty zone
404
		// addDirtyZone(ruleScope);
405
		// }
405 406
		resetStatus();
406 407
		rule.setTopologyErrorContainer(this);
407 408
		rule.setId(this.ruleId++);
408 409
	}
409 410

  
410

  
411

  
412

  
413 411
	/*
414 412
	 * Overwrited implementations of FLayers methods
415 413
	 */
......
418 416
		addLayer(layers.size(), layer);
419 417
	}
420 418

  
421
	public void addLayer(int pos, FLayer layer)  {
419
	public void addLayer(int pos, FLayer layer) {
422 420
		if (!(layer instanceof FLyrVect))
423 421
			throw new WrongLyrForTopologyException(
424 422
					"Intentando a?adir capa no vectorial a una topologia");
......
427 425

  
428 426
		int shapeType = -1;
429 427
		try {
430
			shapeType = ((FLyrVect)layer).getShapeType();
431
			if( (shapeType == FShape.POINT) || (shapeType == FShape.MULTIPOINT) || (shapeType == FShape.TEXT))
428
			shapeType = ((FLyrVect) layer).getShapeType();
429
			if ((shapeType == FShape.POINT) || (shapeType == FShape.MULTIPOINT)
430
					|| (shapeType == FShape.TEXT))
432 431
				return;
433 432
		} catch (ReadDriverException e) {
434 433
			e.printStackTrace();
435
			throw new WrongLyrForTopologyException("Error al intentar verificar el tipo de geometria de la capa", e);
434
			throw new WrongLyrForTopologyException(
435
					"Error al intentar verificar el tipo de geometria de la capa",
436
					e);
436 437
		}
437 438

  
438

  
439
		MustBeLargerThanClusterTolerance rule = new
440
			MustBeLargerThanClusterTolerance(this, (FLyrVect) layer, clusterTolerance);
439
		MustBeLargerThanClusterTolerance rule = new MustBeLargerThanClusterTolerance(
440
				this, (FLyrVect) layer, clusterTolerance);
441 441
		rule.setId(this.ruleId++);
442 442
		Rectangle2D ruleScope;
443 443
		try {
444 444
			ruleScope = layer.getFullExtent();
445
//		 before to add the rule we check if it verifies preconditions
445
			// before to add the rule we check if it verifies preconditions
446 446
			rule.checkPreconditions();
447 447

  
448
			if(status == EMPTY)
448
			if (status == EMPTY)
449 449
				setStatus(NOT_VALIDATED);
450
			else if(status == VALIDATED ){
450
			else if (status == VALIDATED) {
451 451
				setStatus(VALIDATED_WITH_DIRTY_ZONES);
452 452
				addDirtyZone(ruleScope);
453
			}else if(status == VALIDATED_WITH_ERRORS){
454
				//we dont change the status, but add a new dirty zone
455
//				addDirtyZone(ruleScope);
456
				//si habia errores, la reevaluacion haria que se repitiesen
453
			} else if (status == VALIDATED_WITH_ERRORS) {
454
				// we dont change the status, but add a new dirty zone
455
				// addDirtyZone(ruleScope);
456
				// si habia errores, la reevaluacion haria que se repitiesen
457 457
				resetStatus();
458 458
			}
459 459
			rule.setTopologyErrorContainer(this);
460 460
			clusterToleranceRules.add(rule);
461 461

  
462
			//finally, we connect edition with topology
463
			layer.addLayerListener(new LayerListener(){
462
			// finally, we connect edition with topology
463
			layer.addLayerListener(new LayerListener() {
464 464

  
465 465
				public void activationChanged(LayerEvent e) {
466 466
				}
......
468 468
				public void editionChanged(LayerEvent e) {
469 469
					FLayer editionLyr = e.getSource();
470 470

  
471
					if (editionLyr instanceof FLyrVect){
471
					if (editionLyr instanceof FLyrVect) {
472 472

  
473 473
						final ArrayList<Rectangle2D> dirtyZones = new ArrayList<Rectangle2D>();
474 474

  
475
						FLyrVect fLyrVect = (FLyrVect)editionLyr;
475
						FLyrVect fLyrVect = (FLyrVect) editionLyr;
476 476

  
477 477
						ReadableVectorial rv = fLyrVect.getSource();
478
						if(! (rv instanceof VectorialEditableAdapter))
478
						if (!(rv instanceof VectorialEditableAdapter))
479 479
							return;
480
						final VectorialEditableAdapter vea =
481
							(VectorialEditableAdapter)rv;
480
						final VectorialEditableAdapter vea = (VectorialEditableAdapter) rv;
482 481

  
483
						vea.addEditionListener(new IEditionListener(){
482
						vea.addEditionListener(new IEditionListener() {
484 483

  
485 484
							public void afterFieldEditEvent(
486 485
									AfterFieldEditEvent e) {
......
488 487

  
489 488
							public void afterRowEditEvent(IRow row,
490 489
									AfterRowEditEvent e) {
491
								//If we include alphanumeric rules to a topology as a
492
								//integrity rule, we'll add a new dirty zone for this too
493
								if(e.getChangeType() == EditionEvent.ALPHANUMERIC)
490
								// If we include alphanumeric rules to a
491
								// topology as a
492
								// integrity rule, we'll add a new dirty zone
493
								// for this too
494
								if (e.getChangeType() == EditionEvent.ALPHANUMERIC)
494 495
									return;
495 496
								int numRow = (int) e.getNumRow();
496 497

  
......
514 515
							}
515 516

  
516 517
							public void processEvent(EditionEvent e) {
517
								if(e.getChangeType() == EditionEvent.STOP_EDITION){
518
									for(int i = 0; i < dirtyZones.size(); i++){
519
										Rectangle2D dirtyZone = dirtyZones.get(i);
518
								if (e.getChangeType() == EditionEvent.STOP_EDITION) {
519
									for (int i = 0; i < dirtyZones.size(); i++) {
520
										Rectangle2D dirtyZone = dirtyZones
521
												.get(i);
520 522
										Topology.this.addDirtyZone(dirtyZone);
521
									}//for
522
								}//if
523
							}});
523
									}// for
524
								}// if
525
							}
526
						});
524 527
					}
525 528
				}
526 529

  
......
528 531
				}
529 532

  
530 533
				public void visibilityChanged(LayerEvent e) {
531
				}});
534
				}
535
			});
532 536

  
533

  
534 537
		} catch (ExpansionFileReadException e) {
535 538
			e.printStackTrace();
536
			throw new WrongLyrForTopologyException("No es posible acceder all FullExtent de la capa", e);
539
			throw new WrongLyrForTopologyException(
540
					"No es posible acceder all FullExtent de la capa", e);
537 541
		} catch (ReadDriverException e) {
538 542
			e.printStackTrace();
539
			throw new WrongLyrForTopologyException("No es posible acceder all FullExtent de la capa", e);
543
			throw new WrongLyrForTopologyException(
544
					"No es posible acceder all FullExtent de la capa", e);
540 545
		} catch (TopologyRuleDefinitionException e) {
541 546
			e.printStackTrace();
542
			throw new WrongLyrForTopologyException("Regla topologica mal definida", e);
547
			throw new WrongLyrForTopologyException(
548
					"Regla topologica mal definida", e);
543 549
		}
544 550
	}
545 551

  
546 552
	/**
547 553
	 * Sets the rank/importance of a layer in xy and z planes.
548
	 *
549
	 * @param lyr layer
550
	 *
551
	 * @param xyRank importance of this layer coordinates in xy plane
552
	 *
553
	 * @param zRank importante of this layer coordinates in z plane
554
	 * 
555
	 * @param lyr
556
	 *            layer
557
	 * 
558
	 * @param xyRank
559
	 *            importance of this layer coordinates in xy plane
560
	 * 
561
	 * @param zRank
562
	 *            importante of this layer coordinates in z plane
554 563
	 */
555 564
	public void setRank(FLyrVect lyr, int xyRank, int zRank) {
556 565
		XYZLayerRank rank = new XYZLayerRank(lyr.getName(), xyRank, zRank);
557 566
		layerRanks.put(lyr, rank);
558 567
	}
559 568

  
560

  
561
	public XYZLayerRank getRank(FLyrVect lyr){
569
	public XYZLayerRank getRank(FLyrVect lyr) {
562 570
		return layerRanks.get(lyr);
563 571
	}
564 572

  
......
572 580
		setRank(layer, xyRank, zRank);
573 581
	}
574 582

  
575

  
576 583
	/**
577 584
	 * Remove a layer from a topology.
578
	 *
585
	 * 
579 586
	 * This task is more complex than removing a layer from a LayerCollection:
580
	 * -must remove all rules which references to this layer.
581
	 * -must recompute status and dirty zones.
582
	 * etc.
583
	 *
587
	 * -must remove all rules which references to this layer. -must recompute
588
	 * status and dirty zones. etc.
589
	 * 
584 590
	 * TODO Implement remove layer as a geoprocess.
585
	 *
591
	 * 
586 592
	 */
587 593
	public void removeLayer(FLayer lyr) throws CancelationException {
588 594
		callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr));
589 595

  
590
		//remove cluster rules related with the layer
591
		Iterator<MustBeLargerThanClusterTolerance> clusterRulesIt = clusterToleranceRules.iterator();
592
		while(clusterRulesIt.hasNext()){
596
		// remove cluster rules related with the layer
597
		Iterator<MustBeLargerThanClusterTolerance> clusterRulesIt = clusterToleranceRules
598
				.iterator();
599
		while (clusterRulesIt.hasNext()) {
593 600
			MustBeLargerThanClusterTolerance rule = clusterRulesIt.next();
594
			if(rule.getOriginLyr().equals(lyr)){
601
			if (rule.getOriginLyr().equals(lyr)) {
595 602
				clusterRulesIt.remove();
596 603
			}
597
		}//while
604
		}// while
598 605

  
599
		//Remove normal rules related with the layer
606
		// Remove normal rules related with the layer
600 607
		Iterator<ITopologyRule> rulesIt = this.rules.iterator();
601
		while(rulesIt.hasNext()){
602
			ITopologyRule rule =  rulesIt.next();
603
			if(rule instanceof IOneLyrRule){
608
		while (rulesIt.hasNext()) {
609
			ITopologyRule rule = rulesIt.next();
610
			if (rule instanceof IOneLyrRule) {
604 611
				IOneLyrRule oneLyrRule = (IOneLyrRule) rule;
605
				if(oneLyrRule.getOriginLyr().equals(lyr)){
612
				if (oneLyrRule.getOriginLyr().equals(lyr)) {
606 613
					rulesIt.remove();
607 614
					continue;
608 615
				}
609 616
			}
610 617

  
611
			if(rule instanceof ITwoLyrRule){
618
			if (rule instanceof ITwoLyrRule) {
612 619
				ITwoLyrRule twoLyrRule = (ITwoLyrRule) rule;
613
				if(twoLyrRule.getOriginLyr().equals(lyr)){
620
				if (twoLyrRule.getOriginLyr().equals(lyr)) {
614 621
					rulesIt.remove();
615 622
				}
616 623
			}
617
		}//while
624
		}// while
618 625

  
619 626
		this.errorContainer.removeErrorsByLayer((FLyrVect) lyr);
620 627
		this.layerRanks.remove(lyr);
......
622 629
		callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr));
623 630
	}
624 631

  
625
	public void removeLayer(int idLyr){
632
	public void removeLayer(int idLyr) {
626 633
		FLayer lyr = (FLayer) layers.get(idLyr);
627 634
		removeLayer(lyr);
628 635
	}
629 636

  
630
	public void removeRule(ITopologyRule rule){
631
		if(rules.contains(rule)){
637
	public void removeRule(ITopologyRule rule) {
638
		if (rules.contains(rule)) {
632 639
			rules.remove(rule);
633
		}else if(clusterToleranceRules.contains(rule)){
640
		} else if (clusterToleranceRules.contains(rule)) {
634 641
			clusterToleranceRules.remove(rule);
635 642
		}
636 643
		this.errorContainer.removeErrorsByRule(rule.getName());
......
638 645
		this.updateDirtyZones();
639 646
	}
640 647

  
641

  
642

  
643 648
	private void updateDirtyZones() {
644
//		this.dirtyZones.clear(); //FIXME REVISAR SI ES NECESARIO BORRAR LAS ZONAS SUCIAS
649
		// this.dirtyZones.clear(); //FIXME REVISAR SI ES NECESARIO BORRAR LAS
650
		// ZONAS SUCIAS
645 651
		int errorNum = errorContainer.getNumberOfErrors();
646
		for(int i = 0; i < errorNum; i++){
652
		for (int i = 0; i < errorNum; i++) {
647 653
			TopologyError topologyError = errorContainer.getTopologyError(i);
648 654
			Rectangle2D rect = topologyError.getGeometry().getBounds2D();
649 655
			addDirtyZone(rect);
......
652 658

  
653 659
	/**
654 660
	 * Ranks (in xy plane and z plane) for layers of the topology.
655
	 *
661
	 * 
656 662
	 * The rank of layer marks its weight for computing weihgted average
657 663
	 * coordinates.
658
	 *
664
	 * 
659 665
	 * @author azabala
660
	 *
666
	 * 
661 667
	 */
662 668
	class XYZLayerRank implements IPersistence {
663 669
		int xyRank;
......
670 676
			this.zRank = zRank;
671 677
		}
672 678

  
673
		XYZLayerRank(){}
679
		XYZLayerRank() {
680
		}
674 681

  
675 682
		public String getClassName() {
676 683
			return this.getClass().getName();
......
685 692
		}
686 693

  
687 694
		public void setXMLEntity(XMLEntity xml) {
688
			if(xml.contains("layerName"))
695
			if (xml.contains("layerName"))
689 696
				layerName = xml.getStringProperty("layerName");
690 697

  
691
			if(xml.contains("xyRank"))
698
			if (xml.contains("xyRank"))
692 699
				xyRank = xml.getIntProperty("xyRank");
693 700

  
694
			if(xml.contains("zRank"))
701
			if (xml.contains("zRank"))
695 702
				zRank = xml.getIntProperty("zRank");
696 703

  
697 704
		}
......
710 717
		return status;
711 718
	}
712 719

  
713
	public List<ITopologyRule> getAllRules(){
720
	public List<ITopologyRule> getAllRules() {
714 721
		List<ITopologyRule> solution = new ArrayList<ITopologyRule>();
715 722
		solution.addAll(this.rules);
716 723
		solution.addAll(this.clusterToleranceRules);
......
722 729
	 * the topology has been edited)
723 730
	 */
724 731
	public void addDirtyZone(Rectangle2D newDirtyZone) {
725
		if(status == NOT_VALIDATED)
732
		if (status == NOT_VALIDATED)
726 733
			return;
727 734
		Iterator<Rectangle2D> zonesIt = dirtyZones.iterator();
728 735
		while (zonesIt.hasNext()) {
......
742 749
			}
743 750
		}// while
744 751

  
745
		if(status == VALIDATED)
752
		if (status == VALIDATED)
746 753
			setStatus(VALIDATED_WITH_DIRTY_ZONES);
747 754

  
748 755
		// at this point, we add the new dirty zone
749 756
		dirtyZones.add(newDirtyZone);
750 757
	}
751 758

  
752

  
753 759
	public void removeDirtyZone(Rectangle2D newDirtyZone) {
754
		if(status == NOT_VALIDATED)
755
			return;//maybe we must launch an inconsistent status exception
760
		if (status == NOT_VALIDATED)
761
			return;// maybe we must launch an inconsistent status exception
756 762
		Iterator<Rectangle2D> zonesIt = dirtyZones.iterator();
757 763
		while (zonesIt.hasNext()) {
758 764
			Rectangle2D dirtyZone = zonesIt.next();
......
766 772
		dirtyZones.remove(newDirtyZone);
767 773
	}
768 774

  
769

  
770 775
	public Rectangle2D getDirtyZone(int i) {
771 776
		return dirtyZones.get(i);
772 777
	}
773 778

  
774
	public int getNumberOfDirtyZones(){
779
	public int getNumberOfDirtyZones() {
775 780
		return dirtyZones.size();
776 781
	}
777 782

  
778

  
779
	public void validate(){
783
	public void validate() {
780 784
		validate(null);
781 785
	}
782 786

  
......
786 790
	 */
787 791
	public void validate(CancellableProgressTask progressMonitor) {
788 792

  
789
		if(progressMonitor != null){
793
		if (progressMonitor != null) {
790 794
			progressMonitor.setInitialStep(0);
791 795
			int numOfSteps = rules.size() + clusterToleranceRules.size();
792 796
			progressMonitor.setFinalStep(numOfSteps);
793 797
			progressMonitor.setDeterminatedProcess(true);
794 798
			progressMonitor.setNote(Messages.getText("Validating_a_topology"));
795
			progressMonitor.setStatusMessage(Messages.getText(rules.get(0).getName()));
799
			progressMonitor.setStatusMessage(Messages.getText(rules.get(0)
800
					.getName()));
796 801
		}
797 802

  
798

  
799 803
		if (this.status == EMPTY) {
800
			//TODO Maybe we must do progressMonitor.setFinished(true)
801
			//or throw an exception
804
			// TODO Maybe we must do progressMonitor.setFinished(true)
805
			// or throw an exception
802 806
			return;
803 807
		} else if (this.status == VALIDATED) {
804 808
			return;
805 809
		}
806 810

  
807
		else if (this.status == NOT_VALIDATED){
811
		else if (this.status == NOT_VALIDATED) {
808 812
			setStatus(VALIDATING);
809 813

  
810

  
811
			//we make a local copy of dirty zones to avoid to use dirty zones created in
812
			//the current validation.
814
			// we make a local copy of dirty zones to avoid to use dirty zones
815
			// created in
816
			// the current validation.
813 817
			ArrayList<Rectangle2D> dirtyZonesCopy = new ArrayList<Rectangle2D>();
814 818
			Collections.copy(dirtyZonesCopy, this.dirtyZones);
815
			Iterator<MustBeLargerThanClusterTolerance> it =
816
				clusterToleranceRules.iterator();
817
			while(it.hasNext()){
819
			Iterator<MustBeLargerThanClusterTolerance> it = clusterToleranceRules
820
					.iterator();
821
			while (it.hasNext()) {
818 822
				MustBeLargerThanClusterTolerance rule = it.next();
819
				if(progressMonitor != null){
820
					if(progressMonitor.isCanceled()/*|| progressMonitor.isFinished()*/){
823
				if (progressMonitor != null) {
824
					if (progressMonitor.isCanceled()/*
825
													 * ||
826
													 * progressMonitor.isFinished()
827
													 */) {
821 828
						resetStatus();
822 829
						return;
823 830
					}
824
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")+" "+
825
   						Messages.getText(rule.getName()));
831
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")
832
							+ " " + Messages.getText(rule.getName()));
826 833
					progressMonitor.reportStep();
827
   				}
834
				}
828 835

  
829
				if(getNumberOfErrors() >= this.maxNumberOfErrors){
830
					if(progressMonitor != null)
836
				if (getNumberOfErrors() >= this.maxNumberOfErrors) {
837
					if (progressMonitor != null)
831 838
						progressMonitor.setCanceled(true);
832 839
					return;
833 840
				}
......
839 846
			while (rulesIt.hasNext()) {
840 847
				ITopologyRule rule = rulesIt.next();
841 848

  
842
				if(progressMonitor != null){
843
					if(progressMonitor.isCanceled()/*|| progressMonitor.isFinished()*/){
849
				if (progressMonitor != null) {
850
					if (progressMonitor.isCanceled()/*
851
													 * ||
852
													 * progressMonitor.isFinished()
853
													 */) {
844 854
						resetStatus();
845 855
						return;
846 856
					}
847
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")+" "+
848
   						Messages.getText(rule.getName()));
857
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")
858
							+ " " + Messages.getText(rule.getName()));
849 859
					progressMonitor.reportStep();
850
   				}
860
				}
851 861

  
852
				if(getNumberOfErrors() >= this.maxNumberOfErrors){
853
					if(progressMonitor != null)
862
				if (getNumberOfErrors() >= this.maxNumberOfErrors) {
863
					if (progressMonitor != null)
854 864
						progressMonitor.setCanceled(true);
855 865
					return;
856 866
				}
857 867

  
858
				if(dirtyZonesCopy.size() == 0){
868
				if (dirtyZonesCopy.size() == 0) {
859 869
					rule.checkRule(progressMonitor);
860
				}else{
861
					//A topology is NON_VALIDATED with dirty zones when
862
					//it has VALIDATED status and we add a new rule.
870
				} else {
871
					// A topology is NON_VALIDATED with dirty zones when
872
					// it has VALIDATED status and we add a new rule.
863 873

  
864
					//TODO Check to add a new rule to a topology
865
					//with VALIDATED_WITH_ERROR status
866
					Iterator<Rectangle2D> dirtyZonesIt = dirtyZonesCopy.iterator();
867
					while(dirtyZonesIt.hasNext()){
874
					// TODO Check to add a new rule to a topology
875
					// with VALIDATED_WITH_ERROR status
876
					Iterator<Rectangle2D> dirtyZonesIt = dirtyZonesCopy
877
							.iterator();
878
					while (dirtyZonesIt.hasNext()) {
868 879
						Rectangle2D rect = dirtyZonesIt.next();
869
						rule.checkRule(progressMonitor,rect);
870
					}//while
871
				}//else
872
			}//while
873
			if(this.errorContainer.getNumberOfErrors() > 0){
880
						rule.checkRule(progressMonitor, rect);
881
					}// while
882
				}// else
883
			}// while
884
			if (this.errorContainer.getNumberOfErrors() > 0) {
874 885
				setStatus(VALIDATED_WITH_ERRORS);
875 886
				addErrorLyr();
876
			}else
887
			} else
877 888
				setStatus(VALIDATED);
878
		}
879
		else if (this.status == VALIDATED_WITH_ERRORS ||
880
				this.status == ITopologyStatus.VALIDATED_WITH_DIRTY_ZONES) {
889
		} else if (this.status == VALIDATED_WITH_ERRORS
890
				|| this.status == ITopologyStatus.VALIDATED_WITH_DIRTY_ZONES) {
881 891
			setStatus(VALIDATING);
882 892
			// this topology must have at least one dirty zone
883
			if (this.dirtyZones.size() < 1){
884
//				 FIXME Deberiamos lanzar una
893
			if (this.dirtyZones.size() < 1) {
894
				// FIXME Deberiamos lanzar una
885 895
				// InconsistentStatusException ??
886 896
				return;
887 897
			}
888 898

  
889
			Iterator<Rectangle2D> dirtyZonesIt = this.dirtyZones.iterator();
890
			while (dirtyZonesIt.hasNext()) {
891
				Rectangle2D dirtyZone = dirtyZonesIt.next();
899
			this.errorContainer.clear();
892 900

  
893
				Iterator<MustBeLargerThanClusterTolerance> it = this.clusterToleranceRules.iterator();
894
				while(it.hasNext()){
895
					MustBeLargerThanClusterTolerance rule = it.next();
896
					if(progressMonitor != null){
897
						if(progressMonitor.isCanceled()/*|| progressMonitor.isFinished()*/){
898
							resetStatus();
899
							return;
900
						}
901
						progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")+" "+
902
	   						Messages.getText(rule.getName()));
903
						progressMonitor.reportStep();
904
	   				}
905

  
906
					if(getNumberOfErrors() >= this.maxNumberOfErrors){
907
						if(progressMonitor != null)
908
							progressMonitor.setCanceled(true);
901
			Iterator<MustBeLargerThanClusterTolerance> it = this.clusterToleranceRules
902
					.iterator();
903
			while (it.hasNext()) {
904
				MustBeLargerThanClusterTolerance rule = it.next();
905
				if (progressMonitor != null) {
906
					if (progressMonitor.isCanceled()/*
907
													 * ||
908
													 * progressMonitor.isFinished()
909
													 */) {
910
						//TODO Si se cancela la validacion de una topologia con 
911
						//estado VALIDADO CON ERRORES, NO SE DEBE LLAMAR A RESETSTATUS!!!
912
						//LO QUE HAY QUE HACER ES RESTAURAR EL ESTADO PREVIO
913
						resetStatus();
909 914
						return;
910 915
					}
916
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")
917
							+ " " + Messages.getText(rule.getName()));
918
					progressMonitor.reportStep();
919
				}
911 920

  
921
				if (getNumberOfErrors() >= this.maxNumberOfErrors) {
922
					if (progressMonitor != null)
923
						progressMonitor.setCanceled(true);
924
					return;
925
				}
926

  
927
				List<Rectangle2D> dirtyZonesCopy = new ArrayList<Rectangle2D>(
928
						dirtyZones);
929
				Iterator<Rectangle2D> dirtyZonesIt = dirtyZonesCopy.iterator();
930
				while (dirtyZonesIt.hasNext()) {
931
					Rectangle2D dirtyZone = dirtyZonesIt.next();
912 932
					rule.checkRule(dirtyZone);
913 933
				}
934
			}// MustBeGreaterThanClusterTolerance
914 935

  
915
				Iterator<ITopologyRule> rulesIt = this.rules.iterator();
916
				while (rulesIt.hasNext()) {
917
					ITopologyRule rule = rulesIt.next();
918
					if(progressMonitor != null){
919
						if(progressMonitor.isCanceled()/*|| progressMonitor.isFinished()*/){
920
							resetStatus();
921
							return;
922
						}
923
						progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")+" "+
924
	   						Messages.getText(rule.getName()));
925
						progressMonitor.reportStep();
926
	   				}
927

  
928
					if(getNumberOfErrors() >= this.maxNumberOfErrors){
929
						if(progressMonitor != null)
930
							progressMonitor.setCanceled(true);
936
			Iterator<ITopologyRule> rulesIt = this.rules.iterator();
937
			while (rulesIt.hasNext()) {
938
				ITopologyRule rule = rulesIt.next();
939
				if (progressMonitor != null) {
940
					if (progressMonitor.isCanceled()/*
941
													 * ||
942
													 * progressMonitor.isFinished()
943
													 */) {
944
						resetStatus();
931 945
						return;
932 946
					}
947
					progressMonitor.setNote(Messages.getText("VALIDANDO_REGLA")
948
							+ " " + Messages.getText(rule.getName()));
949
					progressMonitor.reportStep();
950
				}
951

  
952
				if (getNumberOfErrors() >= this.maxNumberOfErrors) {
953
					if (progressMonitor != null)
954
						progressMonitor.setCanceled(true);
955
					return;
956
				}
957
				List<Rectangle2D> dirtyZonesCopy = new ArrayList<Rectangle2D>(
958
						dirtyZones);
959
				Iterator<Rectangle2D> dirtyZonesIt = dirtyZonesCopy.iterator();
960
				while (dirtyZonesIt.hasNext()) {
961
					Rectangle2D dirtyZone = dirtyZonesIt.next();
933 962
					rule.checkRule(dirtyZone);
934
				}//while
935

  
936

  
937
			}//while
938
			if(this.errorContainer.getNumberOfErrors() > 0){
963
				}
964
			}// while
965
			if (this.errorContainer.getNumberOfErrors() > 0) {
939 966
				setStatus(VALIDATED_WITH_ERRORS);
940 967
				addErrorLyr();
941
			}else
968
			} else
942 969
				setStatus(VALIDATED);
943
		}//if
970
		}// if
944 971
	}
945 972

  
946 973
	private void addErrorLyr() {
947 974
		IProjection proj = this.getProjection();
948 975
		int idx = 0;
949
		while(proj == null && idx < this.getLayerCount()){
976
		while (proj == null && idx < this.getLayerCount()) {
950 977
			proj = this.getLayer(idx).getProjection();
951 978
			idx++;
952 979
		}
953
		errorLayer = this.errorContainer.getAsFMapLayer(this.name+"_error", 														proj);
980
		errorLayer = this.errorContainer.getAsFMapLayer(this.name + "_error",
981
				proj);
954 982
	}
955 983

  
956 984
	public int getLayerCount() {
957 985
		return super.getLayersCount();
958 986
	}
959 987

  
960
	public List getLayers(){
988
	public List getLayers() {
961 989
		return this.layers;
962 990
	}
963 991

  
......
973 1001
		return rules.get(ruleIndex);
974 1002
	}
975 1003

  
976
	public ITopologyRule getRuleById(int ruleId){
977
		for(int i = 0; i < rules.size(); i++){
1004
	public ITopologyRule getRuleById(int ruleId) {
1005
		for (int i = 0; i < rules.size(); i++) {
978 1006
			ITopologyRule rule = rules.get(i);
979
			if(rule.getId() == ruleId){
1007
			if (rule.getId() == ruleId) {
980 1008
				return rule;
981
			}//if
982
		}//for
1009
			}// if
1010
		}// for
983 1011

  
984
		for(int i = 0; i < clusterToleranceRules.size(); i++){
985
			MustBeLargerThanClusterTolerance rule = clusterToleranceRules.get(i);
986
			if(rule.getId() == ruleId){
1012
		for (int i = 0; i < clusterToleranceRules.size(); i++) {
1013
			MustBeLargerThanClusterTolerance rule = clusterToleranceRules
1014
					.get(i);
1015
			if (rule.getId() == ruleId) {
987 1016
				return rule;
988
			}//if
1017
			}// if
989 1018
		}
990 1019
		return null;
991 1020
	}
......
993 1022
	/**
994 1023
	 * Looks for all rules which has at least one reference to the given layer
995 1024
	 * (as origin or destination layer in the rule)
996
	 *
1025
	 * 
997 1026
	 * @param lyr
998 1027
	 * @return
999 1028
	 */
1000
	public List<ITopologyRule> getRulesByLyr(FLyrVect lyr){
1029
	public List<ITopologyRule> getRulesByLyr(FLyrVect lyr) {
1001 1030
		List<ITopologyRule> solution = new ArrayList<ITopologyRule>();
1002 1031
		Iterator<ITopologyRule> ruleIt = this.rules.iterator();
1003
		while(ruleIt.hasNext()){
1032
		while (ruleIt.hasNext()) {
1004 1033
			ITopologyRule rule = ruleIt.next();
1005
			if(rule instanceof IOneLyrRule){
1034
			if (rule instanceof IOneLyrRule) {
1006 1035
				IOneLyrRule oneLyrRule = (IOneLyrRule) rule;
1007 1036
				FLyrVect originLyr = oneLyrRule.getOriginLyr();
1008
				if(originLyr.equals(lyr))
1009
				{
1037
				if (originLyr.equals(lyr)) {
1010 1038
					solution.add(rule);
1011
					continue;//dont need to check for destination layer
1039
					continue;// dont need to check for destination layer
1012 1040
				}
1013
			}//if
1041
			}// if
1014 1042

  
1015
			if(rule instanceof ITwoLyrRule){
1043
			if (rule instanceof ITwoLyrRule) {
1016 1044
				ITwoLyrRule twoLyrRule = (ITwoLyrRule) rule;
1017 1045
				FLyrVect destinationLyr = twoLyrRule.getDestinationLyr();
1018
				if(destinationLyr.equals(lyr)){
1046
				if (destinationLyr.equals(lyr)) {
1019 1047
					solution.add(rule);
1020 1048
				}
1021 1049
			}
1022 1050

  
1023
		}//while
1051
		}// while
1024 1052

  
1025
		Iterator<MustBeLargerThanClusterTolerance> clusterIt = clusterToleranceRules.iterator();
1026
		while(clusterIt.hasNext()){
1053
		Iterator<MustBeLargerThanClusterTolerance> clusterIt = clusterToleranceRules
1054
				.iterator();
1055
		while (clusterIt.hasNext()) {
1027 1056
			MustBeLargerThanClusterTolerance rule = clusterIt.next();
1028 1057
			FLyrVect originLyr = rule.getOriginLyr();
1029
			if(originLyr.equals(lyr))
1030
			{
1058
			if (originLyr.equals(lyr)) {
1031 1059
				solution.add(rule);
1032
				continue;//dont need to check for destination layer
1060
				continue;// dont need to check for destination layer
1033 1061
			}
1034 1062
		}
1035 1063
		return solution;
......
1052 1080

  
1053 1081
	/**
1054 1082
	 * Modify the dirty zone of the specified index
1055
	 *
1083
	 * 
1056 1084
	 * TODO Make thread safe ?
1057 1085
	 */
1058 1086
	public void updateDirtyZone(int dirtyZoneIndex, Rectangle2D dirtyZone) {
......
1079 1107
	}
1080 1108

  
1081 1109
	/**
1082
	 * marks topologyErrors as an exception (and removes its bounds of the
1083
	 * dirty zones list)
1084
	 * @param topologyError error to mark as exceptions
1110
	 * marks topologyErrors as an exception (and removes its bounds of the dirty
1111
	 * zones list)
1112
	 * 
1113
	 * @param topologyError
1114
	 *            error to mark as exceptions
1085 1115
	 */
1086 1116
	public void markAsTopologyException(TopologyError topologyError) {
1087 1117
		errorContainer.markAsTopologyException(topologyError);
1088 1118
		Rectangle2D rect = topologyError.getGeometry().getBounds2D();
1089 1119
		removeDirtyZone(rect);
1090 1120

  
1091
		if(status == VALIDATED_WITH_DIRTY_ZONES){
1092
			if(dirtyZones.size() == 0)
1121
		if (status == VALIDATED_WITH_DIRTY_ZONES) {
1122
			if (dirtyZones.size() == 0)
1093 1123
				setStatus(VALIDATED);
1094
		}else if(status == VALIDATED_WITH_ERRORS){
1095
			if(getNumberOfErrors() == getNumberOfExceptions())
1124
		} else if (status == VALIDATED_WITH_ERRORS) {
1125
			if (getNumberOfErrors() == getNumberOfExceptions())
1096 1126
				setStatus(VALIDATED);
1097 1127
		}
1098 1128
	}
......
1101 1131
		errorContainer.demoteToError(topologyError);
1102 1132
		Rectangle2D rect = topologyError.getGeometry().getBounds2D();
1103 1133
		addDirtyZone(rect);
1104
		if(getNumberOfErrors() > getNumberOfExceptions() )
1134
		if (getNumberOfErrors() > getNumberOfExceptions())
1105 1135
			setStatus(VALIDATED_WITH_ERRORS);
1106 1136
	}
1107 1137

  
1108

  
1109

  
1110 1138
	public List<TopologyError> getTopologyErrorsByLyr(FLyrVect layer,
1111
													IProjection desiredProjection,
1112
													boolean includeExceptions) {
1139
			IProjection desiredProjection, boolean includeExceptions) {
1113 1140

  
1114
		return errorContainer.getTopologyErrorsByLyr(layer,
1115
										 desiredProjection,
1116
										 includeExceptions);
1141
		return errorContainer.getTopologyErrorsByLyr(layer, desiredProjection,
1142
				includeExceptions);
1117 1143
	}
1118 1144

  
1119 1145
	public List<TopologyError> getTopologyErrorsByRule(String ruleName,
1120 1146
			IProjection desiredProjection, boolean includeExceptions) {
1121 1147

  
1122 1148
		return errorContainer.getTopologyErrorsByRule(ruleName,
1123
												desiredProjection,
1124
												includeExceptions);
1149
				desiredProjection, includeExceptions);
1125 1150
	}
1126 1151

  
1127

  
1128 1152
	public List<TopologyError> getTopologyErrorsByShapeType(int shapeType,
1129 1153
			IProjection desiredProjection, boolean includeExceptions) {
1130 1154
		return errorContainer.getTopologyErrorsByShapeType(shapeType,
1131
													desiredProjection,
1132
													includeExceptions);
1155
				desiredProjection, includeExceptions);
1133 1156
	}
1134 1157

  
1135

  
1136 1158
	/**
1137 1159
	 * Get TopologyError filtered byte shapeType, sourte layer of the rule which
1138 1160
	 * was violtated by this error.
......
1141 1163
			int shapeType, FLyrVect sourceLayer, IProjection desiredProjection,
1142 1164
			boolean includeExceptions) {
1143 1165

  
1144
		return errorContainer.getTopologyErrors(ruleName,
1145
												shapeType,
1146
												sourceLayer,
1147
												desiredProjection,
1148
												includeExceptions);
1166
		return errorContainer.getTopologyErrors(ruleName, shapeType,
1167
				sourceLayer, desiredProjection, includeExceptions);
1149 1168
	}
1150 1169

  
1151 1170
	/**
1152 1171
	 * Return an unique identifier for the error saved in this
1153 1172
	 * TopologyErrorContainer.
1154
	 *
1155
	 * Until a new error would be added to this error container, it will
1156
	 * return always the same error fid.
1173
	 * 
1174
	 * Until a new error would be added to this error container, it will return
1175
	 * always the same error fid.
1157 1176
	 */
1158 1177
	public synchronized String getErrorFid() {
1159 1178
		return errorContainer.getErrorFid();
......
1171 1190
		errorContainer.clear();
1172 1191
	}
1173 1192

  
1174
	public XMLEntity getXMLEntity() throws XMLException{
1193
	public XMLEntity getXMLEntity() throws XMLException {
1175 1194

  
1176
		//Topology is a subclass of FLayers, so the call to super
1177
		//allows to persist layer status, toc information and layers
1195
		// Topology is a subclass of FLayers, so the call to super
1196
		// allows to persist layer status, toc information and layers
1178 1197
		XMLEntity xml = super.getXMLEntity();
1179 1198

  
1180
		//Si no ponemos esto className ser? FLayerDefault, no??
1199
		// Si no ponemos esto className ser? FLayerDefault, no??
1181 1200
		xml.putProperty("className", this.getClass().getName());
1182 1201
		xml.putProperty("name", name);
1183 1202
		xml.putProperty("clusterTolerance", clusterTolerance);
......
1186 1205

  
1187 1206
		int numberOfTopologyRules = rules.size();
1188 1207
		xml.putProperty("numberOfTopologyRules", numberOfTopologyRules);
1189
		for(int i = 0; i < numberOfTopologyRules; i++){
1208
		for (int i = 0; i < numberOfTopologyRules; i++) {
1190 1209
			ITopologyRule rule = rules.get(i);
1191 1210
			xml.addChild(rule.getXMLEntity());
1192 1211
		}
1193 1212

  
1194

  
1195 1213
		int numberOfClusterRules = clusterToleranceRules.size();
1196 1214
		xml.putProperty("numberOfClusterRules", numberOfClusterRules);
1197
		for(int i = 0; i < numberOfClusterRules; i++){
1198
			MustBeLargerThanClusterTolerance rule = clusterToleranceRules.get(i);
1215
		for (int i = 0; i < numberOfClusterRules; i++) {
1216
			MustBeLargerThanClusterTolerance rule = clusterToleranceRules
1217
					.get(i);
1199 1218
			xml.addChild(rule.getXMLEntity());
1200 1219
		}
1201 1220

  
1202 1221
		int numberOfDirtyZones = dirtyZones.size();
1203 1222
		xml.putProperty("numberOfDirtyZones", numberOfDirtyZones);
1204
		for(int i = 0; i < numberOfDirtyZones; i++){
1223
		for (int i = 0; i < numberOfDirtyZones; i++) {
1205 1224
			Rectangle2D rect = dirtyZones.get(i);
1206
			if(rect != null){
1225
			if (rect != null) {
1207 1226
				XMLEntity dirtyZoneXML = new XMLEntity();
1208 1227
				dirtyZoneXML.putProperty("extent" + i + "X", rect.getX());
1209 1228
				dirtyZoneXML.putProperty("extent" + i + "Y", rect.getY());
......
1211 1230
				dirtyZoneXML.putProperty("extent" + i + "H", rect.getHeight());
1212 1231

  
1213 1232
				xml.addChild(dirtyZoneXML);
1214
			}//if
1233
			}// if
1215 1234

  
1216
		}//for
1235
		}// for
1217 1236

  
1218 1237
		XMLEntity errorContainerXML = errorContainer.getXMLEntity();
1219 1238
		xml.addChild(errorContainerXML);
......
1222 1241
		int numberOfRanks = ranksVal.size();
1223 1242
		xml.putProperty("numberOfRanks", numberOfRanks);
1224 1243
		Iterator<XYZLayerRank> xyzRankIterator = layerRanks.values().iterator();
1225
		while(xyzRankIterator.hasNext()){
1244
		while (xyzRankIterator.hasNext()) {
1226 1245
			XYZLayerRank layerRank = xyzRankIterator.next();
1227 1246
			XMLEntity entity = layerRank.getXMLEntity();
1228 1247
			xml.addChild(entity);
......
1230 1249
		return xml;
1231 1250
	}
1232 1251

  
1233

  
1234 1252
	public void setXMLEntity(XMLEntity xml) throws XMLException {
1235 1253
		super.setXMLEntity(xml);
1236 1254

  
1237
		//FIXME Cambiar el uso de childrenCount por el empleo de propiedades
1255
		// FIXME Cambiar el uso de childrenCount por el empleo de propiedades
1238 1256
		int numLayers = this.getLayersCount();
1239 1257
		int numProperties = this.getExtendedProperties().size();
1240 1258

  
1241 1259
		int childrenCount = numLayers + numProperties;
1242 1260

  
1243
		if(xml.contains("clusterTolerance"))
1244
		{
1261
		if (xml.contains("clusterTolerance")) {
1245 1262
			this.clusterTolerance = xml.getDoubleProperty("clusterTolerance");
1246 1263
		}
1247 1264

  
1248
		if(xml.contains("name"))
1249
		{
1265
		if (xml.contains("name")) {
1250 1266
			this.name = xml.getStringProperty("name");
1251 1267
		}
1252 1268

  
1253
		if(xml.contains("status"))
1254
		{
1269
		if (xml.contains("status")) {
1255 1270
			this.status = (byte) xml.getIntProperty("status");
1256 1271
		}
1257 1272

  
1258
		if(xml.contains("maxNumberOfErrors"))
1259
		{
1260
			this.maxNumberOfErrors =  xml.getIntProperty("maxNumberOfErrors");
1273
		if (xml.contains("maxNumberOfErrors")) {
1274
			this.maxNumberOfErrors = xml.getIntProperty("maxNumberOfErrors");
1261 1275
		}
1262 1276

  
1263
		if(xml.contains("numberOfTopologyRules"))
1264
		{
1265
			int numberOfTopologyRules =   xml.getIntProperty("numberOfTopologyRules");
1266
			for(int i = 0; i < numberOfTopologyRules; i++){
1277
		if (xml.contains("numberOfTopologyRules")) {
1278
			int numberOfTopologyRules = xml
1279
					.getIntProperty("numberOfTopologyRules");
1280
			for (int i = 0; i < numberOfTopologyRules; i++) {
1267 1281
				XMLEntity ruleXML = xml.getChild(childrenCount++);
1268
				ITopologyRule rule = TopologyRuleFactory.createFromXML(this, ruleXML);
1282
				ITopologyRule rule = TopologyRuleFactory.createFromXML(this,
1283
						ruleXML);
1269 1284
				this.rules.add(rule);
1270 1285
			}
1271 1286
		}
1272 1287

  
1273

  
1274
		if(xml.contains("numberOfClusterRules")){
1275
			int numberOfClusterRules = xml.getIntProperty("numberOfClusterRules");
1276
			for(int i = 0; i < numberOfClusterRules; i++){
1288
		if (xml.contains("numberOfClusterRules")) {
1289
			int numberOfClusterRules = xml
1290
					.getIntProperty("numberOfClusterRules");
1291
			for (int i = 0; i < numberOfClusterRules; i++) {
1277 1292
				XMLEntity ruleXML = xml.getChild(childrenCount++);
1278
				MustBeLargerThanClusterTolerance rule = (MustBeLargerThanClusterTolerance)TopologyRuleFactory.createFromXML(this, ruleXML);
1293
				MustBeLargerThanClusterTolerance rule = (MustBeLargerThanClusterTolerance) TopologyRuleFactory
1294
						.createFromXML(this, ruleXML);
1279 1295
				this.clusterToleranceRules.add(rule);
1280 1296
			}
1281 1297
		}
1282 1298

  
1283
		if(xml.contains("numberOfDirtyZones")){
1299
		if (xml.contains("numberOfDirtyZones")) {
1284 1300
			int numberOfDirtyZones = xml.getIntProperty("numberOfDirtyZones");
1285
			for(int i = 0; i < numberOfDirtyZones; i++){
1301
			for (int i = 0; i < numberOfDirtyZones; i++) {
1286 1302
				XMLEntity dirtyZoneXml = xml.getChild(childrenCount++);
1287
				double x = dirtyZoneXml.getDoubleProperty("extent"+i+"X");
1288
				double y = dirtyZoneXml.getDoubleProperty("extent"+i+"Y");
1289
				double w = dirtyZoneXml.getDoubleProperty("extent"+i+"W");
1290
				double h = dirtyZoneXml.getDoubleProperty("extent"+i+"H");
1303
				double x = dirtyZoneXml.getDoubleProperty("extent" + i + "X");
1304
				double y = dirtyZoneXml.getDoubleProperty("extent" + i + "Y");
1305
				double w = dirtyZoneXml.getDoubleProperty("extent" + i + "W");
1306
				double h = dirtyZoneXml.getDoubleProperty("extent" + i + "H");
1291 1307

  
1292 1308
				Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
1293 1309
				dirtyZones.add(rect);
1294 1310
			}
1295 1311
		}
1296 1312

  
1297

  
1298

  
1299 1313
		XMLEntity errorContainerXML = xml.getChild(childrenCount++);
1300
		if(errorContainerXML != null)
1301
		{
1302
			this.errorContainer = TopologyPersister.createErrorContainerFromXML(errorContainerXML);
1314
		if (errorContainerXML != null) {
1315
			this.errorContainer = TopologyPersister
1316
					.createErrorContainerFromXML(errorContainerXML);
1303 1317
		}
1304 1318

  
1305
		if(xml.contains("numberOfRanks")){
1319
		if (xml.contains("numberOfRanks")) {
1306 1320
			int numberOfRanks = xml.getIntProperty("numberOfRanks");
1307
			for(int i = 0; i < numberOfRanks; i++){
1321
			for (int i = 0; i < numberOfRanks; i++) {
1308 1322
				XMLEntity xmlRank = xml.getChild(childrenCount++);
1309 1323
				XYZLayerRank rank = new XYZLayerRank();
1310 1324
				rank.setXMLEntity(xmlRank);
......
1316 1330
		return this.errorContainer.getNumberOfExceptions();
1317 1331
	}
1318 1332

  
1319

  
1320

  
1321 1333
	public String getName() {
1322 1334
		return name;
1323 1335
	}
1324 1336

  
1325

  
1326

  
1327 1337
	public void setName(String name) {
1328 1338
		this.name = name;
1329 1339
	}
1330 1340

  
1331
	public ITopologyErrorContainer getErrorContainer(){
1341
	public ITopologyErrorContainer getErrorContainer() {
1332 1342
		return this.errorContainer;
1333 1343
	}
1334 1344

  
1335

  
1336
	public FLayer getErrorLayer(){
1345
	public FLayer getErrorLayer() {
1337 1346
		return this.errorLayer;
1338 1347
	}
1339 1348

  
1340
	public void setErrorContainer(ITopologyErrorContainer errorContainer){
1349
	public void setErrorContainer(ITopologyErrorContainer errorContainer) {
1341 1350
		this.errorContainer = errorContainer;
1342 1351
		this.errorContainer.setTopology(this);
1343 1352
	}
1344 1353

  
1345
	private void fireStatusChange(TopologyStatusEvent event){
1346
		Iterator<ITopologyStatusListener> it =
1347
			this.statusListeners.iterator();
1348
		while(it.hasNext()){
1354
	private void fireStatusChange(TopologyStatusEvent event) {
1355
		Iterator<ITopologyStatusListener> it = this.statusListeners.iterator();
1356
		while (it.hasNext()) {
1349 1357
			ITopologyStatusListener listener = it.next();
1350 1358
			listener.statusChange(event);
1351 1359
		}
......
1359 1367
		this.errorContainer.removeErrorsByRule(ruleName);
1360 1368
	}
1361 1369

  
1362
	public void setRules(List<ITopologyRule> rules){
1370
	public void setRules(List<ITopologyRule> rules) {
1363 1371
		this.rules = rules;
1364 1372
	}
1365 1373

  
1366
	public void setDirtyZones(List<Rectangle2D> dirtyZones){
1374
	public void setDirtyZones(List<Rectangle2D> dirtyZones) {
1367 1375
		this.dirtyZones = dirtyZones;
1368 1376
	}
1369 1377

  
1370
	public void setStatusListeners(List<ITopologyStatusListener> statusListeners){
1378
	public void setStatusListeners(List<ITopologyStatusListener> statusListeners) {
1371 1379
		this.statusListeners = statusListeners;
1372 1380
	}
1373 1381

  
1374
	public void setLayerRanks(Map<FLyrVect, XYZLayerRank> layerRanks){
1382
	public void setLayerRanks(Map<FLyrVect, XYZLayerRank> layerRanks) {
1375 1383
		this.layerRanks = layerRanks;
1376 1384
	}
1377 1385

  
1378
	public Object clone(){
1379
		Topology newTopology = new Topology(super.getMapContext(), super.getParentLayer());
1386
	public Object clone() {
1387
		Topology newTopology = new Topology(super.getMapContext(), super
1388
				.getParentLayer());
1380 1389
		newTopology.setName(this.name);
1381 1390
		newTopology.setClusterTolerance(this.clusterTolerance);
1382 1391
		newTopology.ruleId = ruleId;
1383 1392
		newTopology.setMaxNumberOfErrors(maxNumberOfErrors);
1384
		newTopology.setRules(rules)	;
1393
		newTopology.setRules(rules);
1385 1394
		newTopology.setDirtyZones(dirtyZones);
1386 1395
		newTopology.setStatusListeners(statusListeners);
1387 1396
		newTopology.setLayerRanks(layerRanks);
1388 1397
		newTopology.layers = new ArrayList();
1389
		for(int i = 0; i < layers.size(); i++){
1398
		for (int i = 0; i < layers.size(); i++) {
1390 1399
			newTopology.addLayer((FLayer) layers.get(i));
1391 1400
		}
1392 1401
		newTopology.setStatus(status);
1393
		newTopology.setErrorContainer((ITopologyErrorContainer) errorContainer.clone());
1402
		newTopology.setErrorContainer((ITopologyErrorContainer) errorContainer
1403
				.clone());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff