include/Action.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: Action.H 543 2006-03-07 12:31:53Z cesar $ */
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     to_parse["msg"] = _response->get_result_msg();
00110     to_parse["code"] = 
00111       StrUtil::to_string("%d", (int) _response->get_result_code());
00112     
00113     _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$");
00114   }
00115 
00116 private:
00117   Action();
00118 
00119 };
00120 
00121 LIBEPP_NICBR_NS_END
00122 #endif //__ACTION_H__

Generated on Wed Mar 22 14:18:26 2006 for libepp_nicbr by  doxygen 1.4.6