package org.w3c.jigsaw.frames;
import org.w3c.tools.resources.*;
import org.w3c.jigsaw.http.* ;
import org.w3c.www.http.* ;
public class VirtualHostFrame extends HTTPFrame {
protected static int ATTR_FOLLOWUP = -1;
static {
Class c = null;
Attribute a = null;
try {
c = Class.forName("org.w3c.jigsaw.frames.VirtualHostFrame");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
a = new StringAttribute("followup"
, null
, Attribute.EDITABLE);
ATTR_FOLLOWUP = AttributeRegistry.registerAttribute(c, a);
}
protected ResourceReference followup = null;
@return
public String getFollowup() {
return getString(ATTR_FOLLOWUP, null);
}
public void registerResource(FramedResource resource) {
super.registerOtherResource(resource);
}
@return
public synchronized ResourceReference lookupFollowup() {
if ( followup == null ) {
String name = getFollowup();
if ( name != null )
followup = getServer().loadRoot(name);
if ( followup == null ) {
getServer().errlog(getIdentifier()
+ "[" + getClass().getName() + "]: "
+ "unable to restore \"" + name + "\" "
+ " from root store.");
}
}
return followup;
}
protected boolean lookupOther(LookupState ls, LookupResult lr)
throws ProtocolException
{
ResourceReference vrroot = null;
ContainerResource root = null;
root = (ContainerResource)getResource();
Request r = (Request)ls.getRequest();
if ( r != null ) {
String host = r.getHost();
if ( host != null ) {
vrroot = root.lookup(host.toLowerCase());
}
}
if ( vrroot == null )
vrroot = lookupFollowup();
if (vrroot == null)
return super.lookupOther(ls, lr);
try {
lr.setTarget(vrroot);
FramedResource resource = (FramedResource) vrroot.lock();
boolean done =
(resource != null ) ? resource.lookup(ls, lr) : false;
if (! done)
lr.setTarget(null);
return true;
} catch (InvalidResourceException ex) {
return false;
} finally {
vrroot.unlock();
}
}
}