try {
ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
// first search the local catalog.
List<IResolve> matches = catalog.find(url, new SubProgressMonitor(progressMonitor, 2));
for (IResolve resolve : matches) {
if (resolve instanceof ExpectedService) {
// found the resource now we have to search it for the
// resource we want
if (searchServiceForResource(new SubProgressMonitor(progressMonitor, 2), addPosition, map,
(IService) resolve))
return;
} else if (resolve instanceof ExpectedGeoResource) {
// yay we found the resource this is too easy:)
ApplicationGIS.addLayersToMap(map, Collections.singletonList((IGeoResource) resolve), addPosition);
return;
}
}
// usually only returns 1 service but it may be that multiple
// Services know how to interpret the URL
List<IService> services = CatalogPlugin.getDefault().getServiceFactory().createService(url);
IService found = null;
progressMonitor.worked(1);
// find the service you want
for (IService service : services) {
// determine if the service is the type you are expecting;
if (service instanceof ExpectedService) {
found = service;
break;
}
}
catalog.add(found);
searchServiceForResource(new SubProgressMonitor(progressMonitor, 2), addPosition, map, found);
} finally {
progressMonitor.done();
}