peiyongz    2003/10/29 08:16:08

  Modified:    c/src/xercesc/internal XMLGrammarPoolImpl.cpp
                        XMLGrammarPoolImpl.hpp XSerializable.hpp
                        XTemplateSerializer.cpp XTemplateSerializer.hpp
  Log:
  GrammarPool' serialization/deserialization support
  
  Revision  Changes    Path
  1.8       +157 -1    xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.cpp
  
  Index: XMLGrammarPoolImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLGrammarPoolImpl.cpp    10 Oct 2003 18:36:41 -0000      1.7
  +++ XMLGrammarPoolImpl.cpp    29 Oct 2003 16:16:08 -0000      1.8
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.8  2003/10/29 16:16:08  peiyongz
  + * GrammarPool' serialization/deserialization support
  + *
    * Revision 1.7  2003/10/10 18:36:41  neilg
    * update XMLGrammarPool default implementation to reflect recent modifications to 
the base interface.
    *
  @@ -88,11 +91,15 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include <xercesc/internal/XMLGrammarPoolImpl.hpp>
  +#include <xercesc/internal/XSerializeEngine.hpp>
  +#include <xercesc/internal/XTemplateSerializer.hpp>
   #include <xercesc/validators/DTD/DTDGrammar.hpp>
   #include <xercesc/validators/DTD/XMLDTDDescriptionImpl.hpp>
   #include <xercesc/validators/schema/SchemaGrammar.hpp>
   #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
   
  +#include <xercesc/util/SynchronizedStringPool.hpp>
  +
   XERCES_CPP_NAMESPACE_BEGIN
   
   // ---------------------------------------------------------------------------
  @@ -219,5 +226,154 @@
           return fSynchronizedStringPool;
       return fStringPool;
   }
  +
  +// -----------------------------------------------------------------------
  +// serialization and deserialization support
  +// -----------------------------------------------------------------------
  +/***
  + *
  + * don't serialize
  + *
  + *   XMLSynchronizedStringPool*  fSynchronizedStringPool;
  + *   bool                        fLocked;
  + */
  +
  +/***
  + *   .not locked
  + *   .non-empty gramamrRegistry
  + ***/
  +void XMLGrammarPoolImpl::serializeGrammars(BinOutputStream* const binOut)
  +{
  +    if (fLocked)
  +    {
  +        ThrowXML(XSerializationException, XMLExcepts::XSer_GrammarPool_Locked);
  +    }
  +
  +    fLocked = true;
  +    RefHashTableOfEnumerator<Grammar> grammarEnum(fGrammarRegistry);
  +    if (!(grammarEnum.hasMoreElements())) 
  +    {
  +        fLocked = false;
  +        ThrowXML(XSerializationException, XMLExcepts::XSer_GrammarPool_Empty);
  +    }
  +
  +    try 
  +    {
  +        XSerializeEngine  serEng(binOut, getMemoryManager());
  +
  +        //version information
  +        serEng<<gXercesMajVersion;
  +        serEng<<gXercesMinVersion;
  +        serEng<<gXercesRevision;
  +
  +        //StringPool, don't use <<
  +        fStringPool->serialize(serEng);
  +
  +        /***
  +         * Serialize RefHashTableOf<Grammar>*    fGrammarRegistry; 
  +         ***/
  +        XTemplateSerializer::storeObject(fGrammarRegistry, serEng);
  +          
  +    }
  +    catch(...)
  +    {
  +        fLocked = false;
  +        throw;
  +    }
  +
  +    fLocked = false;
  +}
  +
  +/***
  + *   .not locked
  + *   .empty stringPool
  + *   .empty gramamrRegistry
  + ***/
  +void XMLGrammarPoolImpl::deserializeGrammars(BinInputStream* const binIn)
  +{
  +    if (fLocked)
  +    {
  +        ThrowXML(XSerializationException, XMLExcepts::XSer_GrammarPool_Locked);
  +    }
  +
  +    fLocked = true;
  +    unsigned int stringCount = fStringPool->getStringCount();
  +    if (stringCount)
  +    {
  +        /***
  +         * it contains only the four predefined one, that is ok
  +         * but we need to reset the string before deserialize it
  +         *
  +         ***/
  +        if ( stringCount <= 4 )
  +        {
  +            fStringPool->flushAll();
  +        }
  +        else
  +        {
  +            fLocked = false;
  +            ThrowXML(XSerializationException, XMLExcepts::XSer_StringPool_NotEmpty);
  +        }
  +    }
  +
  +    RefHashTableOfEnumerator<Grammar> grammarEnum(fGrammarRegistry);
  +    if (grammarEnum.hasMoreElements()) 
  +    {
  +        fLocked = false;
  +        ThrowXML(XSerializationException, XMLExcepts::XSer_GrammarPool_NotEmpty);
  +    }
  +
  +    try 
  +    {
  +        XSerializeEngine  serEng(binIn, getMemoryManager());
  +
  +        //version information
  +        unsigned int  MajVer;
  +        unsigned int  MinVer;
  +        unsigned int  Revision;
  +
  +        serEng>>MajVer;
  +        serEng>>MinVer;
  +        serEng>>Revision;
  +
  +        //we may change the logic once we have more
  +        //versions
  +        if ((MajVer   != gXercesMajVersion) ||
  +            (MinVer   != gXercesMinVersion) ||
  +            (Revision != gXercesRevision)     )
  +        {
  +            fLocked = false;
  +            XMLCh     MajVerChar[4];
  +            XMLCh     MinVerChar[4];
  +            XMLCh     RevisionChar[4];
  +            XMLString::binToText(MajVer,   MajVerChar,   4, 10);
  +            XMLString::binToText(MinVer,   MinVerChar,   4, 10);
  +            XMLString::binToText(Revision, RevisionChar, 4, 10);
  +            
  +            ThrowXML3(XSerializationException
  +                    , XMLExcepts::XSer_BinaryData_Version_NotSupported
  +                    , MajVerChar
  +                    , MinVerChar
  +                    , RevisionChar);
  +        }
  +
  +        //StringPool, don't use >>
  +        fStringPool->serialize(serEng);
  +
  +        /***
  +         * Deserialize RefHashTableOf<Grammar>*    fGrammarRegistry; 
  +         ***/
  +        XTemplateSerializer::loadObject(&fGrammarRegistry, 29, true, serEng);
  +
  +    }
  +    catch(...)
  +    {
  +        fLocked = false;
  +        throw;
  +    }
  +
  +    fLocked = false;
  +}
  +
   
   XERCES_CPP_NAMESPACE_END
  
  
  
  1.8       +20 -7     xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.hpp
  
  Index: XMLGrammarPoolImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLGrammarPoolImpl.hpp    10 Oct 2003 18:36:41 -0000      1.7
  +++ XMLGrammarPoolImpl.hpp    29 Oct 2003 16:16:08 -0000      1.8
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.8  2003/10/29 16:16:08  peiyongz
  + * GrammarPool' serialization/deserialization support
  + *
    * Revision 1.7  2003/10/10 18:36:41  neilg
    * update XMLGrammarPool default implementation to reflect recent modifications to 
the base interface.
    *
  @@ -87,11 +90,11 @@
   #define XMLGrammarPoolImplIMPL_HPP
   
   #include <xercesc/framework/XMLGrammarPool.hpp>
  -#include <xercesc/util/RefHashTableOf.hpp>
  -#include <xercesc/util/SynchronizedStringPool.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  +class XMLSynchronizedStringPool;
  +
   class XMLUTIL_EXPORT XMLGrammarPoolImpl : public XMLGrammarPool
   {
   public :
  @@ -237,6 +240,16 @@
       virtual XMLStringPool *getURIStringPool();
   
       // @}
  +
  +    // -----------------------------------------------------------------------
  +    // serialization and deserialization support
  +    // -----------------------------------------------------------------------
  +    virtual void     serializeGrammars(BinOutputStream* const); 
  +    virtual void     deserializeGrammars(BinInputStream* const); 
  +
  +    friend class XObjectComparator;
  +    friend class XTemplateComparator;
  +
   private:
       // -----------------------------------------------------------------------
       /** name  Unimplemented copy constructor and operator= */
  @@ -260,10 +273,10 @@
       //      whether the pool has been locked
       //
       // -----------------------------------------------------------------------
  -    RefHashTableOf<Grammar>* fGrammarRegistry; 
  -    XMLStringPool         * fStringPool;
  -    XMLSynchronizedStringPool * fSynchronizedStringPool;
  -    bool                    fLocked;
  +    RefHashTableOf<Grammar>*    fGrammarRegistry; 
  +    XMLStringPool*              fStringPool;
  +    XMLSynchronizedStringPool*  fSynchronizedStringPool;
  +    bool                        fLocked;
   
   };
   
  
  
  
  1.3       +12 -1     xml-xerces/c/src/xercesc/internal/XSerializable.hpp
  
  Index: XSerializable.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSerializable.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XSerializable.hpp 23 Sep 2003 18:12:19 -0000      1.2
  +++ XSerializable.hpp 29 Oct 2003 16:16:08 -0000      1.3
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.3  2003/10/29 16:16:08  peiyongz
  + * GrammarPool' serialization/deserialization support
  + *
    * Revision 1.2  2003/09/23 18:12:19  peiyongz
    * Macro re-organized: provide create/nocreate macros for abstract and
    * nonabstract classes
  @@ -121,6 +124,8 @@
   virtual bool                    isSerializable()                  const ;  \
   virtual XProtoType*             getProtoType()                    const;   \
   virtual void                    serialize(XSerializeEngine&); \
  +friend  class XObjectComparator;   \
  +friend  class XTemplateComparator; \
   \
   inline friend XSerializeEngine& operator>>(XSerializeEngine& serEng  \
                                            , class_name*&      objPtr) \
  @@ -153,6 +158,11 @@
   XProtoType* class_name::getProtoType()   const \
   {return XPROTOTYPE_CLASS(class_name); } 
   
  +#define IS_EQUIVALENT(lptr, rptr) \
  +    if (lptr == rptr)             \
  +        return true;              \
  +    if (( lptr && !rptr) || (!lptr &&  rptr))  \
  +        return false;
   
   XERCES_CPP_NAMESPACE_END
   
  
  
  
  1.2       +77 -5     xml-xerces/c/src/xercesc/internal/XTemplateSerializer.cpp
  
  Index: XTemplateSerializer.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XTemplateSerializer.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XTemplateSerializer.cpp   17 Oct 2003 21:07:49 -0000      1.1
  +++ XTemplateSerializer.cpp   29 Oct 2003 16:16:08 -0000      1.2
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.2  2003/10/29 16:16:08  peiyongz
  + * GrammarPool' serialization/deserialization support
  + *
    * Revision 1.1  2003/10/17 21:07:49  peiyongz
    * To support Template object serialization/deserialization
    *
  @@ -69,6 +72,7 @@
   // ---------------------------------------------------------------------------
   #include <xercesc/internal/XSerializeEngine.hpp>
   #include <xercesc/internal/XTemplateSerializer.hpp>
  +#include <xercesc/validators/common/Grammar.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -753,6 +757,7 @@
    *   XercesAttGroupInfo
    *   XMLRefInfo
    *   DatatypeValidator
  + *   Grammar
    *
    ***********************************************************/
   void XTemplateSerializer::storeObject(RefHashTableOf<KVStringPair>* const objToStore
  @@ -1306,6 +1311,73 @@
       }
   }
   
  +void XTemplateSerializer::storeObject(RefHashTableOf<Grammar>* const objToStore
  +                                    , XSerializeEngine&              serEng)        
                                  
  +{
  +
  +    if (serEng.needToStoreObject(objToStore))
  +    {
  +        RefHashTableOfEnumerator<Grammar> e(objToStore);
  +        int itemNumber = 0;        
  +
  +        while (e.hasMoreElements())
  +        {
  +            e.nextElement();
  +            itemNumber++;
  +        }
  +
  +        serEng<<itemNumber;
  +        e.Reset();
  +
  +        while (e.hasMoreElements())
  +        {
  +            XMLCh*     key  = (XMLCh*) e.nextElementKey();
  +            serEng.writeString(key);
  +
  +            Grammar* data = objToStore->get(key);
  +            Grammar::storeGrammar(serEng, data);
  +        }
  +    }
  +}
  +
  +void XTemplateSerializer::loadObject(RefHashTableOf<Grammar>** objToLoad
  +                                   , int                       initSize
  +                                   , bool                      toAdopt
  +                                   , XSerializeEngine&         serEng)
  +{
  +
  +    if (serEng.needToLoadObject((void**)objToLoad))
  +    {
  +        if (!*objToLoad)
  +        {
  +            if (initSize < 0)
  +                initSize = 16;
  +
  +            *objToLoad = new (serEng.getMemoryManager()) 
  +                             RefHashTableOf<Grammar>(
  +                                                     initSize
  +                                                   , toAdopt
  +                                                   , serEng.getMemoryManager()
  +                                                   );
  +        }
  +
  +        serEng.registerObject(*objToLoad);
  +
  +        int itemNumber = 0;
  +        serEng>>itemNumber;
  +
  +        for (int itemIndex = 0; itemIndex < itemNumber; itemIndex++)
  +        {
  +            XMLCh*      key;
  +            serEng.readString(key);
  +
  +            Grammar*  data;
  +            data = Grammar::loadGrammar(serEng);
  +
  +            (*objToLoad)->put((void*)key, data);
  +        }
  +    }
  +}
   
   /**********************************************************
    *
  @@ -1343,7 +1415,7 @@
               serEng.writeString(key1);
               serEng<<key2;
   
  -            XMLAttDef* data = objToStore->get(key1, key2);
  +            SchemaAttDef* data = objToStore->get(key1, key2);
               serEng<<data;
   
           }
  @@ -1510,8 +1582,8 @@
           while (e.hasMoreElements())
           {
               //there is no e.nextElementKey() for RefHash3KeysIdPoolEnumerator
  -            SchemaElementDecl& attDef = e.nextElement();
  -            attDef.serialize(serEng);
  +            SchemaElementDecl& data = e.nextElement();
  +            data.serialize(serEng);
           }
   
       }
  
  
  
  1.2       +13 -2     xml-xerces/c/src/xercesc/internal/XTemplateSerializer.hpp
  
  Index: XTemplateSerializer.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XTemplateSerializer.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XTemplateSerializer.hpp   17 Oct 2003 21:07:49 -0000      1.1
  +++ XTemplateSerializer.hpp   29 Oct 2003 16:16:08 -0000      1.2
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.2  2003/10/29 16:16:08  peiyongz
  + * GrammarPool' serialization/deserialization support
  + *
    * Revision 1.1  2003/10/17 21:07:49  peiyongz
    * To support Template object serialization/deserialization
    *
  @@ -235,6 +238,7 @@
        *   XercesAttGroupInfo
        *   XMLRefInfo
        *   DatatypeValidator
  +     *   Grammar
        *
        ***********************************************************/
       static void           storeObject(RefHashTableOf<KVStringPair>* const 
tempObjToWrite
  @@ -301,6 +305,13 @@
                                      , bool                                      
toAdopt
                                      , XSerializeEngine&                         
serEng);
   
  +    static void           storeObject(RefHashTableOf<Grammar>* const tempObjToWrite
  +                                    , XSerializeEngine&              serEng);
  +
  +    static void           loadObject(RefHashTableOf<Grammar>**       tempObjToRead
  +                                   , int                             initSize
  +                                   , bool                            toAdopt
  +                                   , XSerializeEngine&               serEng);
   
       /**********************************************************
        *
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to