Revision 40597

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/exception/AttributeNameTooLongException.java
1
package org.gvsig.fmap.dal.feature.exception;
2

  
3
import org.gvsig.fmap.dal.exception.DataException;
4

  
5
/**
6
 * 
7
 * 
8
 * @author jldominguez
9
 *
10
 */
11
public class AttributeNameTooLongException extends AttributeNameException {
12
	
13
	/**
14
	 * 
15
	 */
16
	private static final long serialVersionUID = 1L;
17
	private final static String MESSAGE_FORMAT =
18
			"Attribute name '%(attrname)' is too long in '%(storeName)'. Max length is %(maxlen)";
19
	private final static String MESSAGE_KEY = "_AttributeNameTooLongException";
20

  
21
	public AttributeNameTooLongException(
22
			String attrname,
23
			String storeName,
24
			int maxlen) {
25
		
26
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
27
		setValue("attrname", attrname);
28
		setValue("storeName", storeName);
29
		setValue("maxlen", Integer.toString(maxlen));
30
	}
31

  
32
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/exception/AttributeNameException.java
1
package org.gvsig.fmap.dal.feature.exception;
2

  
3
import org.gvsig.fmap.dal.exception.DataException;
4

  
5
/**
6
 * 
7
 * Used to notify the case when the name of an attribute is not valid
8
 * for a certain data store. Example: A field name longer than
9
 * 11 characters in a DBF file. Perhaps: a field name with invalid characters
10
 * in a database.
11
 * 
12
 * @author jldominguez
13
 *
14
 */
15
public class AttributeNameException extends DataException {
16
	
17
	/**
18
	 * 
19
	 */
20
	private static final long serialVersionUID = 1L;
21
	private final static String MESSAGE_FORMAT =
22
			"Attribute name '%(attrname)' not valid in '%(storeName)'.";
23
	private final static String MESSAGE_KEY = "_AttributeNameException";
24

  
25
	public AttributeNameException(
26
			String attrname,
27
			String storeName) {
28
		
29
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
30
		setValue("attrname", attrname);
31
		setValue("storeName", storeName);
32

  
33
	}
34
	
35
	public AttributeNameException(
36
			String messageFormat, String messageKey, long code) {
37
		
38
		super(messageFormat, messageKey, code);
39
	}
40

  
41

  
42
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java
48 48
import org.gvsig.fmap.dal.feature.FeatureSet;
49 49
import org.gvsig.fmap.dal.feature.FeatureStore;
50 50
import org.gvsig.fmap.dal.feature.FeatureType;
51
import org.gvsig.fmap.dal.feature.exception.AttributeNameException;
51 52
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
52 53
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
53 54
import org.gvsig.fmap.dal.resource.ResourceAction;
......
435 436
//			this.resourcesEnd();
436 437
//		}
437 438
	}
439
	
440
	public void performChanges(Iterator deleteds, Iterator inserteds,
441
			Iterator updateds, Iterator originalFeatureTypesUpdated)
442
					throws PerformEditingException {
443
		
444
		
445
		/*
446
		 * This will throw an exception if there are new fields
447
		 * with names too long
448
		 */
449
		checkNewFieldsNameSize(originalFeatureTypesUpdated);
438 450

  
439
	public void performChanges(Iterator deleteds, Iterator inserteds,
440
			Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
451
		
441 452
		final FeatureType fType;
442 453
		try {
443 454
			fType = this.getStoreServices().getDefaultFeatureType();
......
548 559

  
549 560
	}
550 561

  
562

  
563

  
551 564
	protected void resourceCloseRequest() throws ResourceException {
552 565
		// super.resourceCloseRequest();
553 566
		// this.shpResource.closeRequest();
......
623 636
	public Object getSourceId() {
624 637
		return this.getShpParameters().getFile();
625 638
	}
626
}
639
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java
60 60
import org.gvsig.fmap.dal.feature.FeatureSet;
61 61
import org.gvsig.fmap.dal.feature.FeatureStore;
62 62
import org.gvsig.fmap.dal.feature.FeatureType;
63
import org.gvsig.fmap.dal.feature.exception.AttributeNameException;
64
import org.gvsig.fmap.dal.feature.exception.AttributeNameTooLongException;
63 65
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
64 66
import org.gvsig.fmap.dal.feature.exception.UnknownDataTypeException;
65 67
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
66 68
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
67 69
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
68 70
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
71
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider.FeatureTypeChanged;
69 72
import org.gvsig.fmap.dal.resource.ResourceAction;
70 73
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
71 74
import org.gvsig.fmap.dal.resource.exception.ResourceException;
......
93 96

  
94 97
    private static final Logger LOG = LoggerFactory.getLogger(DBFStoreProvider.class);
95 98

  
99
    public static final int MAX_FIELD_NAME_LENGTH = 11;
100
    
96 101
	public static String NAME = "DBF";
97 102
	public static String DESCRIPTION = "DBF file";
98 103
	private static final Locale ukLocale = new Locale("en", "UK");
......
217 222
	public void performChanges(Iterator deleteds, Iterator inserteds,
218 223
			Iterator updateds, Iterator originalFeatureTypesUpdated)
219 224
			throws PerformEditingException {
225
		
226
		/*
227
		 * This will throw an exception if there are new fields
228
		 * with names too long
229
		 */
230
		checkNewFieldsNameSize(originalFeatureTypesUpdated);
220 231

  
221 232
		try {
222 233
			final FeatureStore store =
......
290 301

  
291 302
		this.counterNewsOIDs = -1;
292 303
	}
304
	
305
	protected void checkNewFieldsNameSize(Iterator ft_upd) throws PerformEditingException {
293 306

  
307
		String long_fields = getNewFieldsWithNameTooLong(ft_upd);
308
		if (long_fields != null) {
309
			AttributeNameException ane = new AttributeNameTooLongException(
310
					long_fields,
311
					getProviderName(),
312
					MAX_FIELD_NAME_LENGTH);
313
			throw new PerformEditingException(getProviderName(), ane);
314
		}
315
	}
316
	
317
	/**
318
	 * Returns null or a string which is a comma-separated list
319
	 * 
320
	 * @param ft_updated
321
	 * @return
322
	 */
323
	protected String getNewFieldsWithNameTooLong(Iterator ft_updated) {
324
		
325
		String resp = "";
326
		FeatureTypeChanged item = null;
327
		FeatureType ft = null;
328
		FeatureAttributeDescriptor[] atts = null;
329
		while (ft_updated.hasNext()) {
330
			item = (FeatureTypeChanged) ft_updated.next();
331
			ft = item.getTarget();
332
			atts = ft.getAttributeDescriptors();
333
			for (int i=0; i<atts.length; i++) {
334
				if (atts[i].getName().length() > MAX_FIELD_NAME_LENGTH) {
335
					if (resp.length() == 0) {
336
						resp = atts[i].getName(); 
337
					} else {
338
						resp = resp + ", " + atts[i].getName(); 
339
					}
340
				}
341
			}
342
		}
343
		
344
		if (resp.length() == 0) {
345
			return null;
346
		} else {
347
			return "(" + resp + ")";
348
		}
349
	}
294 350
	/*
295 351
	 * ==================================================
296 352
	 */
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
55 55
import org.gvsig.fmap.dal.exception.OpenException;
56 56
import org.gvsig.fmap.dal.exception.ReadException;
57 57
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
58
import org.gvsig.fmap.dal.exception.WriteException;
58 59
import org.gvsig.fmap.dal.feature.EditableFeature;
59 60
import org.gvsig.fmap.dal.feature.EditableFeatureType;
60 61
import org.gvsig.fmap.dal.feature.Feature;
......
85 86
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
86 87
import org.gvsig.fmap.dal.feature.exception.NoNewFeatureInsertException;
87 88
import org.gvsig.fmap.dal.feature.exception.NullFeatureTypeException;
89
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
88 90
import org.gvsig.fmap.dal.feature.exception.PersistenceCantFindDefaultFeatureTypeException;
89 91
import org.gvsig.fmap.dal.feature.exception.PersistenceCantFindFeatureTypeException;
90 92
import org.gvsig.fmap.dal.feature.exception.PersistenceStoreAlreadyLoadedException;
......
1195 1197
                notifyChange(FeatureStoreNotification.BEFORE_FINISHEDITING);
1196 1198
                if (hasStrongChanges) {
1197 1199
                    validateFeatures(Feature.FINISH_EDITING);
1200
                    
1201
                    /*
1202
                     * This will throw a PerformEditingExceptionif the provider
1203
                     * does not accept the changes (for example, an invalid field name)
1204
                     */
1198 1205
                    provider.performChanges(featureManager.getDeleted(),
1199 1206
                        featureManager.getInserted(),
1200 1207
                        featureManager.getUpdated(),
......
1205 1212
                notifyChange(FeatureStoreNotification.AFTER_FINISHEDITING);
1206 1213
                break;
1207 1214
            }
1215
        } catch (PerformEditingException pee) {
1216
            throw new WriteException(provider.getProviderName(), pee);
1208 1217
        } catch (Exception e) {
1209 1218
            throw new FinishEditingException(e);
1210 1219
        }
......
2127 2136
        return cloned_store;
2128 2137
        
2129 2138
    }
2130
}
2139
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/plugins/PluginClassLoader.java
68 68
 */
69 69
public class PluginClassLoader extends URLClassLoader {
70 70
    /** DOCUMENT ME! */
71
    private static Logger logger = LoggerFactory.getLogger(PluginClassLoader.class.getName());
71
    // private static Logger logger = LoggerFactory.getLogger(PluginClassLoader.class.getName());
72
	
73
    private MyDummyLogger logger = new MyDummyLogger();
72 74

  
73 75
    /** DOCUMENT ME! */
74 76
    private Hashtable<String, ZipFile> clasesJar = new Hashtable<String, ZipFile>();
......
147 149
    }
148 150

  
149 151
    private void debugDump() {
152
    	
150 153
    	if( !logger.isDebugEnabled() ) {
151 154
    		return;
152 155
    	}
......
498 501
    public String toString() {
499 502
        return super.toString() + " (" + getPluginName() + ")";
500 503
    }
504
    
505
    public class MyDummyLogger {
506
    	
507
    	public MyDummyLogger() {
508
    		
509
    	}
510
    	
511
    	public void debug(String str, Throwable th) {
512
    		
513
    	}
514
    	
515
    	public void debug(String str, String str2) {
516
    		
517
    	}
518

  
519
    	public void debug(String str, String str2, File f) {
520
    		
521
    	}
522

  
523
    	public void debug(String str, String str2, String f) {
524
    		
525
    	}
526

  
527
    	public void debug(String str) {
528
    		
529
    	}
530

  
531
    	public void warn(String str, Object[] oo) {
532
    		
533
    	}
534

  
535
    	public void info(String str, Object[] oo) {
536
    		
537
    	}
538

  
539
    	public void info(String str, Object[] oo, Throwable th) {
540
    		
541
    	}
542

  
543
    	public void debug(String str, Object[] oo) {
544
    		
545
    	}
546
    	
547
    	public boolean isDebugEnabled() {
548
    		return false;
549
    	}
550

  
551
    }
501 552
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.editing.app/org.gvsig.editing.app.mainplugin/src/main/java/org/gvsig/editing/EditionManager.java
55 55
import org.gvsig.fmap.dal.feature.FeatureSelection;
56 56
import org.gvsig.fmap.dal.feature.FeatureStore;
57 57
import org.gvsig.fmap.dal.feature.FeatureType;
58
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
58 59
import org.gvsig.fmap.dal.feature.rule.CheckMandatoryAttributesRule;
59 60
import org.gvsig.fmap.geom.Geometry;
60 61
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
......
783 784
	            }
784 785
	            break;
785 786
	        case ACCEPT_EDITING:
786
	            lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
787
	            lv.getFeatureStore().deleteObserver(lyrEd);
788 787
	            featureStore = lv.getFeatureStore();
789 788
	            try {
789
	            	
790
	            	/*
791
	            	 * This will throw a WriteException
792
	            	 * also if the provider does not accept
793
	            	 * the changes (added/updated/deleted/updated featuretype)  
794
	            	 */
790 795
	                featureStore.finishEditing();
791
	            } catch (WriteException e) {
792
	                throw new ReadException(lv.getName(), e);
796
	                
793 797
	            } catch (DataException e) {
794 798
	                throw new ReadException(lv.getName(), e);
795 799
	            }
796
	            lv.getFeatureStore().deleteObserver(view);
800
	            lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
801
	            featureStore.deleteObserver(lyrEd);
802
	            featureStore.deleteObserver(view);
797 803
	            lv.removeLayerListener(this);
798 804
	            if (view != null) {
799 805
	                view.getMapControl().getMapContext().removeLayerDrawListener(lyrEd);
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.editing.app/org.gvsig.editing.app.mainplugin/src/main/java/org/gvsig/editing/EditionUtilities.java
159 159
//		return lyrDef;
160 160
//	}
161 161

  
162

  
163
	public static String getLastMessage(Throwable ex) {
164
        
165
        Throwable p = ex;
166
        while (p.getCause() != null && p.getCause() != p) {
167
            p = p.getCause();
168
        }
169
        return p.getMessage();
170
    }
162 171
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.editing.app/org.gvsig.editing.app.mainplugin/src/main/java/org/gvsig/editing/StopEditing.java
47 47
import org.gvsig.andami.plugins.status.IExtensionStatus;
48 48
import org.gvsig.andami.plugins.status.IUnsavedData;
49 49
import org.gvsig.andami.plugins.status.UnsavedData;
50
import org.gvsig.app.ApplicationLocator;
50 51
import org.gvsig.app.project.Project;
51 52
import org.gvsig.app.project.ProjectManager;
52 53
import org.gvsig.app.project.documents.view.DefaultViewDocument;
......
119 120
					try {
120 121
	                    edMan.stopEditLayer(vista, lv, user_opt);
121 122
					} catch (Exception ex) {
122
					    logger.error("While stopping layer editing.", ex);
123
						
124
						/*
125
						 * Unable to end editing, inform user
126
						 * of the problem. Editing session will continue.
127
						 */
128
		            	showUnableToEndEditingDialog(ex);
129
		            	isStop = false;
130
					    logger.info("While stopping layer editing.", ex);
123 131
					}
124 132
				}
125 133
			}
......
132 140
	}
133 141

  
134 142

  
143
	private void showUnableToEndEditingDialog(Exception ex) {
144
		
145
		String msg = Messages.getText(
146
				"_Invalid_values_in_some_fields_must_be_edited_before_end_editing");
147
		msg = msg + ":\n\n" + EditionUtilities.getLastMessage(ex);
148
		JOptionPane.showMessageDialog(
149
				ApplicationLocator.getManager().getRootComponent(),
150
				msg,
151
				Messages.getText("_Guardar"),
152
				JOptionPane.ERROR_MESSAGE);
153
		
154
	}
155

  
135 156
	/**
136 157
	 * @see org.gvsig.andami.plugins.IExtension#isEnabled()
137 158
	 */

Also available in: Unified diff