Annotation of java/classes/org/w3c/tools/resources/ResourceFrame.java, revision 1.7

1.1       bmahe       1: // ResourceFrame.java
1.7     ! bmahe       2: // $Id: ResourceFrame.java,v 1.6 1998/02/13 15:53:03 bmahe Exp $
1.1       bmahe       3: // (c) COPYRIGHT MIT and INRIA, 1996.
                      4: // Please first read the full copyright statement in file COPYRIGHT.html
                      5: 
                      6: package org.w3c.tools.resources ;
                      7: 
                      8: import java.util.* ;
                      9: import java.io.* ;
                     10: 
                     11: import org.w3c.tools.resources.event.*;
                     12: 
                     13: /**
                     14:  * The resource frame class. A ResourceFrame can be attached to a
                     15:  * resource.
                     16:  */
                     17: public class ResourceFrame extends FramedResource 
                     18:                            implements AttributeChangedListener
                     19: {
                     20: 
                     21:   /**
                     22:    * Our FrameEventListener.
                     23:    */
                     24:   protected transient FrameEventListener frameListener = null;
                     25: 
                     26:   /**
                     27:    * Our target resource.
                     28:    */
                     29:   protected FramedResource resource = null;
                     30: 
                     31:   static {
                     32:     Attribute a   = null ;
                     33:     Class     cls = null ;
                     34:     // Get a pointer to our own class:
                     35:     try {
                     36:       cls  = Class.forName("org.w3c.tools.resources.ResourceFrame") ;
                     37:     } catch (Exception ex) {
                     38:       ex.printStackTrace() ;
                     39:       System.exit(1) ;
                     40:     }
                     41:   }
1.6       bmahe      42: 
                     43:   /**
                     44:    * Get the file part of the URL this resource is attached to.
                     45:    * @return An URL object specifying the location in the information 
                     46:    *    space of this resource.
                     47:    */
                     48:   public String getURLPath() {
                     49:     return getString(ATTR_URL, getResource().getURLPath()) ;
                     50:   }
                     51: 
1.1       bmahe      52:   /**
                     53:    * Get the space entry for that resource. This Object is use to
                     54:    * retrieve the resource in the resource space.
                     55:    * A ResourceFrame has no SpaceEntry.
                     56:    * @return always null.
                     57:    */
                     58:   protected SpaceEntry getSpaceEntry() {
                     59:     return null;
                     60:   }
                     61: 
1.4       bmahe      62:   private ResourceReference self = null;
                     63:   /**
                     64:    * Get The FrameReference of this frame, or <strong>null</strong>
                     65:    * if this frame is not registered.
                     66:    * @return A ResourceReference instance.
                     67:    */
                     68:   public ResourceReference getFrameReference() {
                     69:     if ((self == null) &&  (resource != null)) {
                     70:       self = resource.getFrameReference(this);
                     71:     }
                     72:     return self;
                     73:   }
                     74:   
                     75: 
1.1       bmahe      76:   /**
                     77:    * If our target resource has some children, we could have
                     78:    * some attribute to give to them.
                     79:    * @param attrs A Hashtable.
                     80:    */
                     81:   protected void updateDefaultChildAttributes(Hashtable attrs) {
                     82:     //nothing here
                     83:   }
                     84: 
1.2       bmahe      85:   /**
                     86:    * Check if this kind of request can be perform by this resource.
                     87:    * @param request A RequestInterface instance
                     88:    * @return a boolean.
                     89:    */
1.1       bmahe      90:   public boolean checkRequest(RequestInterface request) {
                     91:     return true;
                     92:   }
                     93: 
                     94:   /**
                     95:    * FIXME doc
                     96:    */ 
                     97:   public ReplyInterface perform(RequestInterface request) 
1.3       bmahe      98:     throws ProtocolException, NotAProtocolException
1.1       bmahe      99:   {
                    100:     return super.perform(request);
                    101:   }
                    102: 
                    103:   /**
                    104:    * FIXME doc
                    105:    */ 
                    106:   public boolean lookup(LookupState ls, LookupResult lr) 
                    107:     throws ProtocolException
                    108:   {
                    109:     //FIXME does a frame can have frames other than filters?
                    110:     //exclude filters?
                    111:     ResourceFrame frames[] = getFrames();
                    112:     if (frames != null) {
                    113:       for (int i = 0 ; i < frames.length ; i++) {
                    114:        if (frames[i] == null)
                    115:          continue;
                    116:        if (frames[i].lookup(ls,lr))
                    117:          return true;
                    118:       }
                    119:     }
                    120:     //
                    121:     // FIXME unuseful.
                    122:     //
                    123:     if ( ls.hasMoreComponents() ) {
                    124:       // We are not a container resource, and we don't have children:
                    125:       lr.setTarget(null);
                    126:       return false;
                    127:     } else {
                    128:       // We are done !
                    129:       //    org.w3c.util.Trace.showTrace("lookup done : "+
                    130:       //                      this+", "+resource.getResourceReference());
                    131:       lr.setTarget(resource.getResourceReference());
                    132:       return true;
                    133:     }
                    134:   }
                    135: 
                    136:   public void processEvent(ResourceEvent evt) {
                    137:     if (evt instanceof FrameEvent) {
                    138:       fireFrameEvent((FrameEvent)evt);
                    139:     }
                    140:   }
                    141: 
                    142:   /**
                    143:    * Add a frame event listener.
                    144:    * @param l The new frame event listener.
                    145:    */
                    146: 
                    147:   public void addFrameEventListener(FrameEventListener l) {
                    148:     frameListener = ResourceEventMulticaster.add(frameListener, l);
                    149:   }
                    150: 
                    151:   /**
                    152:    * Remove a frame event listener.
                    153:    * @param l The listener to remove.
                    154:    */
                    155:     
                    156:   public void removeFrameEventListener (FrameEventListener l) {
                    157:     frameListener = ResourceEventMulticaster.remove(frameListener, l);
                    158:   }
                    159: 
                    160:   /**
                    161:    * Post a frameEvent.
                    162:    * @param the frame event type.
                    163:    */
                    164:   protected void postFrameEvent(int type) {
                    165:     if (frameListener != null) {
                    166:       FrameEvent evt = new FrameEvent(this, type);
                    167:       postEvent(evt);
                    168:     }
                    169:   }
                    170: 
                    171:   /**
                    172:    * Fire a frameEvent.
                    173:    * @param the frame event type.
                    174:    */
                    175:   protected void fireFrameEvent(FrameEvent evt) {
                    176:     if (frameListener != null) {
                    177:       int type = evt.getID();
                    178:       switch (type) {
                    179:       case Events.FRAME_ADDED :
                    180:        frameListener.frameAdded(evt);
                    181:        break;
                    182:       case Events.FRAME_MODIFIED :
                    183:        frameListener.frameModified(evt);
                    184:        break;
                    185:       case Events.FRAME_REMOVED :
                    186:        frameListener.frameRemoved(evt);
                    187:        break;
                    188:       }
                    189:     }
                    190:   }
                    191: 
                    192:   /**
                    193:    * Listen its resource.
                    194:    */
                    195:   public void attributeChanged(AttributeChangedEvent evt) {
                    196:     displayEvent( this, evt );
                    197:     setValue(ATTR_LAST_MODIFIED, new Long(System.currentTimeMillis()));
1.5       bmahe     198:     
                    199:   }
                    200: 
                    201:   /**
                    202:    * This handles the <code>FRAME_MODIFIED</code> kind of events.
                    203:    * @param evt The event describing the change.
                    204:    */
                    205:   
                    206:   public void frameModified(FrameEvent evt) {
                    207:     displayEvent( this, evt );
                    208:     markModified();
                    209:     postFrameEvent(evt.getID());
1.1       bmahe     210:   }
                    211: 
                    212:   /**
                    213:    * We overide setValue, to fire event.
                    214:    * @param idx The index of the attribute to modify.
                    215:    * @param value The new attribute value.
                    216:    */
                    217:   public synchronized void setValue(int idx, Object value) {
                    218:     super.setValue(idx,value);
                    219:     if (idx != ATTR_LAST_MODIFIED)
                    220:       postFrameEvent(Events.FRAME_MODIFIED); 
                    221:   }
                    222: 
                    223:   /**
                    224:    * Get the target resource.
                    225:    * @return a resource instance.
                    226:    */
1.4       bmahe     227:   public FramedResource getResource() {
1.1       bmahe     228:     return resource;
                    229:   }
                    230: 
                    231:   /**
1.7     ! bmahe     232:    * Register a target resource. Called after initialize,
        !           233:    * set the context. getServer() can be call only after
        !           234:    * this method call.
1.1       bmahe     235:    * @parame resource The resource to register.
                    236:    */ 
                    237:   public void registerResource(FramedResource resource) {
                    238:     this.resource = resource;
                    239:     postFrameEvent(Events.FRAME_ADDED);
                    240:     setValue(ATTR_CONTEXT, resource.getContext());
                    241:   }
                    242: 
                    243:   /**
                    244:    * Register a target resource.
                    245:    * @parame resource The resource to register.
                    246:    */ 
                    247:   public void unregisterResource(Resource resource) {
                    248:     //FIXME (can we have more than one resource? )
                    249:     this.resource = null;
                    250:     postFrameEvent(Events.FRAME_REMOVED);
                    251:   }
                    252: 
                    253: }

Webmaster