00001 #include "IsGetCommand.h"
00002 #include "Archiver.h"
00003 #include "SerializableWrappers.h"
00004 #include "Sct/IS/IOManagerIS.h"
00005 #include "Sct/IoExceptions.h"
00006
00007 #include "is/isinfoany.h"
00008 #include <boost/timer.hpp>
00009
00010 namespace SctArchiving{
00011 IsGetCommand::IsGetCommand(boost::shared_ptr<Sct::IS::IONameIS> name)
00012 : GetCommand(name)
00013 {}
00014
00015 IsGetCommand::IsGetCommand() {}
00016
00017 IsGetCommand::~IsGetCommand(){}
00018
00019 void IsGetCommand::execute(){
00020 boost::timer t;
00021 if (m_name->getIOName().find("SctData")==std::string::npos) {
00022
00023 m_ob = retrieveISOB( m_name->getIOName() );
00024 }else{
00025
00026 m_ob = Sct::IS::IOManagerIS::instance().read(m_name->getIOName());
00027 }
00028
00029 Archiver::instance().addISTime(t.elapsed());
00030 }
00031
00032 boost::shared_ptr<ArchivingCommand> IsGetCommand::create()const{
00033 boost::shared_ptr<ArchivingCommand> cmd(new IsGetCommand() );
00034 return cmd;
00035 }
00036
00038 shared_ptr<Sct::Serializable> IsGetCommand::retrieveISOB(const std::string& name) const {
00039 ISInfoAny infoany;
00040 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), infoany);
00041 if (result != ISInfo::Success) {
00042 std::ostringstream oss;
00043 oss << "Error reading from IS server. Couldn't get: "
00044 << name << " expected class TestData";
00045 throw Sct::IsException(result, oss.str(), __FILE__, __LINE__);
00046 }
00047 const std::string& classname=infoany.type().name();
00048
00049 if (classname == "TestData") {
00050 shared_ptr<TestData> td ( new TestData() );
00051 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), *td);
00052 if (result != ISInfo::Success) {
00053 std::ostringstream oss;
00054 oss << "Error reading from IS server. Couldn't get: "
00055 << name << " expected class TestData";
00056 throw IsException(result, oss.str(), __FILE__, __LINE__);
00057 }
00058 return shared_ptr<Sct::Serializable> ( new Sct::ISSerializableWrapper<TestData>(td) );
00059 } else if (classname == "SequenceData"){
00060 shared_ptr<SequenceData> td ( new SequenceData() );
00061 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), *td);
00062 if (result != ISInfo::Success) {
00063 std::ostringstream oss;
00064 oss << "Error reading from IS server. Couldn't get: "
00065 << name << " expected class SequenceData";
00066 throw Sct::IsException(result, oss.str(), __FILE__, __LINE__);
00067 }
00068 return shared_ptr<Sct::Serializable> ( new Sct::ISSerializableWrapper<SequenceData>(td) );
00069 } else {
00070 throw Sct::InvalidArgumentError(string("I don't know how to retrieve ") + name, __FILE__, __LINE__);
00071 }
00072 }
00073
00074 }