@Override
public Object lookup(Name name, Credence credence) throws NamingException,
RemoteException {
Object result = null;
if(name.isEmpty()) {
result = new NamingContext(null, (Name)(Name)this.prefix.clone(), getRoot());
} else {
if(name.size() > 1) {
Object ctx = getObject(name, credence);
if(ctx instanceof NamingServer) {
result = ((NamingServer)ctx).lookup(name.getSuffix(1), credence);
} else if(ctx instanceof Reference) {
result = new ResolveResult(ctx, name.getSuffix(1));
} else {
throw new NotContextException();
}
} else {
if (name.get(0).equals("")) {
result = new NamingContext(null, (Name)(Name)this.prefix.clone(), getRoot());
} else {
Object res = getObject(name, credence);
if (res instanceof NamingServer) {
Name fullName = (Name)(Name)this.prefix.clone();
fullName.addAll(name);
result = new NamingContext(null, fullName, getRoot());
} else {
result = res;
}
}
}