package org.aohe.transfer;


import org.aohe.core.twain.Twain;
import org.aohe.core.twain.TwainSource;
import org.aohe.exceptions.TwainException;
import org.aohe.exceptions.TwainUserCancelException;


public class TwainTransfer {

    protected TwainSource source;
    protected boolean isCancelled;

    public TwainTransfer(TwainSource source) {
        this.source = source;
        isCancelled = false;
    }

    public void initiate() throws TwainException {
        commitCancel();
    }

    public void setCancel(boolean isCancelled) {
        this.isCancelled = isCancelled;
    }

    protected void commitCancel() throws TwainException {
        if (isCancelled && (source.getState() == Twain.STATE_TRANSFERREADY)) {
            throw new TwainUserCancelException();
        }
    }

    public void finish() throws TwainException {
    }

    public void cancel() throws TwainException {
    }

    public void cleanup() throws TwainException {
    }
}
