/**
 *
 * Copyright 2004 Hiram Chirino
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.activeio;

import java.io.IOException;


/**
 * A SynchChannelFilter can be used as a filter another {@see org.activeio.SynchChannel}
 * Most {@see org.activeio.SynchChannel} that are not directly accessing the network will 
 * extends the SynchChannelFilter since they act as a filter between the client and the network.
 *    
 * @version $Revision$
 */
public class FilterSynchChannel implements SynchChannel {

    private final SynchChannel next;

    public FilterSynchChannel(SynchChannel next) {
        this.next = next;
    }

    /**
     * @see org.activeio.Channel#write(org.activeio.channel.Packet)
     */
    public void write(Packet packet) throws IOException {
        next.write(packet);
    }

    /**
     * @see org.activeio.Channel#flush()
     */
    public void flush() throws IOException {
        next.flush();
    }

    /**
     * @see org.activeio.Disposable#dispose()
     */
    public void dispose() {
        next.dispose();
    }

    /**
     * @see org.activeio.Service#start()
     */
    public void start() throws IOException {
        next.start();
    }

    /**
     * @see org.activeio.Service#stop(long)
     */
    public void stop(long timeout) throws IOException {
        next.stop(timeout);
    }

    /**
     * @return Returns the next.
     */
    public SynchChannel getNext() {
        return next;
    }

    /**
     * @see org.activeio.SynchChannel#read(long)
     */
    public Packet read(long timeout) throws IOException {
        return next.read(timeout);
    }
    
    public Object narrow(Class target) {
        if( target.isAssignableFrom(getClass()) ) {
            return this;
        }
        return next.narrow(target);
    }    
    
    public String toString() {
        return next.toString();
    }
}