}
public void replace( ID id, IService replacement ) throws UnsupportedOperationException {
if (replacement == null || replacement.getIdentifier() == null || id == null) {
throw new NullPointerException("Cannot have a null id"); //$NON-NLS-1$
}
final IService service = getServiceById(id);
List<IResolveDelta> changes = new ArrayList<IResolveDelta>();
List<IResolveDelta> childChanges = new ArrayList<IResolveDelta>();
try {
List< ? extends IGeoResource> newChildren = replacement.resources(null);
List< ? extends IGeoResource> oldChildren = service.resources(null);
if (oldChildren != null)
for( IGeoResource oldChild : oldChildren ) {
String oldName = oldChild.getIdentifier().toString();
for( IGeoResource child : newChildren ) {
String name = child.getIdentifier().toString();
if (oldName.equals(name)) {
childChanges.add(new ResolveDelta(child, oldChild,
IResolveDelta.NO_CHILDREN));
break;
}
}
}
} catch (IOException ignore) {
// no children? Not a very good entry ..
}
changes.add(new ResolveDelta(service, replacement, childChanges));
IResolveDelta deltas = new ResolveDelta(this, changes);
IResolveChangeEvent event = new ResolveChangeEvent(this,
IResolveChangeEvent.Type.PRE_DELETE, deltas);
fire(event);
services.remove(service);
runInterceptor(service, ServiceInterceptor.REMOVED_ID);
PlatformGIS.run(new IRunnableWithProgress(){
public void run( IProgressMonitor monitor ) throws InvocationTargetException,
InterruptedException {
try {
service.dispose(monitor);
} catch (Throwable e) {
CatalogPlugin.log("error disposing of: " + service.getIdentifier(), e); //$NON-NLS-1$
}
}
});
services.add(replacement);
runInterceptor(replacement, ServiceInterceptor.ADDED_ID);
event = new ResolveChangeEvent(this, IResolveChangeEvent.Type.POST_CHANGE, deltas);
if (!id.equals(replacement.getIdentifier())) {
// the service has actually moved
IService moved = new MovedService(id, replacement.getID());
services.add(moved);
runInterceptor(moved, ServiceInterceptor.ADDED_ID);
}
fire(event);
}