[udig-devel] Datastores & co
Andrea Antonello
andrea.antonello at gmail.com
Thu Jan 17 01:16:06 PST 2008
On Wed, 16 Jan 2008 10:15:32 -0800 Jody Garnett
<jgarnett at refractions.net> probably wrote:
> Andrea Antonello wrote:
> > But I found a UDIGFeatureStore that didn't resolve to DataStore.
> > I mean, I can get a DataStore out of it, but I always have to do
> > the check.
> > Is that right?
> Nope that would be a mistake; lets fix it :-)
> > Am I forced to see if what I got is a UDIGFeatureStore or a
> > DataStore?
> You should get back what you ask for .. UDIGFeatureStore is not a
> DataStore so I am confused by your sentence?
> > I have not my example by hand right now, but if I wasn't clear, I
> > will post a better example :)
> Sure lets go through an example together; we could even start up a
> file in the example code plugin and stop guessing.
Alright, good idea, so let's start with this and build/modify it:
1) get a datastore from the catalog:
ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
ArrayList<IResolve> neededCatalogMembers = null;
try {
List< ? extends IResolve> allCatalogMembers =
catalog.members(null);
neededCatalogMembers = new ArrayList<IResolve>();
for( IResolve catalogMember : allCatalogMembers ) {
if (catalogMember.canResolve(DataStore.class)) {
neededCatalogMembers.add(catalogMember);
itemsMap.put(new
File(catalogMember.getIdentifier().getPath()).getName(),
catalogMember.resolve(DataStore.class, null)); }
}
} catch (IOException e) {
e.printStackTrace();
}
which works like a charm.
2) try to get the same thing from a udig layer (assuming the ILayers
were put into the itemsMap):
ILayer tmpLayer = itemsMap.get(name);
if (tmpLayer != null) {
try {
FeatureStore tmpStore =
tmpLayer.getResource(FeatureStore.class, null); if (tmpStore != null)
selectedLayers.add(tmpStore);
} catch (IOException e) {
e.printStackTrace();
}
}
Here I have to use FeatureStore, because with DataStore it would return
null.
In fact, UDIGFeatureStore implements FeatureStore, but not DataStore,
so they do not resolve to the same. To get the DataStore out of the
UDIGFeatureStore I need to go through:
DataStore dS = null;
if (tmp instanceof DataStore) {
dS = tmp
} else if (tmp instanceof UDIGFeatureStore) {
dS = ((UDIGFeatureStore) tmp).getDataStore()
}
Well, I pass the ball to you.
Andrea
> Jody
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
More information about the udig-devel
mailing list