ulxr_responseparse_wb.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002             ulxr_responseparse_wb.cpp  -  parse wbxml-rpc method response
00003                              -------------------
00004     begin                : Fri Jan 09 2004
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_responseparse_wb.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_wb.h>
00037 #include <ulxmlrpcpp/ulxr_except.h>
00038 #include <ulxmlrpcpp/ulxr_htmlform_handler.h>
00039 
00040 
00041 namespace ulxr {
00042 
00043 
00044 ULXR_API_IMPL(void)
00045   MethodResponseParserWb::startElement(unsigned token, const Attributes &attr)
00046 {
00047   if (!testStartElement(token, attr))
00048     ValueParserWb::testStartElement(token, attr);
00049 }
00050 
00051 
00052 ULXR_API_IMPL(bool)
00053   MethodResponseParserWb::testStartElement(unsigned token, const Attributes &)
00054 {
00055   ULXR_TRACE(ULXR_PCHAR("MethodResponseParserWb::testStartElement()")
00056              << ULXR_PCHAR("\n  token: ")+HtmlFormHandler::makeHexNumber(token)
00057             );
00058 
00059   switch(states.top()->getParserState() )
00060   {
00061     case eNone:
00062       if(wbToken_MethodResponse == token)
00063       {
00064         setComplete (false);
00065         states.push(new ValueState(eMethodResponse));
00066       }
00067       else
00068         return false;
00069     break;
00070 
00071     case eMethodResponse:
00072       if(wbToken_Fault == token)
00073         states.push(new ValueState(eFault));
00074 
00075       else if(wbToken_Params == token)
00076         states.push(new ValueState(eParams));
00077 
00078       else
00079         return false;
00080     break;
00081 
00082     case eFault:
00083       if(wbToken_Value == token)
00084         states.push(new ValueState(eValue));
00085       else
00086         return false;
00087     break;
00088 
00089     case eParams:
00090       if(wbToken_Param == token)
00091         states.push(new ValueState(eParam));
00092       else
00093         return false;
00094     break;
00095 
00096     case eParam:
00097       if(wbToken_Value == token)
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) MethodResponseParserWb::endElement()
00112 {
00113   if (!testEndElement())
00114     ValueParserWb::testEndElement();
00115 }
00116 
00117 
00118 ULXR_API_IMPL(bool) MethodResponseParserWb::testEndElement()
00119 {
00120   ULXR_TRACE(ULXR_PCHAR("MethodResponseParserWb::testEndElement()"));
00121 
00122   if (states.size() <= 1)
00123     throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("abnormal program behaviour: MethodResponseParserWb::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       on_top->takeValue (curr->getValue());
00134       if (on_top->getValue() != 0)
00135         method_value = *on_top->getValue();
00136     break;
00137 
00138     case eFault:
00139     case eParams:
00140     case eParam:
00141       on_top->takeValue (curr->getValue());
00142     break;
00143 
00144     default:
00145       states.push(curr);   // put back, someone else will process
00146       return false;
00147   }
00148 
00149   delete curr;
00150   return true;
00151 }
00152 
00153 
00154 }  // namespace ulxr

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