{
Object result;
if (name.isEmpty())
{
// Return this
result = new NamingContext(null, (Name)(prefix.clone()), getRoot());
} else if (name.size() > 1)
{
// Recurse to find correct context
// System.out.println("lookup#"+name+"#");
Object ctx = getObject(name);
if (ctx instanceof NamingServer)
{
result = ((NamingServer)ctx).lookup(name.getSuffix(1));
} else if (ctx instanceof Reference)
{
// Federation
if (((Reference)ctx).get("nns") != null)
{
CannotProceedException cpe = new CannotProceedException();
cpe.setResolvedObj(ctx);
cpe.setRemainingName(name.getSuffix(1));
throw cpe;
}
result = new ResolveResult(ctx, name.getSuffix(1));
} else
{
throw new NotContextException();
}
} else
{
// Get object to return
if (name.get(0).equals(""))
{
result = new NamingContext(null, prefix, getRoot());
} else
{
// System.out.println("lookup "+name);
Object res = getObject(name);
if (res instanceof NamingServer)
{
Name fullName = (Name)(prefix.clone());
fullName.addAll(name);
result = new NamingContext(null, fullName, getRoot());
}
else
result = res;
}
}