Revision 41807 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java
FLyrVect.java | ||
---|---|---|
419 | 419 |
|
420 | 420 |
public void saveToState(PersistentState state) throws PersistenceException { |
421 | 421 |
|
422 |
if (!this.isAvailable()) { |
|
422 |
FeatureStore featureStore = null; |
|
423 |
|
|
424 |
if ( !this.isAvailable() ) { |
|
425 |
logger.info("The '" + this.getName() + "' layer is not available, it will persist not."); |
|
423 | 426 |
return; |
424 | 427 |
} |
428 |
|
|
429 |
try { |
|
430 |
super.saveToState(state); |
|
425 | 431 |
|
426 |
super.saveToState(state); |
|
432 |
if ( getLegend() != null ) { |
|
433 |
state.set("legend", getLegend()); |
|
434 |
} |
|
427 | 435 |
|
428 |
if (getLegend() != null) { |
|
429 |
state.set("legend", getLegend()); |
|
430 |
} |
|
436 |
featureStore = getFeatureStore(); |
|
431 | 437 |
|
432 |
FeatureStore fst = null; |
|
433 |
fst = getFeatureStore(); |
|
438 |
if ( featureStore != null ) { |
|
439 |
state.set("featureStore", featureStore); |
|
440 |
} |
|
434 | 441 |
|
435 |
if (fst != null) { |
|
436 |
state.set("featureStore", fst); |
|
437 |
} |
|
442 |
state.set("isLabeled", isLabeled); |
|
438 | 443 |
|
439 |
state.set("isLabeled", isLabeled); |
|
444 |
if ( strategy != null ) { |
|
445 |
state.set("labelingStrategy", strategy); |
|
446 |
} |
|
440 | 447 |
|
441 |
if (strategy != null) {
|
|
442 |
state.set("labelingStrategy", strategy);
|
|
443 |
} |
|
448 |
if ( getLinkProperties() != null ) {
|
|
449 |
state.set("linkProperties", getLinkProperties());
|
|
450 |
}
|
|
444 | 451 |
|
445 |
if (getLinkProperties() != null) { |
|
446 |
state.set("linkProperties", getLinkProperties()); |
|
452 |
state.set("typeShape", typeShape); |
|
453 |
} catch (PersistenceException ex) { |
|
454 |
logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
|
455 |
throw ex; |
|
456 |
} catch (RuntimeException ex) { |
|
457 |
logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
|
458 |
throw ex; |
|
447 | 459 |
} |
448 | 460 |
|
449 |
// state.set("bHasJoin", bHasJoin); |
|
450 |
state.set("typeShape", typeShape); |
|
451 | 461 |
} |
452 | 462 |
|
453 | 463 |
|
454 | 464 |
public void loadFromState(PersistentState state) throws PersistenceException { |
455 | 465 |
|
456 | 466 |
DataStore store = null; |
457 |
try { |
|
458 |
super.loadFromState(state); |
|
459 |
store = (DataStore) state.get("featureStore"); |
|
460 |
} catch (PersistenceRuntimeException e) { |
|
461 |
logger.debug("Unable to load store from persistence in layer: " + this.getName(), e); |
|
462 |
this.setAvailable(false); |
|
463 |
return; |
|
464 |
} |
|
467 |
IVectorLegend vectorLegend = null; |
|
468 |
ILabelingStrategy labelingStrategy = null; |
|
469 |
Boolean isLabeled = Boolean.FALSE; |
|
465 | 470 |
|
466 | 471 |
try { |
467 |
this.bindToDataStore(store); |
|
468 |
} catch (LoadLayerException e) { |
|
469 |
throw new PersistenceException("While loading FLyrVect from state.", |
|
470 |
e); |
|
471 |
} |
|
472 |
|
|
473 |
IVectorLegend lgnd = null; |
|
474 |
|
|
475 |
try { |
|
476 |
lgnd = (IVectorLegend) state.get("legend"); |
|
477 |
} catch (PersistenceRuntimeException pre) { |
|
478 |
/* |
|
479 |
* For example, symbol image file not found |
|
480 |
*/ |
|
481 |
logger.debug("Unable to instantiate persisted lagend.", pre); |
|
482 |
this.setAvailable(false); |
|
483 |
return; |
|
484 |
} |
|
485 |
|
|
486 |
try { |
|
487 |
this.setLegend(lgnd); |
|
488 |
} catch (LegendLayerException e) { |
|
489 |
throw new PersistenceException("While loading FLyrVect from state.", e); |
|
490 |
} |
|
472 |
super.loadFromState(state); |
|
473 |
store = (DataStore) state.get("featureStore"); |
|
491 | 474 |
|
492 |
Boolean isLbl = new Boolean(false); |
|
493 |
ILabelingStrategy lblst = null; |
|
475 |
try { |
|
476 |
this.bindToDataStore(store); |
|
477 |
} catch (LoadLayerException e) { |
|
478 |
throw new PersistenceException("Can't bind layer '"+this.getName()+"' to store '"+store.getFullName()+"'.",e); |
|
479 |
} |
|
494 | 480 |
|
495 |
try { |
|
496 |
isLbl = (Boolean) state.get("isLabeled"); |
|
497 |
if (isLbl.booleanValue()) { |
|
498 |
lblst = (ILabelingStrategy) state.get("labelingStrategy"); |
|
481 |
|
|
482 |
vectorLegend = (IVectorLegend) state.get("legend"); |
|
483 |
|
|
484 |
try { |
|
485 |
this.setLegend(vectorLegend); |
|
486 |
} catch (LegendLayerException e) { |
|
487 |
throw new PersistenceException("Can't set vector legend to the layer.", e); |
|
499 | 488 |
} |
500 |
} catch (Exception ex) { |
|
501 |
throw new PersistenceException("While loading FLyrVect from state.", |
|
502 |
ex); |
|
503 |
} |
|
504 | 489 |
|
505 |
/* |
|
506 |
* String _labelFieldName = null; |
|
507 |
* String _labelfield = null; |
|
508 |
*/ |
|
509 | 490 |
|
510 |
if (isLbl.booleanValue()) { |
|
511 |
this.setIsLabeled(true); |
|
512 |
this.setLabelingStrategy(lblst); |
|
513 |
} else { |
|
514 |
this.setIsLabeled(false); |
|
515 |
this.setLabelingStrategy(null); |
|
516 |
} |
|
491 |
try { |
|
492 |
isLabeled = (Boolean) state.get("isLabeled"); |
|
493 |
if ( isLabeled.booleanValue() ) { |
|
494 |
labelingStrategy = (ILabelingStrategy) state.get("labelingStrategy"); |
|
495 |
} |
|
496 |
} catch (Exception ex) { |
|
497 |
throw new PersistenceException("Can't load labeling strategi from persistent state.", |
|
498 |
ex); |
|
499 |
} |
|
517 | 500 |
|
518 |
typeShape = state.getInt("typeShape"); |
|
501 |
if ( isLabeled.booleanValue() ) { |
|
502 |
this.setIsLabeled(true); |
|
503 |
this.setLabelingStrategy(labelingStrategy); |
|
504 |
} else { |
|
505 |
this.setIsLabeled(false); |
|
506 |
this.setLabelingStrategy(null); |
|
507 |
} |
|
519 | 508 |
|
509 |
typeShape = state.getInt("typeShape"); |
|
510 |
|
|
511 |
} catch (Throwable e) { |
|
512 |
String storeName = (store == null)? "unknow" : store.getFullName(); |
|
513 |
logger.warn("can't load layer '" + this.getName() + "' (store="+storeName+") from persisted state.", e); |
|
514 |
this.setAvailable(false); |
|
515 |
return; |
|
516 |
} |
|
517 |
|
|
520 | 518 |
} |
521 | 519 |
|
522 | 520 |
/** |
Also available in: Unified diff