001/*
002 * #%L
003 * Netarchivesuite - archive
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University 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.arcrepository.distribute;
024
025import java.io.File;
026
027import dk.netarkivet.archive.distribute.ArchiveMessage;
028import dk.netarkivet.archive.distribute.ArchiveMessageVisitor;
029import dk.netarkivet.common.distribute.ChannelID;
030import dk.netarkivet.common.distribute.Channels;
031import dk.netarkivet.common.distribute.RemoteFile;
032import dk.netarkivet.common.distribute.RemoteFileFactory;
033import dk.netarkivet.common.exceptions.ArgumentNotValid;
034
035/**
036 * Messages requesting store of file. This message is sent to the arc repository which distributes the file to the known
037 * bitarchives, and checks the result, and then responds to the sender.
038 */
039@SuppressWarnings({"serial"})
040public class StoreMessage extends ArchiveMessage {
041    /** The actual data. */
042    private RemoteFile theRemoteFile;
043
044    /**
045     * Construct StoreMessage.
046     *
047     * @param replyTo Channel to reply back to
048     * @param arcfile The file to store
049     */
050    public StoreMessage(ChannelID replyTo, File arcfile) {
051        super(Channels.getTheRepos(), replyTo);
052        ArgumentNotValid.checkNotNull(arcfile, "arcfile");
053        theRemoteFile = RemoteFileFactory.getDistributefileInstance(arcfile);
054    }
055
056    /**
057     * Retrieve name of the stored file.
058     *
059     * @return current value of arcfileName
060     */
061    public String getArcfileName() {
062        return theRemoteFile.getName();
063    }
064
065    /**
066     * Get method for field theRemoteFile.
067     *
068     * @return Current value of theRemoteFile
069     */
070    public RemoteFile getRemoteFile() {
071        return theRemoteFile;
072    }
073
074    /**
075     * Should be implemented as a part of the visitor pattern. fx.: public void accept(ArchiveMessageVisitor v) {
076     * v.visit(this); }
077     *
078     * @param v A message visitor
079     */
080    public void accept(ArchiveMessageVisitor v) {
081        v.visit(this);
082    }
083
084    /**
085     * Generate String representation of this object.
086     *
087     * @return String representation of this object
088     */
089    public String toString() {
090        return super.toString() + " Arcfile: " + getArcfileName();
091    }
092
093}