ulxr_responseparse.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002             ulxr_responseparse.cpp  -  parse xml-rpc method response
00003                              -------------------
00004     begin                : Wed Mar 13 2002
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_responseparse.cpp 940 2006-12-30 18:22:05Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 //#define ULXR_SHOW_TRACE
00031 //#define ULXR_DEBUG_OUTPUT
00032 
00033 #define ULXR_NEED_EXPORTS
00034 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00035 
00036 #include <ulxmlrpcpp/ulxr_responseparse.h>
00037 #include <ulxmlrpcpp/ulxr_except.h>
00038 
00039 
00040 namespace ulxr {
00041 
00042 
00043 ULXR_API_IMPL(void)
00044   MethodResponseParser::startElement(const XML_Char* name, const XML_Char** atts)
00045 {
00046   if (!testStartElement(name, atts))
00047     ValueParser::testStartElement(name, atts);
00048 }
00049 
00050 
00051 ULXR_API_IMPL(bool)
00052   MethodResponseParser::testStartElement(const XML_Char* name, const XML_Char** /*atts*/)
00053 {
00054   ULXR_TRACE(ULXR_PCHAR("MethodResponseParser::testStartElement(const XML_Char*, const char**)")
00055              << ULXR_PCHAR("\n  name: ")
00056              << ULXR_GET_STRING(name)
00057             );
00058 
00059   switch(states.top()->getParserState() )
00060   {
00061     case eNone:
00062       if(strcmp(name, "methodResponse") == 0)
00063       {
00064         setComplete (false);
00065         states.push(new ValueState(eMethodResponse));
00066       }
00067       else
00068         return false;
00069     break;
00070 
00071     case eMethodResponse:
00072       if(strcmp(name, "fault") == 0)
00073         states.push(new ValueState(eFault));
00074 
00075       else if(strcmp(name, "params") == 0)
00076         states.push(new ValueState(eParams));
00077 
00078       else
00079         return false;
00080     break;
00081 
00082     case eFault:
00083       if(strcmp(name, "value") == 0)
00084         states.push(new ValueState(eValue));
00085       else
00086         return false;
00087     break;
00088 
00089     case eParams:
00090       if(strcmp(name, "param") == 0)
00091         states.push(new ValueState(eParam));
00092       else
00093         return false;
00094     break;
00095 
00096     case eParam:
00097       if(strcmp(name, "value") == 0)
00098         states.push(new ValueState(eValue));
00099       else
00100         return false;
00101     break;
00102 
00103     default:
00104         return false;
00105   }
00106 
00107   return true;
00108 }
00109 
00110 
00111 ULXR_API_IMPL(void) MethodResponseParser::endElement(const XML_Char *name)
00112 {
00113   if (!testEndElement(name))
00114     ValueParser::testEndElement(name);
00115 }
00116 
00117 
00118 ULXR_API_IMPL(bool) MethodResponseParser::testEndElement(const XML_Char *name)
00119 {
00120   ULXR_TRACE(ULXR_PCHAR("MethodResponseParser::testEndElement(const XML_Char*)"));
00121 
00122   if (states.size() <= 1)
00123     throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("abnormal program behaviour: MethodResponseParser::testEndElement() had no states left")));
00124 
00125   ValueState *curr = getTopValueState();
00126   states.pop();
00127   ValueState *on_top = getTopValueState();
00128 
00129   switch(curr->getParserState() )
00130   {
00131     case eMethodResponse:
00132       setComplete(true);
00133       assertEndElement(name, "methodResponse");
00134       on_top->takeValue (curr->getValue());
00135       if (on_top->getValue() != 0)
00136         method_value = *on_top->getValue();
00137     break;
00138 
00139     case eFault:
00140       assertEndElement(name, "fault");
00141       on_top->takeValue (curr->getValue());
00142     break;
00143 
00144     case eParams:
00145       assertEndElement(name, "params");
00146       on_top->takeValue (curr->getValue());
00147     break;
00148 
00149     case eParam:
00150       assertEndElement(name, "param");
00151       on_top->takeValue (curr->getValue());
00152     break;
00153 
00154     default:
00155       states.push(curr);   // put back, someone else will process
00156       return false;
00157   }
00158 
00159   delete curr;
00160   return true;
00161 }
00162 
00163 
00164 }  // namespace ulxr

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1