package org.w3c.tools.resources ;
import java.util.* ;
import java.io.* ;
import org.w3c.tools.resources.event.*;
public class ResourceFrame extends FramedResource
implements AttributeChangedListener
{
protected transient FrameEventListener frameListener = null;
protected FramedResource resource = null;
static {
Attribute a = null ;
Class cls = null ;
try {
cls = Class.forName("org.w3c.tools.resources.ResourceFrame") ;
} catch (Exception ex) {
ex.printStackTrace() ;
System.exit(1) ;
}
}
@return
public String getURLPath() {
return getString(ATTR_URL, getResource().getURLPath()) ;
}
@return
protected SpaceEntry getSpaceEntry() {
return null;
}
private ResourceReference self = null;
@return
public ResourceReference getFrameReference() {
if ((self == null) && (resource != null)) {
self = resource.getFrameReference(this);
}
return self;
}
public ResourceReference getResourceReference() {
return getFrameReference();
}
@param attrs
protected void updateDefaultChildAttributes(Hashtable attrs) {
}
@param request@return
public boolean checkRequest(RequestInterface request) {
return true;
}
public ReplyInterface perform(RequestInterface request)
throws ProtocolException, NotAProtocolException
{
return super.perform(request);
}
public boolean lookup(LookupState ls, LookupResult lr)
throws ProtocolException
{
ResourceFrame frames[] = getFrames();
if (frames != null) {
for (int i = 0 ; i < frames.length ; i++) {
if (frames[i] == null)
continue;
if (frames[i].lookup(ls,lr))
return true;
}
}
if ( ls.hasMoreComponents() ) {
lr.setTarget(null);
return false;
} else {
lr.setTarget(resource.getResourceReference());
return true;
}
}
public void processEvent(ResourceEvent evt) {
if (evt instanceof FrameEvent) {
fireFrameEvent((FrameEvent)evt);
} else if (evt instanceof AttributeChangedEvent) {
fireAttributeChangeEvent((AttributeChangedEvent)evt);
}
}
@param l
public void addFrameEventListener(FrameEventListener l) {
frameListener = ResourceEventMulticaster.add(frameListener, l);
}
@param l
public void removeFrameEventListener (FrameEventListener l) {
frameListener = ResourceEventMulticaster.remove(frameListener, l);
}
@param the
protected void postFrameEvent(int type) {
if (frameListener != null) {
FrameEvent evt = new FrameEvent(this, type);
postEvent(evt);
}
}
@param the
protected void fireFrameEvent(FrameEvent evt) {
if (frameListener != null) {
int type = evt.getID();
switch (type) {
case Events.FRAME_ADDED :
frameListener.frameAdded(evt);
break;
case Events.FRAME_MODIFIED :
frameListener.frameModified(evt);
break;
case Events.FRAME_REMOVED :
frameListener.frameRemoved(evt);
break;
}
}
}
public void attributeChanged(AttributeChangedEvent evt) {
displayEvent( this, evt );
setValue(ATTR_LAST_MODIFIED, new Long(System.currentTimeMillis()));
}
@param evt
public void frameModified(FrameEvent evt) {
displayEvent( this, evt );
markModified();
postFrameEvent(evt.getID());
}
@param idx@param value
public synchronized void setValue(int idx, Object value) {
super.setValue(idx,value);
if (idx != ATTR_LAST_MODIFIED)
postFrameEvent(Events.FRAME_MODIFIED);
}
@return
public FramedResource getResource() {
return resource;
}
public void registerResource(FramedResource resource) {
this.resource = resource;
postFrameEvent(Events.FRAME_ADDED);
setValue(ATTR_CONTEXT, resource.getContext());
}
public void unregisterResource(Resource resource) {
this.resource = null;
postFrameEvent(Events.FRAME_REMOVED);
}
}