package de.dtele.net.protocol {
  
  import de.dtele.net.MediaRequest;
  import de.dtele.net.MediaRequestError;
  import de.dtele.net.events.ProtocolHandlerErrorEvent;
  
  import flash.events.EventDispatcher;
  
  /**
   * Fallback protocol handler for unknown protocols, only triggers errors
   * 
   * @author Mathias Brodala
   */
  public class UnknownProtocolHandler extends EventDispatcher implements IProtocolHandler {
    
    /**
     * Connects this handler to a source
     * 
     * @param url The url of a source
     */
    public function connect(url:String):void {
      
      this.dispatchEvent(new ProtocolHandlerErrorEvent(
        ProtocolHandlerErrorEvent.ERROR,
        new MediaRequestError(MediaRequestError.UNKNOWN_PROTOCOL)
      ));
    }
    
    /**
     * Disconnects this handler from a source
     */
    public function disconnect():void {
      
      this.dispatchEvent(new ProtocolHandlerErrorEvent(
        ProtocolHandlerErrorEvent.ERROR,
        new MediaRequestError(MediaRequestError.UNKNOWN_PROTOCOL)
      ));
    }
    
    /**
     * Performs a request to a source
     * 
     * @param request The request to submit
     */
    public function send(request:MediaRequest):void {
      
      this.dispatchEvent(new ProtocolHandlerErrorEvent(
        ProtocolHandlerErrorEvent.ERROR,
        new MediaRequestError(MediaRequestError.UNKNOWN_PROTOCOL),
        request
      ));
    }
  }
}