You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2002/07/11 20:21:20 UTC

cvs commit: xml-xerces/c/src/xercesc/validators/schema SchemaGrammar.hpp SchemaGrammar.cpp

knoaman     2002/07/11 11:21:20

  Modified:    c/src/xercesc/validators/schema SchemaGrammar.hpp
                        SchemaGrammar.cpp
  Log:
  Grammar caching/preparsing - initial implementation.
  
  Revision  Changes    Path
  1.3       +59 -31    xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp
  
  Index: SchemaGrammar.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SchemaGrammar.hpp	5 Jul 2002 17:08:10 -0000	1.2
  +++ SchemaGrammar.hpp	11 Jul 2002 18:21:20 -0000	1.3
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.3  2002/07/11 18:21:20  knoaman
  + * Grammar caching/preparsing - initial implementation.
  + *
    * Revision 1.2  2002/07/05 17:08:10  tng
    * [Bug 10119] Grammar::getGrammarType need a const modifier
    *
  @@ -117,6 +120,7 @@
   #include <xercesc/validators/schema/SchemaElementDecl.hpp>
   #include <xercesc/util/ValueVectorOf.hpp>
   #include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
  +#include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
   
   //
   // This class stores the Schema information
  @@ -130,7 +134,6 @@
   // ---------------------------------------------------------------------------
   //  Forward Declarations
   // ---------------------------------------------------------------------------
  -class DatatypeValidatorFactory;
   class ComplexTypeInfo;
   class NamespaceScope;
   class XercesGroupInfo;
  @@ -211,6 +214,8 @@
           const   XMLCh* const    notName
       );
   
  +    virtual bool getValidated() const;
  +
       virtual XMLElementDecl* putElemDecl
       (
           const   unsigned int    uriId
  @@ -218,11 +223,13 @@
           , const XMLCh* const    prefixName
           , const XMLCh* const    qName
           , unsigned int          scope
  +        , const bool            notDeclared = false
       );
   
       virtual unsigned int putElemDecl
       (
           XMLElementDecl* const elemDecl
  +        , const bool          notDeclared = false
       )   const;
   
       virtual unsigned int putNotationDecl
  @@ -230,6 +237,8 @@
           XMLNotationDecl* const notationDecl
       )   const;
   
  +    virtual void setValidated(const bool newState);
  +
       virtual void reset();
   
       // -----------------------------------------------------------------------
  @@ -240,11 +249,10 @@
       RefHashTableOf<ComplexTypeInfo>* getComplexTypeRegistry() const;
       RefHashTableOf<XercesGroupInfo>* getGroupInfoRegistry() const;
       RefHashTableOf<XercesAttGroupInfo>* getAttGroupInfoRegistry() const;
  -    DatatypeValidatorFactory* getDatatypeRegistry() const;
  +    DatatypeValidatorFactory* getDatatypeRegistry();
       NamespaceScope* getNamespaceScope() const;
       RefHash2KeysTableOf<ElemVector>* getValidSubstitutionGroups() const;
       RefHashTableOf<XMLRefInfo>* getIDRefList() const;
  -    bool getUPAChecked() const;
   
       // -----------------------------------------------------------------------
       //  Setter methods
  @@ -254,10 +262,8 @@
       void setComplexTypeRegistry(RefHashTableOf<ComplexTypeInfo>* const other);
       void setGroupInfoRegistry(RefHashTableOf<XercesGroupInfo>* const other);
       void setAttGroupInfoRegistry(RefHashTableOf<XercesAttGroupInfo>* const other);
  -    void setDatatypeRegistry(DatatypeValidatorFactory* const dvRegistry);
       void setNamespaceScope(NamespaceScope* const nsScope);
       void setValidSubstitutionGroups(RefHash2KeysTableOf<ElemVector>* const);
  -    void setUPAChecked(bool newState);
   
       // -----------------------------------------------------------------------
       //  Helper methods
  @@ -270,13 +276,21 @@
   private:
   
       // -----------------------------------------------------------------------
  +    //  Helper methods
  +    // -----------------------------------------------------------------------
  +    void cleanUp();
  +
  +    // -----------------------------------------------------------------------
       //  Private data members
       //
       //  fElemDeclPool
       //      This is the element decl pool. It contains all of the elements
  -    //      declared in the Schema (and their associated attributes.) When in
  -    //      non-validating mode, its just populated as new elements are seen
  -    //      and they are given default characteristics.
  +    //      declared in the Schema (and their associated attributes.) 
  +    //
  +    //  fElemNonDeclPool
  +    //      This is the element decl pool that is is populated as new elements
  +    //      are seen in the XML document (not declared in the Schema), and they
  +    //      are given default characteristics.
       //
       //  fGroupElemDeclPool
       //      This is the element decl pool for elements in a group that are
  @@ -315,23 +329,25 @@
       //      List of ids of schema declarations extracted during schema grammar
       //      traversal
       //
  -    //  fUPAChecked
  -    //      Indicates if this Grammar has already been validated for
  -    //      schema unique particle attribute constraint checking.
  +    //  fValidated
  +    //      Indicates if the content of the Grammar has been pre-validated
  +    //      or not (UPA checking, etc.). When using a cached grammar, no need
  +    //      for pre content validation.
       // -----------------------------------------------------------------------
       XMLCh*                                 fTargetNamespace;
       RefHash3KeysIdPool<SchemaElementDecl>* fElemDeclPool;
  +    RefHash3KeysIdPool<SchemaElementDecl>* fElemNonDeclPool;
       RefHash3KeysIdPool<SchemaElementDecl>* fGroupElemDeclPool;
       NameIdPool<XMLNotationDecl>*           fNotationDeclPool;
       RefHashTableOf<XMLAttDef>*             fAttributeDeclRegistry;
       RefHashTableOf<ComplexTypeInfo>*       fComplexTypeRegistry;
       RefHashTableOf<XercesGroupInfo>*       fGroupInfoRegistry;
       RefHashTableOf<XercesAttGroupInfo>*    fAttGroupInfoRegistry;
  -    DatatypeValidatorFactory*              fDatatypeRegistry;
  +    DatatypeValidatorFactory               fDatatypeRegistry;
       NamespaceScope*                        fNamespaceScope;
       RefHash2KeysTableOf<ElemVector>*       fValidSubstitutionGroups;
       RefHashTableOf<XMLRefInfo>*            fIDRefList;
  -    bool                                   fUPAChecked;
  +    bool                                   fValidated;
   };
   
   
  @@ -367,9 +383,9 @@
       return fAttGroupInfoRegistry;
   }
   
  -inline DatatypeValidatorFactory* SchemaGrammar::getDatatypeRegistry() const {
  +inline DatatypeValidatorFactory* SchemaGrammar::getDatatypeRegistry() {
   
  -    return fDatatypeRegistry;
  +    return &fDatatypeRegistry;
   }
   
   inline NamespaceScope* SchemaGrammar::getNamespaceScope() const {
  @@ -383,10 +399,6 @@
       return fValidSubstitutionGroups;
   }
   
  -inline bool SchemaGrammar::getUPAChecked() const {
  -    return fUPAChecked;
  -}
  -
   inline RefHashTableOf<XMLRefInfo>* SchemaGrammar::getIDRefList() const {
   
       return fIDRefList;
  @@ -424,12 +436,6 @@
       fAttGroupInfoRegistry = other;
   }
   
  -inline void
  -SchemaGrammar::setDatatypeRegistry(DatatypeValidatorFactory* const dvRegistry) {
  -
  -    fDatatypeRegistry = dvRegistry;
  -}
  -
   inline void SchemaGrammar::setNamespaceScope(NamespaceScope* const nsScope) {
   
       fNamespaceScope = nsScope;
  @@ -441,9 +447,6 @@
       fValidSubstitutionGroups = other;
   }
   
  -inline void SchemaGrammar::setUPAChecked(bool newState) {
  -    fUPAChecked = newState;
  -}
   
   // ---------------------------------------------------------------------------
   //  SchemaGrammar: Virtual methods
  @@ -484,9 +487,14 @@
   {
       const SchemaElementDecl* decl = fElemDeclPool->getByKey(baseName, uriId, scope);
   
  -    if (!decl)
  +    if (!decl) {
  +
           decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
   
  +        if (!decl)
  +            decl = fElemNonDeclPool->getByKey(baseName, uriId, scope);
  +    }
  +
       return decl;
   }
   
  @@ -497,9 +505,14 @@
   {
       SchemaElementDecl* decl = fElemDeclPool->getByKey(baseName, uriId, scope);
   
  -    if (!decl)
  +    if (!decl) {
  +
           decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
   
  +        if (!decl)
  +            decl = fElemNonDeclPool->getByKey(baseName, uriId, scope);
  +    }
  +
       return decl;
   }
   
  @@ -525,8 +538,13 @@
       return decl;
   }
   
  -inline unsigned int SchemaGrammar::putElemDecl (XMLElementDecl* const elemDecl)   const
  +inline unsigned int
  +SchemaGrammar::putElemDecl(XMLElementDecl* const elemDecl,
  +                           const bool notDeclared) const
   {
  +    if (notDeclared)
  +        return fElemNonDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl);
  +
       return fElemDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl);
   }
   
  @@ -549,6 +567,16 @@
   inline unsigned int SchemaGrammar::putNotationDecl(XMLNotationDecl* const notationDecl)   const
   {
       return fNotationDeclPool->put(notationDecl);
  +}
  +
  +inline bool SchemaGrammar::getValidated() const
  +{
  +    return fValidated;
  +}
  +
  +inline void SchemaGrammar::setValidated(const bool newState)
  +{
  +    fValidated = newState;
   }
   
   #endif
  
  
  
  1.2       +48 -32    xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp
  
  Index: SchemaGrammar.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchemaGrammar.cpp	1 Feb 2002 22:22:46 -0000	1.1
  +++ SchemaGrammar.cpp	11 Jul 2002 18:21:20 -0000	1.2
  @@ -56,8 +56,11 @@
   
   /*
    * $Log$
  - * Revision 1.1  2002/02/01 22:22:46  peiyongz
  - * Initial revision
  + * Revision 1.2  2002/07/11 18:21:20  knoaman
  + * Grammar caching/preparsing - initial implementation.
  + *
  + * Revision 1.1.1.1  2002/02/01 22:22:46  peiyongz
  + * sane_include
    *
    * Revision 1.11  2002/01/02 15:20:22  tng
    * Schema Fix: should not store a temp value as the key in the element pool and the attribute pool.
  @@ -113,17 +116,17 @@
   SchemaGrammar::SchemaGrammar() :
       fTargetNamespace(0)
       , fElemDeclPool(0)
  +    , fElemNonDeclPool(0)
       , fGroupElemDeclPool(0)
       , fNotationDeclPool(0)
       , fAttributeDeclRegistry(0)
       , fComplexTypeRegistry(0)
       , fGroupInfoRegistry(0)
       , fAttGroupInfoRegistry(0)
  -    , fDatatypeRegistry(0)
       , fNamespaceScope(0)
       , fValidSubstitutionGroups(0)
       , fIDRefList(0)
  -    , fUPAChecked(false)
  +    , fValidated(false)
   {
       //
       //  Init all the pool members.
  @@ -132,31 +135,31 @@
       //  pools.
       //
       fElemDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(109);
  -    fGroupElemDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(109, false);
  -    fNotationDeclPool = new NameIdPool<XMLNotationDecl>(109);
  -    fIDRefList = new RefHashTableOf<XMLRefInfo>(29);
   
  -    //
  -    //  Call our own reset method. This lets us have the pool setup stuff
  -    //  done in just one place (because this stame setup stuff has to be
  -    //  done every time we are reset.)
  -    //
  -    reset();
  +    try {
  +        fElemNonDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(29);
  +        fGroupElemDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(109, false);
  +        fNotationDeclPool = new NameIdPool<XMLNotationDecl>(109);
  +        fIDRefList = new RefHashTableOf<XMLRefInfo>(29);
  +        fDatatypeRegistry.expandRegistryToFullSchemaSet();
  +
  +        //
  +        //  Call our own reset method. This lets us have the pool setup stuff
  +        //  done in just one place (because this stame setup stuff has to be
  +        //  done every time we are reset.)
  +        //
  +        reset();
  +    }
  +    catch(...) {
  +
  +        cleanUp();
  +        throw;
  +    }
   }
   
   SchemaGrammar::~SchemaGrammar()
   {
  -    delete fElemDeclPool;
  -    delete fGroupElemDeclPool;
  -    delete fNotationDeclPool;
  -    delete [] fTargetNamespace;
  -    delete fAttributeDeclRegistry;
  -    delete fComplexTypeRegistry;
  -    delete fGroupInfoRegistry;
  -    delete fAttGroupInfoRegistry;
  -    delete fNamespaceScope;
  -    delete fValidSubstitutionGroups;
  -    delete fIDRefList;
  +    cleanUp();
   }
   
   
  @@ -171,17 +174,13 @@
           ,       bool&           wasAdded )
   {
       // See it it exists
  -    SchemaElementDecl* retVal = fElemDeclPool->getByKey(baseName, uriId, scope);
  -
  -    if (!retVal) {
  -        retVal = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
  -    }
  +    SchemaElementDecl* retVal = (SchemaElementDecl*) getElemDecl(uriId, baseName, qName, scope);
   
       // if not, then add this in
       if (!retVal)
       {
           retVal = new SchemaElementDecl(prefixName, baseName, uriId, SchemaElementDecl::Any);
  -        const unsigned int elemId = fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal);
  +        const unsigned int elemId = fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal);
           retVal->setId(elemId);
           wasAdded = true;
       }
  @@ -196,10 +195,12 @@
           , const XMLCh* const    baseName
           , const XMLCh* const    prefixName
           , const XMLCh* const    qName
  -        , unsigned int          scope)
  +        , unsigned int          scope
  +        , const bool            notDeclared)
   {
       SchemaElementDecl* retVal = new SchemaElementDecl(prefixName, baseName, uriId, SchemaElementDecl::Any);
  -    const unsigned int elemId = fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal);
  +    const unsigned int elemId = (notDeclared) ? fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal)
  +                                              : fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal);
       retVal->setId(elemId);
       return retVal;
   }
  @@ -210,11 +211,26 @@
       //  We need to reset all of the pools.
       //
       fElemDeclPool->removeAll();
  +    fElemNonDeclPool->removeAll();
       fGroupElemDeclPool->removeAll();
       fNotationDeclPool->removeAll();
  -    fUPAChecked = false;
  +    fValidated = false;
   }
   
   
  -
  +void SchemaGrammar::cleanUp()
  +{
  +    delete fElemDeclPool;
  +    delete fElemNonDeclPool;
  +    delete fGroupElemDeclPool;
  +    delete fNotationDeclPool;
  +    delete [] fTargetNamespace;
  +    delete fAttributeDeclRegistry;
  +    delete fComplexTypeRegistry;
  +    delete fGroupInfoRegistry;
  +    delete fAttGroupInfoRegistry;
  +    delete fNamespaceScope;
  +    delete fValidSubstitutionGroups;
  +    delete fIDRefList;
  +}
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org