@Override
public synchronized Repository getRepository()
throws RepositoryStubException {
if (repository == null) {
try {
RemoteAdapterFactory raf = new ServerAdapterFactory();
remote = raf.getRemoteRepository(super.getRepository());
// Make sure that the remote reference survives serialization
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(buffer);
oos.writeObject(RemoteObject.toStub(remote));