package connection.peer;
import handlers.AbstractContextualHandler;
import handlers.sets.GenericPeerHandlerSet;
import java.io.IOException;
import transfer.upload.FileUploadConnection;
import chat.connection.AbstractChatConnection;
import chat.connection.ServerSideChatConnection;
import common.connection.AbstractCommunicationSet;
import common.files.SerializableFile;
import common.handlers.AbstractHandlerSet;
import connection.AbstractContextualConnection;
public class GenericPeerConnection extends AbstractContextualConnection
{
private static final GenericPeerHandlerSet HANDLER_SET = new GenericPeerHandlerSet();
public GenericPeerConnection(AbstractCommunicationSet source) throws IOException
{
super(source);
}
public void initializeConnection() throws IOException
{
}
public void finalizeConnection()
{
}
protected AbstractHandlerSet getHandlerSet()
{
return HANDLER_SET;
}
public AbstractContextualHandler getContextualHandler(int protocolId, int opcode)
throws IOException, ClassNotFoundException
{
return GenericPeerHandlerSet.HANDLERS[protocolId][opcode].createContext(this, is);
}
public FileUploadConnection convertToFileUpload(SerializableFile file)
throws IOException
{
FileUploadConnection newConnection = new FileUploadConnection(this, file);
convertTo(newConnection);
return newConnection;
}
public AbstractChatConnection convertToPrivateChat() throws IOException
{
AbstractChatConnection newConnection = new ServerSideChatConnection(this);
convertTo(newConnection);
return newConnection;
}
}