001/*
002 * #%L
003 * Netarchivesuite - archive
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish Library, 
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.archive.bitarchive.distribute;
024
025import dk.netarkivet.archive.distribute.ArchiveMessage;
026import dk.netarkivet.archive.distribute.ArchiveMessageVisitor;
027import dk.netarkivet.common.distribute.ChannelID;
028import dk.netarkivet.common.distribute.RemoteFile;
029import dk.netarkivet.common.exceptions.ArgumentNotValid;
030
031/**
032 * Container for upload request.
033 */
034@SuppressWarnings({"serial"})
035public class UploadMessage extends ArchiveMessage {
036    /** the name of the file to upload. */
037    private String arcfileName;
038
039    /** The actual data. */
040    private RemoteFile theRemoteFile;
041
042    /** precomputed checksum  */
043    private String precomputedChecksum;
044    
045    /**
046     * Construct UploadMessage.
047     *
048     * @param to Channel to message to
049     * @param replyTo Channel to reply back to
050     * @param rf The RemoteFile to upload
051     */
052    public UploadMessage(ChannelID to, ChannelID replyTo, RemoteFile rf) {
053        super(to, replyTo);
054        ArgumentNotValid.checkNotNull(rf, "rf");
055        arcfileName = rf.getName();
056        theRemoteFile = rf;
057    }
058
059    /**
060     * Retrieve name of the uploaded file.
061     *
062     * @return current value of arcfileName
063     */
064    public String getArcfileName() {
065        return arcfileName;
066    }
067
068    /**
069     * Get method for field theRemoteFile.
070     *
071     * @return Current value of theRemoteFile
072     */
073    public RemoteFile getRemoteFile() {
074        return theRemoteFile;
075    }
076
077    /**
078     * Should be implemented as a part of the visitor pattern. fx.: public void accept(ArchiveMessageVisitor v) {
079     * v.visit(this); }
080     *
081     * @param v A message visitor
082     */
083    public void accept(ArchiveMessageVisitor v) {
084        v.visit(this);
085    }
086
087    /**
088     * Generate String representation of this object.
089     *
090     * @return String representation of this object
091     */
092    public String toString() {
093        return super.toString() + " Arcfile: " + arcfileName;
094    }
095
096        public void setPrecomputedChecksum(String precomputedChecksum) {
097                this.precomputedChecksum = precomputedChecksum;
098        }
099        
100        public String getPrecomputedChecksum() {
101                return this.precomputedChecksum;
102        }
103
104}