00001 /*------------------------------------------------------------------------------ 00002 Name: TopicProperty.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 ------------------------------------------------------------------------------*/ 00006 00022 #include <util/qos/TopicProperty.h> 00023 00024 #include <util/Constants.h> 00025 #include <util/Global.h> 00026 #include <util/lexical_cast.h> 00027 00028 00029 00030 using namespace org::xmlBlaster::util; 00031 using namespace org::xmlBlaster::util::qos::storage; 00032 00033 using namespace std; 00034 00035 namespace org { namespace xmlBlaster { namespace util { namespace qos { 00036 00037 // TODO: Change to use glob instead of Global singleton! What about performance? Put variable into Global? 00047 const long destroyDelay_DEFAULT_DEFAULT = 60*1000L; 00049 const bool DEFAULT_readonly = false; 00050 00051 00052 void TopicProperty::copy(const TopicProperty& prop) 00053 { 00054 msgUnitStoreProperty_ = NULL; 00055 historyQueueProperty_ = NULL; 00056 if (prop.msgUnitStoreProperty_) 00057 msgUnitStoreProperty_ = new MsgUnitStoreProperty(*prop.msgUnitStoreProperty_); 00058 if (prop.historyQueueProperty_) 00059 historyQueueProperty_ = new HistoryQueueProperty(*prop.historyQueueProperty_); 00060 00061 destroyDelay_DEFAULT = prop.destroyDelay_DEFAULT; 00062 destroyDelay_ = prop.destroyDelay_; 00063 readonly_ = prop.readonly_; 00064 } 00065 00066 00067 00068 TopicProperty::TopicProperty(Global& global) 00069 : ME("TopicProperty"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), 00070 createDomEntry_(Prop<bool>(true)) 00071 { 00072 msgUnitStoreProperty_ = NULL; 00073 historyQueueProperty_= NULL; 00074 destroyDelay_DEFAULT = global_.getProperty().getLongProperty("topic.destroyDelay", destroyDelay_DEFAULT_DEFAULT); 00075 00076 setDestroyDelay(destroyDelay_DEFAULT); 00077 destroyDelay_ = destroyDelay_DEFAULT; 00078 readonly_ = DEFAULT_readonly; 00079 } 00080 00081 TopicProperty::TopicProperty(const TopicProperty& prop) 00082 : ME(prop.ME), global_(prop.global_), log_(prop.log_), 00083 createDomEntry_(prop.createDomEntry_) 00084 { 00085 copy(prop); 00086 } 00087 00088 TopicProperty& TopicProperty::operator =(const TopicProperty& prop) 00089 { 00090 createDomEntry_ = prop.createDomEntry_; 00091 copy(prop); 00092 return *this; 00093 } 00094 00095 TopicProperty::~TopicProperty() 00096 { 00097 delete msgUnitStoreProperty_; 00098 delete historyQueueProperty_; 00099 } 00100 00104 void TopicProperty::setReadonly(bool readonly) 00105 { 00106 readonly_ = readonly; 00107 } 00108 00112 bool TopicProperty::isReadonly() 00113 { 00114 return readonly_; 00115 } 00116 00120 long TopicProperty::getDestroyDelay() 00121 { 00122 return destroyDelay_; 00123 } 00124 00128 void TopicProperty::setDestroyDelay(long destroyDelay) 00129 { 00130 destroyDelay_ = destroyDelay; 00131 } 00132 00138 bool TopicProperty::createDomEntry() const 00139 { 00140 return createDomEntry_.getValue(); 00141 } 00142 00148 void TopicProperty::setCreateDomEntry(bool createDomEntry) { 00149 createDomEntry_.setValue(createDomEntry); 00150 } 00151 00152 bool TopicProperty::hasMsgUnitStoreProperty() 00153 { 00154 return (msgUnitStoreProperty_ != NULL); 00155 } 00156 00160 MsgUnitStoreProperty TopicProperty::getMsgUnitStoreProperty() 00161 { 00162 if (msgUnitStoreProperty_ == NULL) { 00163 msgUnitStoreProperty_ = new MsgUnitStoreProperty(global_, /*global_.getId()*/ ""); 00164 } 00165 return *msgUnitStoreProperty_; 00166 } 00167 00168 void TopicProperty::setMsgUnitStoreProperty(const MsgUnitStoreProperty& msgUnitStoreProperty) 00169 { 00170 if (msgUnitStoreProperty_) { 00171 delete msgUnitStoreProperty_; 00172 msgUnitStoreProperty_ = NULL; 00173 } 00174 msgUnitStoreProperty_ = new MsgUnitStoreProperty(msgUnitStoreProperty); 00175 } 00176 00177 bool TopicProperty::hasHistoryQueueProperty() 00178 { 00179 return (historyQueueProperty_ != NULL); 00180 } 00181 00185 HistoryQueueProperty TopicProperty::getHistoryQueueProperty() 00186 { 00187 if (historyQueueProperty_ == NULL) { 00188 historyQueueProperty_ = new HistoryQueueProperty(global_, /*global_.getId()*/ ""); 00189 } 00190 return *historyQueueProperty_; 00191 } 00192 00193 void TopicProperty::setHistoryQueueProperty(const HistoryQueueProperty& historyQueueProperty) 00194 { 00195 if (historyQueueProperty_) { 00196 delete historyQueueProperty_; 00197 historyQueueProperty_ = NULL; 00198 } 00199 historyQueueProperty_ = new HistoryQueueProperty(historyQueueProperty); 00200 } 00201 00202 string TopicProperty::toXml(const string& extraOffset) 00203 { 00204 string ret; 00205 string offset = Constants::OFFSET + extraOffset; 00206 00207 ret += offset + "<topic"; 00208 if (DEFAULT_readonly != readonly_) { 00209 ret += " readonly='" + lexical_cast<std::string>(readonly_) + "'"; 00210 } 00211 if (destroyDelay_DEFAULT_DEFAULT != destroyDelay_) { 00212 ret += " destroyDelay='" + lexical_cast<std::string>(destroyDelay_) + "'"; 00213 } 00214 ret += ">"; 00215 //string subscriptionId; 00216 00217 if (hasMsgUnitStoreProperty()) { 00218 ret += getMsgUnitStoreProperty().toXml(extraOffset+Constants::INDENT); 00219 } 00220 if (hasHistoryQueueProperty()) { 00221 ret += getHistoryQueueProperty().toXml(extraOffset+Constants::INDENT); 00222 } 00223 ret += offset + "</topic>"; 00224 00225 if (ret.length() < 22) { 00226 return ""; 00227 } 00228 00229 return ret; 00230 } 00231 00232 }}}}