SOAPParser.h

Go to the documentation of this file.
00001 
00010 // SOAPParser.h: interface for the SOAPParser class.
00011 // Description: This class takes an unparsed XML document
00012 //    and parses it up into it's constituent nodes, attributes, and 
00013 //    values.  It does some things that are specific to SOAP,
00014 //    but for the most part it could probably parse up any XML doc.
00015 //
00017 /*
00018 #if !defined(SOAPPARSER_H)
00019     #include "SOAPParser.h"
00020 #endif // !defined(SOAPPARSER_H)
00021 */
00022 #if !defined(SOAPPARSER_H)
00023 #define SOAPPARSER_H
00024 
00025 #ifndef _STRING_
00026     #include <string>
00027 #endif // _STRING_
00028 
00029 #ifndef _MAP_
00030     #include <map>
00031 #endif // _MAP_
00032     
00033 #if !defined(SOAPFAULT_H)
00034     #include "SOAPFault.h"
00035 #endif // !defined(SOAPFAULT_H)
00036 
00037 class SOAPElement;
00038 
00039 class SOAPParser  
00040 {
00041 public:
00042     // Constructor/ Destructor
00043     SOAPParser();
00044     virtual ~SOAPParser();
00045     
00046     // Maps a namespace identifier to a URN.
00047     typedef std::map<std::string, std::string> XMLNStoURN;
00048     
00049     // parseMessage
00050     // Description:
00051     //  Given a SOAP string, parses it into new elements and 
00052     //  deposits them into the root SOAPElement passed in via
00053     //  soapMessage.
00054     // Arugments:
00055     //  szMessage: The message to parse.
00056     //  soapMessage: The root SOAPElement to fill in.
00057     // Return Value:
00058     //  true: Successful parse.
00059     //  false: Unsuccessful parse.
00060     virtual bool parseMessage( const std::string& szMessage, 
00061         SOAPElement& soapMessage );
00062     
00063     // getNamespacesInUse
00064     // Description:
00065     //  Returns the names and URNs of any and all namespaces found
00066     //  when parsing the message.  If duplicate namespace names are
00067     //  used with different URNs, only the last one found will 
00068     //  appear in the set of return values.
00069     // Arugments:
00070     //  N/A
00071     // Return Value:
00072     //  Returns a reference to the internal namespace to URN mapping.
00073     XMLNStoURN& getNamespacesInUse();
00074     
00075     // getFault
00076     // Description:
00077     //  If the call fails, this returns the fault the call generated.
00078     //  The actaul SOAPFault won't be created unless setFailed() is
00079     //  called.
00080     // Arugments:
00081     //  N/A
00082     // Return Value:
00083     //  Pointer to the fault if it exists.
00084     SOAPFault* getFault();
00085 
00086 protected:
00087     
00088     // parseMessage
00089     // Description:
00090     //  Recursive version of the public interface.  The caller 
00091     //  doesn't need to know that we pass the current position 
00092     //  within the message string as we parse, but it doesn't
00093     //  hurt that the object knows about this.
00094     // Arugments:
00095     //  szMesage: Message to parse.
00096     //  soapElement: Root element to fill in (might be one of the
00097     //  original's sub-elements).
00098     //  nCurrentPos: Current position within szMessage.
00099     // Return Value:
00100     //  true: Successful parse.
00101     //  false: Unsuccessful parse.
00102     virtual bool parseMessage( const std::string& szMessage, 
00103         SOAPElement& soapElement, long& nCurrentPos );
00104     
00105     // setFailed
00106     // Description:
00107     //  Sets the status of the SOAP call to failed and triggers
00108     //  the creation of the SOAPFault.
00109     // Arugments:
00110     //  N/A
00111     // Return Value:
00112     //  N/A
00113     void setFailed();
00114     
00115     // extractQuotedString
00116     // Description:
00117     //  At a given position within a string, find the string with
00118     //  the matching quote types.
00119     // Arugments:
00120     //  szString: String to find a "quoted string" within,
00121     //  nPos: Position to start at on entrance.  Position after last
00122     //  quote on exit.
00123     // Return Value:
00124     //  String minus the quotes used to surround the quoted string.
00125     std::string extractQuotedString( const std::string& szString, 
00126         long& nPos );
00127     
00128     // splitNSAndAccessor
00129     // Description:
00130     //  Given a "full string" splits the namespace from the rest of 
00131     //  the string.
00132     // Arugments:
00133     //  szFullString: String with namespace and accessor.
00134     //  szNamespace: On return, has the namespace name filled in 
00135     //      (if present).
00136     //  szOther: On return contains the name of the accessor.
00137     // Return Value:
00138     //  N/A
00139     void splitNSAndAccessor( std::string szFullString, 
00140         std::string& szNamespace, std::string& szOther );
00141     
00142     // extractValue  
00143     // Description:
00144     //  Extracts the first value it finds in szMessage starting
00145     //  at nCurrentPos and puts it into theElement.  This stops
00146     //  processing when it hits a "<".
00147     // Arugments:
00148     //  theElement: The element to put the value into.
00149     //  szMessage: The message to parse.
00150     //  nCurrentPos: The message to start extracting the value at.
00151     // Return Value:
00152     //  true: Extracted the value successfully.
00153     //  false: Failed to extract the value.
00154     bool extractValue( SOAPElement& theElement, 
00155         const std::string& szMessage, long& nCurrentPos );
00156     
00157     // extractAttributes
00158     // Description:
00159     //  Given an XML start tag, extracts any attributes and their 
00160     //  values.  Remove any namespace declarations before calling
00161     //  this method.
00162     // Arugments:
00163     //  theElement: The element to add the attributes to.
00164     //  szBeginTag: The tag to parse.
00165     // Return Value:
00166     //  true: Extracted the attributes successfully.
00167     //  false: Failed to extract the attributes.
00168     bool extractAttributes( SOAPElement& theElement, 
00169         std::string szBeginTag );
00170     
00171     // extractNamespaces
00172     // Description:
00173     //  Extracts any and all namespace names.  Puts the namespace
00174     //  namesand their associated URNs into the internal namespace
00175     //  to URN map.
00176     // Arugments:
00177     //  szCompleteAccessor: A begin tag.  On return, all namespace
00178     //      declarations are removed.
00179     // Return Value:
00180     //  true: Extracted the namespaces successfully.
00181     //  false: Failed to extract the namespaces.
00182     bool extractNamespaces( std::string& szCompleteAccessor );
00183     
00184     // extractBeginTag
00185     // Description:
00186     //  Extracts the "begin tag".  If the tag is really an end tag,
00187     //  it indicates this via bIsEndTag.  This also returns the
00188     //  namespace declared with the element.
00189     // Arugments:
00190     //  szBeginTag: On entrance, contains nothing.  On exit, contains
00191     //      the begin tag.
00192     //  szNamespace: Contains the namespace of the accessor on exit.
00193     //      If no namespace is used, this is an empty string.
00194     //  szAccessorName: Contains the name of the accessor on exit.
00195     //  szMessage: Contains the message to dig through.
00196     //  nCurrentPos: On entrance, contains the position to start
00197     //      parsing.  On exit, contains the spot where the tag
00198     //      closed.
00199     //  bIsEmptyTag: Indicates if the tag is a begin AND an end tag.
00200     //      Ex.:  <anEmptyTag value="myData" />
00201     //  bIsEndTag: Indicates if the current tag is an end tag.  
00202     //      Ex.: </anEndTag>
00203     // Return Value:
00204     //  true: Extracted the required information successfully.
00205     //  false: Failed to extract the required information.
00206     bool extractBeginTag(
00207         std::string& szBeginTag, 
00208         std::string& szNamespace, 
00209         std::string& szAccessorName, 
00210         std::string szMessage, 
00211         long &nCurrentPos, 
00212         bool &bIsEmptyTag, 
00213         bool &bIsEndTag);
00214     
00215     // Data members
00216     
00217     // m_namespaceMap
00218     // Description: Contains the map of namespace name to URN. 
00219     XMLNStoURN m_namespaceMap;
00220     
00221     // m_pFault
00222     // Description: Stores a pointer to the fault data (if any).
00223     std::auto_ptr<SOAPFault> m_pFault;
00224 };
00225 
00226 #endif // !defined(SOAPPARSER_H)

Generated on Tue Mar 28 09:10:15 2006 for Simple SOAP by  doxygen 1.4.6