00001 /*------------------------------------------------------------------------------ 00002 Name: QueuePropertyFactory.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Factory which creates objects holding queue properties 00006 Version: $Id: QueuePropertyFactory.cpp 16373 2007-07-19 19:10:21Z ruff $ 00007 ------------------------------------------------------------------------------*/ 00008 00009 #include <util/qos/storage/QueuePropertyFactory.h> 00010 #include <util/lexical_cast.h> 00011 #include <util/Global.h> 00012 00013 using namespace std; 00014 using namespace org::xmlBlaster::util; 00015 using namespace org::xmlBlaster::util::parser; 00016 using namespace org::xmlBlaster::util::qos::address; 00017 00018 00019 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace storage { 00020 00021 00022 QueuePropertyFactory::QueuePropertyFactory(Global& global) 00023 : XmlHandlerBase(global), ME("QueuePropertyFactory"), prop_(global, ""), addressFactory_(global) 00024 { 00025 RELATING = "relating"; 00026 inAddress_ = false; 00027 } 00028 00029 QueuePropertyFactory::~QueuePropertyFactory() 00030 { 00031 } 00032 00033 /* 00034 void QueuePropertyFactory::reset(QueuePropertyBase& prop) 00035 { 00036 prop_ = ∝ 00037 } 00038 */ 00039 00040 QueuePropertyBase QueuePropertyFactory::getQueueProperty() 00041 { 00042 return prop_; 00043 } 00044 00045 00049 void QueuePropertyFactory::startElement(const string &name, const AttributeMap& attrs) 00050 { 00051 //if (log_.call()) log_.call(ME, "startElement: " + getStartElementAsString(name, attrs)); 00052 00053 // in case it is inside or entering an 'address' or 'callbackAddress' 00054 if (name.compare("address") == 0) { 00055 inAddress_ = true; 00056 addressFactory_.reset(new Address(global_)); 00057 addressFactory_.startElement(name, attrs); 00058 return; 00059 } 00060 if (name.compare("callback") == 0) { 00061 inAddress_ = true; 00062 addressFactory_.reset(new CallbackAddress(global_)); 00063 addressFactory_.startElement(name, attrs); 00064 return; 00065 } 00066 if (inAddress_) { 00067 addressFactory_.startElement(name, attrs); 00068 return; 00069 } 00070 00071 // not inside any of the sub-elements (the root element) 00072 prop_ = QueuePropertyBase(global_, ""); 00073 //if (log_.trace()) log_.trace(ME, "queue properties are created"); 00074 00075 00076 string relating; 00077 if (getStringAttr(attrs, RELATING, relating)) { 00078 //if (log_.trace()) log_.trace(ME, "attribute 'relating' found. it is '" + relating + "'"); 00079 if (relating == "callback") prop_.initialize("callback"); 00080 else prop_.initialize(""); 00081 prop_.setRelating(relating); 00082 if (log_.trace()) log_.trace(ME, string("the queue is relating to ") + relating); 00083 } 00084 00085 AttributeMap::const_iterator iter = attrs.begin(); 00086 bool found = false; 00087 string tmpName = (*iter).first; 00088 string tmpValue = (*iter).second; 00089 00090 while (iter != attrs.end()) { 00091 00092 if (tmpName.compare("relating") == 0) { 00093 // do nothing since it is already done as the first thing 00094 // but leave it to avoid warnings 00095 found = true; 00096 } 00097 else if (tmpName.compare("maxEntries") == 0) { 00098 prop_.setMaxEntries(XmlHandlerBase::getLongValue(tmpValue)); 00099 } 00100 else if (tmpName.compare("type") == 0) { 00101 prop_.setType(tmpValue); 00102 } 00103 else if (tmpName.compare("version") == 0) { 00104 prop_.setVersion(tmpValue); 00105 } 00106 else if (tmpName.compare("maxEntriesCache") == 0) { 00107 prop_.setMaxEntriesCache(XmlHandlerBase::getLongValue(tmpValue)); 00108 } 00109 else if (tmpName.compare("maxBytes") == 0) { 00110 prop_.setMaxBytes(XmlHandlerBase::getLongValue(tmpValue)); 00111 } 00112 else if (tmpName.compare("maxBytesCache") == 0) { 00113 prop_.setMaxBytesCache(XmlHandlerBase::getLongValue(tmpValue)); 00114 } 00115 else if (tmpName.compare("storeSwapLevel") == 0) { 00116 prop_.setStoreSwapLevel(XmlHandlerBase::getLongValue(tmpValue)); 00117 } 00118 else if (tmpName.compare("storeSwapBytes") == 0) { 00119 prop_.setStoreSwapBytes(XmlHandlerBase::getLongValue(tmpValue)); 00120 } 00121 else if (tmpName.compare("reloadSwapLevel") == 0) { 00122 prop_.setReloadSwapLevel(XmlHandlerBase::getLongValue(tmpValue)); 00123 } 00124 else if (tmpName.compare("reloadSwapBytes") == 0) { 00125 prop_.setReloadSwapBytes(XmlHandlerBase::getLongValue(tmpValue)); 00126 } 00127 else if (tmpName.compare("expires") == 0) { 00128 prop_.setExpires(XmlHandlerBase::getTimestampValue(tmpValue)); 00129 } 00130 else if (tmpName.compare("onOverflow") == 0) { 00131 prop_.setOnOverflow(tmpValue); 00132 } 00133 else if (tmpName.compare("onFailure") == 0) { 00134 prop_.setOnFailure(tmpValue); 00135 } 00136 00137 else if (tmpName.compare("size") == 0) { 00138 // not doing anything (this is done outside: only in MsgQos Factory 00139 } 00140 else if (tmpName.compare("index") == 0) { 00141 // not doing anything (this is done outside: only in MsgQos Factory 00142 } 00143 else { 00144 log_.warn(ME, string("Ignoring unknown attribute '") + tmpName + 00145 string("' in connect QoS <queue>")); 00146 } 00147 iter++; 00148 } 00149 if (!found) { 00150 if (log_.trace()) log_.trace(ME, "Missing 'relating' attribute in connect QoS <queue>"); 00151 } 00152 } 00153 00154 00155 void QueuePropertyFactory::characters(const string &ch) 00156 { 00157 if (inAddress_) addressFactory_.characters(ch); 00158 } 00159 00161 void QueuePropertyFactory::endElement(const string &name) 00162 { 00163 // in case it is inside or entering an 'address' or 'callbackAddress' 00164 if (name.compare("address") == 0) { 00165 addressFactory_.endElement(name); 00166 prop_.addressArr_.insert((prop_.addressArr_).begin(), addressFactory_.getAddress()); 00167 inAddress_ = false; 00168 return; 00169 } 00170 if (name.compare("callback") == 0) { 00171 addressFactory_.endElement(name); 00172 prop_.addressArr_.insert((prop_.addressArr_).begin(), addressFactory_.getAddress()); 00173 inAddress_ = false; 00174 return; 00175 } 00176 if (inAddress_) { 00177 addressFactory_.endElement(name); 00178 return; 00179 } 00180 } 00181 00182 /* 00183 QueuePropertyBase& 00184 QueuePropertyFactory::readQueueProperty(const string& literal, QueuePropertyBase& prop) 00185 { 00186 reset(prop); 00187 init(literal); 00188 return getQueueProperty(); 00189 } 00190 */ 00191 00192 QueuePropertyBase QueuePropertyFactory::readObject(const string& literal) 00193 { 00194 init(literal); 00195 return prop_; 00196 } 00197 00198 }}}}} // namespaces 00199 00200 00201 #ifdef _XMLBLASTER_CLASSTEST 00202 00203 #include <util/qos/storage/ClientQueueProperty.h> 00204 00205 using namespace std; 00206 using namespace org::xmlBlaster::util::qos::storage; 00207 00209 int main(int args, char* argv[]) 00210 { 00211 try { 00212 Global& glob = Global::getInstance(); 00213 glob.initialize(args, argv); 00214 ClientQueueProperty prop(glob, ""); 00215 cout << prop.toXml() << endl; 00216 Address adr(glob, "EMAIL"); 00217 adr.setAddress("et@mars.sun"); 00218 prop.setAddress(adr); 00219 string literal = prop.toXml(); 00220 cout << literal << endl; 00221 00222 QueuePropertyFactory factory(glob); 00223 // ClientQueueProperty prop1(glob, ""); 00224 00225 QueuePropertyBase base= factory.readObject(literal); 00226 cout << "after reparsing the same object : " << endl; 00227 cout << base.toXml() << endl; 00228 } 00229 catch (...) { 00230 cout << "an exception occured in the main thread" << endl; 00231 } 00232 return 0; 00233 } 00234 00235 #endif