Revision 45425 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/impl/DefaultDataManager.java
DefaultDataManager.java | ||
---|---|---|
13 | 13 |
import java.util.Objects; |
14 | 14 |
import java.util.Set; |
15 | 15 |
import java.util.UUID; |
16 |
import javax.json.JsonArray; |
|
17 | 16 |
import javax.json.JsonObject; |
18 |
import javax.json.JsonValue; |
|
19 | 17 |
import org.apache.commons.io.IOUtils; |
20 | 18 |
import org.apache.commons.lang3.StringUtils; |
21 | 19 |
import org.gvsig.expressionevaluator.Expression; |
... | ... | |
24 | 22 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
25 | 23 |
import org.gvsig.expressionevaluator.impl.DefaultDALExpressionBuilder; |
26 | 24 |
import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
27 |
import org.gvsig.expressionevaluator.spi.JsonUtils; |
|
28 | 25 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
29 | 26 |
import org.gvsig.fmap.dal.DALLocator; |
30 | 27 |
|
... | ... | |
112 | 109 |
import org.slf4j.Logger; |
113 | 110 |
import org.slf4j.LoggerFactory; |
114 | 111 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
115 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
116 | 112 |
import org.gvsig.tools.dispose.DisposeUtils; |
117 | 113 |
import org.gvsig.tools.observer.Observer; |
118 | 114 |
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
115 |
import org.gvsig.fmap.dal.spi.DataServerExplorerPoolImpl; |
|
116 |
import static org.gvsig.fmap.dal.spi.DataStoreProviderServices.PROVIDER_PARAMTER_NAME; |
|
117 |
import org.gvsig.json.Json; |
|
119 | 118 |
|
120 | 119 |
@SuppressWarnings("UseSpecificCatch") |
121 | 120 |
public class DefaultDataManager |
... | ... | |
405 | 404 |
LOGGER.warn(msg); |
406 | 405 |
throw new IllegalArgumentException(msg); |
407 | 406 |
} |
407 |
JsonObject parameters_json = null; |
|
408 | 408 |
DataFactory explorerFactory = this.getServerExplorerRegister().getFactory(explorerName); |
409 |
if( explorerFactory == null ) { |
|
410 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
|
411 |
LOGGER.warn(msg); |
|
412 |
throw new IllegalArgumentException(msg); |
|
409 |
if( explorerFactory == null ) { |
|
410 |
parameters_json = Json.createObject(explorerName); |
|
411 |
if( parameters_json==null || |
|
412 |
!parameters_json.containsKey(PROVIDER_PARAMTER_NAME) ) { |
|
413 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
|
414 |
LOGGER.warn(msg); |
|
415 |
throw new IllegalArgumentException(msg); |
|
416 |
} |
|
417 |
explorerName = parameters_json.getString(PROVIDER_PARAMTER_NAME); |
|
418 |
explorerFactory = this.getServerExplorerRegister().getFactory(explorerName); |
|
419 |
if( explorerFactory == null ) { |
|
420 |
String msg = "Can't locate server explorer factory for '"+explorerName+"'."; |
|
421 |
LOGGER.warn(msg); |
|
422 |
throw new IllegalArgumentException(msg); |
|
423 |
} |
|
413 | 424 |
} |
414 | 425 |
DataServerExplorerParameters params = (DataServerExplorerParameters) explorerFactory.createParameters(); |
426 |
if( parameters_json!=null ) { |
|
427 |
Json.addAll(params, parameters_json); |
|
428 |
} |
|
415 | 429 |
return params; |
416 | 430 |
} |
417 | 431 |
|
... | ... | |
551 | 565 |
DataStoreProvider provider = (DataStoreProvider) providerFactory.create(parameters, store); |
552 | 566 |
|
553 | 567 |
storeFactory.setProvider(store, provider); |
554 |
|
|
568 |
|
|
569 |
addObservers(store); |
|
570 |
if( store instanceof FeatureStoreProviderServices ) { |
|
571 |
((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
|
572 |
} |
|
573 |
return store; |
|
574 |
} |
|
575 |
|
|
576 |
public void addObservers(DataStore store){ |
|
555 | 577 |
for (Observer storeObserver : storeObservers) { |
556 | 578 |
if( storeObserver!=null) { |
557 | 579 |
store.addObserver(storeObserver); |
558 | 580 |
} |
559 | 581 |
} |
560 |
if( store instanceof FeatureStoreProviderServices ) { |
|
561 |
((FeatureStoreProviderServices) store).notifyChange(DataStoreNotification.AFTER_OPEN); |
|
562 |
} |
|
563 |
return store; |
|
564 | 582 |
} |
565 | 583 |
|
566 | 584 |
@Override |
... | ... | |
890 | 908 |
@Override |
891 | 909 |
public EditableFeatureType createFeatureType(JsonObject json) { |
892 | 910 |
EditableFeatureType featureType = this.createFeatureType(); |
893 |
featureType.setLabel((String) JsonUtils.getitem(json, "name")); |
|
894 |
JsonArray columns = json.getJsonArray("columns"); |
|
895 |
for (JsonValue item : columns ) { |
|
896 |
JsonObject jsonattr = (JsonObject) item; |
|
897 |
EditableFeatureAttributeDescriptor attr = featureType.add( |
|
898 |
jsonattr.getString("name"), |
|
899 |
jsonattr.getString("type") |
|
900 |
); |
|
901 |
for (String name : jsonattr.keySet()) { |
|
902 |
attr.set(name, JsonUtils.getitem(jsonattr, name)); |
|
903 |
} |
|
904 |
} |
|
911 |
featureType.fromJson(json); |
|
905 | 912 |
return featureType; |
906 | 913 |
} |
907 | 914 |
|
908 | 915 |
@Override |
909 | 916 |
public DataServerExplorerPool getDataServerExplorerPool() { |
910 | 917 |
if (this.dataServerExplorerPool == null) { |
911 |
this.dataServerExplorerPool = new DefaultDataServerExplorerPool();
|
|
918 |
this.dataServerExplorerPool = new DataServerExplorerPoolImpl();
|
|
912 | 919 |
} |
913 | 920 |
return this.dataServerExplorerPool; |
914 | 921 |
} |
Also available in: Unified diff