00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef SEMAINE_CMS_RECEIVER_FEATURERECEIVER_H
00011 #define SEMAINE_CMS_RECEIVER_FEATURERECEIVER_H
00012
00013 #include <semaine/config.h>
00014
00015 #include <cms/CMSException.h>
00016
00017 #include <semaine/cms/receiver/Receiver.h>
00018 #include <semaine/cms/exceptions/MessageFormatException.h>
00019 #include <semaine/cms/message/SEMAINEFeatureMessage.h>
00020
00021
00022 using namespace cms;
00023 using namespace semaine::cms::message;
00024
00025 namespace semaine {
00026 namespace cms {
00027 namespace receiver {
00028
00034 class FeatureReceiver : public Receiver
00035 {
00036 public:
00048 FeatureReceiver(const std::string & topicName) throw(CMSException) :
00049 Receiver(topicName)
00050 {}
00051
00066 FeatureReceiver(const std::string & topicName, const std::string & messageSelector)
00067 throw(CMSException) :
00068 Receiver(topicName, messageSelector)
00069 {}
00070
00079 FeatureReceiver(const std::string & cmsUrl, const std::string & cmsUser, const std::string & cmsPassword,
00080 const std::string & topicName)
00081 throw (CMSException) :
00082 Receiver(cmsUrl, cmsUser, cmsPassword, topicName)
00083 {}
00084
00096 FeatureReceiver(const std::string & cmsUrl, const std::string & cmsUser, const std::string & cmsPassword,
00097 const std::string & topicName, const std::string & messageSelector)
00098 throw (CMSException) :
00099 Receiver(cmsUrl, cmsUser, cmsPassword, topicName, messageSelector)
00100 {}
00101
00102
00103 protected:
00104 virtual SEMAINEMessage * createSEMAINEMessage(const Message * message)
00105 throw(semaine::cms::exceptions::MessageFormatException)
00106 {
00107 SEMAINEFeatureMessage * fm = new SEMAINEFeatureMessage(message);
00108 try {
00109 if (featureNames.empty() && fm->hasFeatureNames()) {
00110 featureNames = fm->getFeatureNames();
00111 } else if (!featureNames.empty() && !fm->hasFeatureNames()) {
00112 fm->setFeatureNames(featureNames);
00113 }
00114 } catch (CMSException & e) {
00115 std::stringstream buf;
00116 buf << "Problem accessing feature names: ";
00117 e.printStackTrace(buf);
00118 throw semaine::cms::exceptions::MessageFormatException(buf.str());
00119 }
00120 return fm;
00121 }
00122
00123
00124 private:
00125 std::vector<std::string> featureNames;
00126 };
00127
00128 }
00129 }
00130 }
00131
00132
00133 #endif
00134