Revision 26209

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/BaseTestEditableFeatureStore.java
33 33
import java.util.Iterator;
34 34

  
35 35
import org.gvsig.fmap.dal.DataServerExplorer;
36
import org.gvsig.fmap.dal.DataStore;
36 37
import org.gvsig.fmap.dal.DataStoreParameters;
37 38
import org.gvsig.fmap.dal.DataTypes;
38 39
import org.gvsig.fmap.dal.exception.DataException;
......
48 49
import org.gvsig.tools.evaluator.EvaluatorData;
49 50
import org.gvsig.tools.evaluator.EvaluatorException;
50 51
import org.gvsig.tools.evaluator.EvaluatorFieldValue;
52
import org.gvsig.tools.observer.Observable;
53
import org.gvsig.tools.observer.Observer;
51 54

  
52 55
/**
53 56
 * @author jmvivo
......
57 60

  
58 61
	public abstract NewFeatureStoreParameters getDefaultNewDataStoreParameters()
59 62
			throws DataException;
63
	
64
	public abstract boolean usesResources();
60 65

  
61 66
	//=================================================
62 67
	//=================================================
......
387 392
			try {
388 393
				this.clearCopy(store, newParams);
389 394
			} catch (RemoveException e) {
390
				//Dp nothing
395
				//Do nothing
391 396
			}
392 397

  
393 398
			FeatureStore result = this.getStoreCopy(store, newParams);
......
1128 1133
			}
1129 1134

  
1130 1135
			set.dispose();
1136
			
1137
			
1138
			
1131 1139

  
1132 1140

  
1133 1141
			originalSet.dispose();
......
1143 1151
		}
1144 1152

  
1145 1153
	}
1154
	
1146 1155

  
1156
	public void testResourceChangeNotification() {
1157
		DataStoreParameters parameters = null;
1158

  
1159
		try {
1160
			parameters = getDefaultDataStoreParameters();
1161

  
1162
			FeatureStore store = (FeatureStore) dataManager
1163
					.createStore(parameters);
1164

  
1165
			NewFeatureStoreParameters newParams = this
1166
					.getDefaultNewDataStoreParameters();
1167
			try {
1168
				this.clearCopy(store, newParams);
1169
			} catch (RemoveException e) {
1170
				//Dp nothing
1171
			}
1172

  
1173
			FeatureStore result = this.getStoreCopy(store, newParams);
1174

  
1175
			FeatureStore result2 = (FeatureStore) dataManager
1176
				.createStore(newParams);
1177

  
1178
			FeatureAttributeDescriptor attr = getFirstAttributeOfType(result.getDefaultFeatureType(), DataTypes.STRING);
1179
			assertNotNull("No String attributes found", attr);
1180

  
1181

  
1182
			UpdateFeature updater = new UpdateFeature("1", result,
1183
					UpdateFeature.TIME_TO_WAIT_NO_WAIT);
1184

  
1185
			updater.addUpdate(UpdateFeature.UPDATE_LAST_FEATURE,
1186
					attr.getName(), getEvaluatorToLower(attr.getName()));
1187

  
1188
			StoreObserverForNotify observer = new StoreObserverForNotify(result2,FeatureStoreNotification.RESOURCE_CHANGED);			
1189
			result2.addObserver(observer);
1190
			
1191
			result.edit();
1192
			updater.run();
1193
			while (updater.getCurrentStatus() < EditStore.STATUS_FINISHED_OK
1194
					&& !updater.isOutOfDate()) {
1195
				Thread.yield();
1196
				try {
1197
					Thread.sleep(200);
1198
				} catch (InterruptedException e) {
1199
					e.printStackTrace();
1200
					fail();
1201
				}
1202
			}
1203
			
1204
			result.finishEditing();
1205

  
1206
			assertTrue(observer.notified());
1207
			
1208
			result2.refresh();
1209
			
1210
			FeatureSet set = result.getFeatureSet();
1211
			FeatureSet set2 = result2.getFeatureSet();
1212
			
1213
			assertTrue(this.compareFeatureIterators(set.iterator(), set2.iterator()));
1214
			
1215
			set2.dispose();
1216
			set.dispose();
1217
			
1218
			// TODO checks FeatureType change
1219
			
1220
			result2.dispose();
1221
			result.dispose();
1222
			this.clearCopy(store, newParams);
1223
			store.dispose();
1224

  
1225
		} catch (DataException e3) {
1226
			e3.printStackTrace();
1227
			fail();
1228
			return;
1229
		}
1230

  
1231
	}
1232

  
1233
	public abstract class StoreObserver implements Observer{
1234
		
1235
		public DataStore store = null;
1236
		
1237
	}
1238

  
1239
	public class StoreObserverForNotify implements Observer{
1240
		
1241
		public DataStore store = null;
1242
		
1243
		public String notifyType = null;
1244
		
1245
		private boolean notifyRecived = false;
1246
		
1247
		public StoreObserverForNotify(DataStore store,String notifyType){
1248
			this.store = store;
1249
			this.notifyType = notifyType;
1250
			this.notifyRecived = false;
1251
		}
1252
		
1253
		public boolean notified(){
1254
			return notifyRecived;
1255
		}
1256

  
1257
		public void update(Observable observable, Object notification) {
1258
			if (!(observable == this.store)){
1259
				return;
1260
			}
1261
			if (!(notification instanceof FeatureStoreNotification)){
1262
				return;
1263
			}
1264
			FeatureStoreNotification fsNotification = (FeatureStoreNotification) notification;
1265

  
1266
			if (fsNotification.getType().equals(this.notifyType)){
1267
				notifyRecived = true;
1268
			}
1269
		}
1270
		
1271
	}
1272

  
1273
	
1147 1274
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/spi/AbstractResource.java
220 220

  
221 221
	public void notifyChanges() throws ResourceNotifyChangesException {
222 222
		this.notifyObserver(ResourceNotification.CHANGED);
223

  
224
		
225
		Iterator it = consumers.iterator();
226
		while (it.hasNext()) {
227
			ResourceConsumer consumer = (ResourceConsumer) ((WeakReference) it
228
					.next()).get();
229
			if (consumer != null) {
230
				consumer.resourceChanged(this);
231
			} else {
232
				it.remove();
233
			}
234
		}
235

  
223 236
	}
224 237

  
225 238
	public void notifyDispose() throws ResourceNotifyDisposeException {
......
270 283
	}
271 284

  
272 285
	public final void removeConsumer(ResourceConsumer consumer) {
273
		this.updateConsumersList();
274
		consumers.remove(consumer);
286
		ResourceConsumer cur;
287
		Iterator it = consumers.iterator();
288
		while (it.hasNext()) {
289
			cur = (ResourceConsumer) ((WeakReference) it
290
					.next()).get();
291
			if (cur == null || (cur == consumer)) {
292
				it.remove();
293
			}
294
		}
275 295
	}
276 296

  
277 297
	public int getConsumersCount() {
......
300 320
					.next()).get();
301 321
			if (consumer != null) {
302 322
				consumer.closeResourceRequested(this);
323
			} else {
324
				it.remove();
303 325
			}
304 326
		}
305 327
	}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
438 438
	 * (java.lang.String, org.gvsig.fmap.dal.resource.Resource)
439 439
	 */
440 440
	public void notifyChange(String notification, Resource resource) {
441
		// TODO Auto-generated method stub
442

  
441
		delegateObservable.notifyObservers(new DefaultFeatureStoreNotification(this,
442
                FeatureStoreNotification.RESOURCE_CHANGED));
443 443
	}
444 444

  
445 445

  
branches/v2_0_0_prep/libraries/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/TestSHP.java
323 323
				.getAddParameters(file_prueba_destino);
324 324
	}
325 325

  
326
	public boolean usesResources() {
327
		return true;
328
	}
329

  
326 330
}
branches/v2_0_0_prep/libraries/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/dbf/TestDBF.java
194 194
				.getAddParameters(dbf_prueba_destino);
195 195
	}
196 196

  
197
	public boolean usesResources() {
198
		return true;
199
	}
200

  
197 201
}

Also available in: Unified diff