include/Action.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: Action.H 720 2006-05-06 21:40:46Z koji $ */
00007 #ifndef __ACTION_H__
00008 #define __ACTION_H__
00009 
00010 #include <string>
00011 
00012 #include "libepp_nicbr.H"
00013 
00014 #include "Response.H"
00015 #include "Command.H"
00016 #include "DomParser.H"
00017 #include "CommonData.H"
00018 
00019 using std::string;
00020 
00021 LIBEPP_NICBR_NS_BEGIN
00022 
00024 class Action
00025 {
00026 public:
00028   virtual ~Action() {}  
00029   
00030 
00032 
00035   virtual void set_xml_template(const string &xml_template) = 0;
00036 
00038 
00041   string get_xml() { return _xml; }
00042 
00044 
00047   ActionType who_am_i() { return _type; }
00048 
00050 
00054   virtual void set_response(const string &xml_payload, DomParser *parser) = 0;
00055 
00057 
00060   Response* get_response()
00061   {
00062     return _response.get(); 
00063   }
00064   
00066 
00069   Command* get_command()
00070   {
00071     return _command.get(); 
00072   }
00073 
00074 protected:
00076   auto_ptr<Command> _command;
00077   
00079   auto_ptr<Response> _response;
00080   
00082   ActionType _type;
00083 
00085   string _xml;
00086 
00088 
00091   Action(const ActionType &type) : _type(type) {}
00092 
00094 
00097   void set_xml_template_common(const string &xml_template)
00098   {
00099     string clTRID = _command->get_clTRID();
00100     map < string, string, less<string> > to_parse;
00101     if (clTRID != "") {
00102       to_parse["clTRID"] = "<clTRID>" + clTRID + "</clTRID>";
00103     } else {
00104       to_parse["clTRID"] = "";
00105     }
00106     
00107     // Response specific attributes
00108     to_parse["svTRID"] = _response->get_svTRID();
00109 
00110     string lang = "";
00111     if (_response->get_result_lang() != "en") {
00112       lang = " lang=\"" + _response->get_result_lang() + "\"";
00113     }
00114 
00115     map <Response::ResultCode, Response::ResultInfo> results;
00116     map <Response::ResultCode, Response::ResultInfo>::const_iterator it;
00117     list<Response::ResultExtValue>::const_iterator ev_it;
00118     results = _response->get_result_list();
00119     to_parse["result"] = "";
00120     for (it = results.begin(); it != results.end(); it++) {
00121       to_parse["result"] += "<result code=\"" + 
00122         StrUtil::to_string("%d", (int)it->first) + "\">" +
00123         "<msg" + lang + ">" + it->second.msg + "</msg>";
00124       for (ev_it = it->second.ext_values.begin();
00125            ev_it != it->second.ext_values.end(); ev_it++) {
00126         if (ev_it->reason == "") {
00127           to_parse["result"] += "<value " + ev_it->xmlns + ">" +
00128             ev_it->value + "</value>";
00129         } else {
00130           to_parse["result"] += "<extValue><value " + ev_it->xmlns+ ">" +
00131             ev_it->value + "</value><reason" + lang + ">" + ev_it->reason +
00132             "</reason></extValue>";
00133         }
00134       }
00135       to_parse["result"] += "</result>";
00136     }
00137     
00138     _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$");
00139   }
00140 
00141 private:
00142   Action();
00143 
00144 };
00145 
00146 LIBEPP_NICBR_NS_END
00147 #endif //__ACTION_H__

Generated on Thu Jun 8 17:40:00 2006 for libepp_nicbr by  doxygen 1.4.6