XercesXMLSerialize.h

Go to the documentation of this file.
00001 /*
00002  * License Agreement
00003  * 
00004  * NOTICE
00005  * This software (or technical data) was produced for the U. S.
00006  * Government under contract W15P7T-05-C-F600, and is
00007  * subject to the Rights in Data-General Clause 52.227-14 (JUNE 1987)
00008  * 
00009  * Copyright (C) 2006. The MITRE Corporation (http://www.mitre.org/).
00010  * All Rights Reserved.
00011  * 
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions
00014  * are met:
00015  * 
00016  * * Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  * 
00019  * * Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  * 
00023  * * The US Government will not be charged any license fee and/or
00024  * royalties related to this software.
00025  * 
00026  * * Neither name of The MITRE Corporation; nor the names of its
00027  * contributors may be used to endorse or promote products derived from
00028  * this software without specific prior written permission.
00029  * 
00030  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00031  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00032  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00033  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
00034  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00035  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00036  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00037  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00038  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00039  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00040  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041  */
00042 
00043 #ifndef _OASYS_XERCES_XML_SERIALIZE_H_
00044 #define _OASYS_XERCES_XML_SERIALIZE_H_
00045 
00046 #include <config.h>
00047 #ifdef XERCES_C_ENABLED
00048 
00049 #include "XMLSerialize.h"
00050 #include <xercesc/dom/DOM.hpp>
00051 #include <xercesc/dom/DOMBuilder.hpp>
00052 #include <xercesc/framework/XMLGrammarPool.hpp>
00053 
00054 namespace oasys {
00055 
00056 class Mutex;
00057 
00072 class XercesXMLUnmarshal : public XMLUnmarshal,
00073                            public Logger {
00074 public:
00075     XercesXMLUnmarshal(bool validation, const char *schema=0);
00076     virtual ~XercesXMLUnmarshal();
00077 
00084     virtual const char *parse(const char *xml_doc = 0);
00085 
00086     // Virtual functions inherited from SerializeAction
00087     virtual void process(const char *name, SerializableObject* object);
00088     virtual void process(const char *name, u_int64_t *i);
00089     virtual void process(const char *name, u_int32_t *i);
00090     virtual void process(const char *name, u_int16_t *i);
00091     virtual void process(const char *name, u_int8_t *i);
00092     virtual void process(const char *name, bool *b);
00093     virtual void process(const char *name, u_char *bp,
00094                          u_int32_t len);
00095     virtual void process(const char* name, u_char** bp,
00096                          u_int32_t* lenp, int flags);
00097     virtual void process(const char *name, std::string *s);
00098 
00099 protected:
00104     virtual const char *next_elem();
00105 
00106     char *root_tag_str;
00107     xercesc::XMLGrammarPool *pool_;
00108     xercesc::DOMImplementation *impl_;
00109     xercesc::DOMBuilder *parser_;
00110     xercesc::DOMDocument *doc_;
00111     xercesc::DOMElement *root_elem_;
00112     xercesc::DOMTreeWalker *walker_;
00113 
00114     // avoid race conditions involving multiple simultaneous
00115     // constructions of XercesXMLUnmarshal
00116     static oasys::Mutex* lock_;
00117 };
00118 
00122 class ValidationError : public xercesc::DOMErrorHandler {
00123 public:
00124     ValidationError()
00125         : set_(false), severity_(-1), message_(0)
00126     {
00127     }
00128 
00129     virtual ~ValidationError()
00130     {
00131         delete [] message_;
00132     }
00133 
00137     virtual bool handleError(const xercesc::DOMError& domError);
00138 
00139     bool is_set()
00140     {
00141         return set_;
00142     }
00143 
00144     short get_severity()
00145     {
00146         return severity_;
00147     }
00148 
00149     const char * message()
00150     {
00151         return message_;
00152     }
00153 
00154 private:
00155     bool set_;
00156     short severity_;
00157     char *message_;
00158 };
00159 
00160 } // namespace oasys
00161 
00162 #endif // XERCES_C_ENABLED
00163 #endif //_OASYS_XERCES_XML_SERIALIZE_H_

Generated on Sat Sep 8 08:43:36 2007 for DTN Reference Implementation by  doxygen 1.5.3