00001 #include "TransferCommand.h"
00002 #include "Sct/LogicErrors.h"
00003 #include "Sct/IoExceptions.h"
00004 #include "Sct/IOName.h"
00005 #include "Archiver.h"
00006
00007 using namespace boost;
00008
00009 namespace SctArchiving{
00010
00011 TransferCommand::TransferCommand(boost::shared_ptr<GetCommand> get,
00012 boost::shared_ptr<PutCommand> put)
00013 : m_get(get), m_put(put)
00014 {}
00015
00016 TransferCommand::~TransferCommand() {}
00017
00018 TransferCommand::TransferCommand() {}
00019
00020 void TransferCommand::execute(){
00021 if ( m_get->getIOName().wildcard() ) {
00022
00023
00024 for (Sct::IOName::const_iterator i = m_get->getIOName().begin();
00025 i!=m_get->getIOName().end(); ++i){
00026
00027 shared_ptr<TransferCommand> newcmd = dynamic_pointer_cast<TransferCommand> (create());
00028 if (!newcmd.get()) throw Sct::IllegalStateError("Bad cast", __FILE__, __LINE__);
00029 newcmd = dynamic_pointer_cast<TransferCommand> (this->create());
00030 newcmd->m_get->setName(*i);
00031
00032 Archiver::instance().addCommand(newcmd);
00033 }
00034 }else{
00035
00036
00037
00038
00039 m_get->execute();
00040 shared_ptr<Sct::Serializable> ob = m_get->getObject();
00041 if (!ob.get()) {
00042 string message = "Get was unsuccessful : ";
00043 message+=m_get->getIOName().getIOName();
00044 throw Sct::IoException(message, __FILE__, __LINE__);
00045 }
00046
00047
00048 m_put->set(ob);
00049 m_put->execute();
00050 }
00051 }
00052
00053 shared_ptr<ArchivingCommand> TransferCommand::create() const {
00054 shared_ptr<GetCommand> newget = dynamic_pointer_cast<GetCommand>(m_get->create());
00055 shared_ptr<PutCommand> newput = dynamic_pointer_cast<PutCommand>(m_put->create());
00056 newput->setParams(m_put->getParams());
00057 return shared_ptr<TransferCommand>(new TransferCommand(newget, newput));
00058 }
00059
00060 }