Revision 41807

View differences:

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/FLyrDefault.java
261 261
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
262 262
	 */
263 263
	public String getName() {
264
		return (String) this.metadataContainer.getDynValue(METADATA_NAME);
264
            String name = "(unknow)";
265
            try {
266
                name = (String) this.metadataContainer.getDynValue(METADATA_NAME);
267
            } catch( Throwable th) {
268
                logger.warn("Can't retrive the layer name.");
269
            }
270
            return name;
265 271
	}
266 272

  
267 273
	/*
......
927 933
	// ========================================================
928 934
	
929 935
	public void saveToState(PersistentState state) throws PersistenceException {
936
            try {
930 937
		state.set("parentLayer", parentLayer);
931 938
		state.set("status",status);
932 939
		state.set("minScale", minScale);
......
936 943
		state.set("name", getName());
937 944
		state.set("crs", getProjection());
938 945
		state.set("properties",properties.getExtendedProperties());
946
            } catch(PersistenceException ex) {
947
                logger.warn("Can't save to persistent state the layer '"+this.getName()+"'.");
948
                throw ex;
949
            } catch(RuntimeException ex) {
950
                logger.warn("Can't save to persistent state the layer '"+this.getName()+"'.");
951
                throw ex;
952
            }
939 953
	}
940 954

  
941 955
	public void loadFromState(PersistentState state) throws PersistenceException {
956
            try {
957
		this.setDynValue(METADATA_NAME, state.getString("name"));
958
		this.setDynValue(METADATA_CRS, state.get("crs"));
959
		
942 960
		this.parentLayer = (FLayers) state.get("parentLayer");
943 961
		this.status = (FLayerStatus) state.get("status");
944 962
		this.minScale = state.getDouble("minScale");
......
946 964
		this.transparency = state.getInt("transparency");
947 965
		this.ct = (ICoordTrans) state.get("coordTrans");
948 966

  
949
		this.setDynValue(METADATA_NAME, state.getString("name"));
950
		this.setDynValue(METADATA_CRS, state.get("crs"));
951
		
952 967
                this.properties.setExtendedProperties(new Hashtable((Map)state.get("properties")));
968
            } catch(PersistenceException ex) {
969
                logger.warn("Can't load from persietent state the layer '"+this.getName()+"'.");
970
                throw ex;
971
            } catch(RuntimeException ex) {
972
                logger.warn("Can't load from persietent state the layer '"+this.getName()+"'.");
973
                throw ex;
974
            }
953 975

  
954 976
	}
955 977

  
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
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