SchemaGrammar.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:8k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 2001, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: SchemaGrammar.cpp,v $
  58.  * Revision 1.10  2001/11/19 18:26:31  knoaman
  59.  * no message
  60.  *
  61.  * Revision 1.9  2001/10/09 12:18:26  tng
  62.  * Leak fix: should use delete [] to delete fTargetNamespace.
  63.  *
  64.  * Revision 1.8  2001/09/14 14:50:22  tng
  65.  * Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems.
  66.  *
  67.  * Revision 1.7  2001/08/21 16:06:11  tng
  68.  * Schema: Unique Particle Attribution Constraint Checking.
  69.  *
  70.  * Revision 1.6  2001/07/31 15:27:10  knoaman
  71.  * Added support for <attributeGroup>.
  72.  *
  73.  * Revision 1.5  2001/07/24 18:33:46  knoaman
  74.  * Added support for <group> + extra constraint checking for complexType
  75.  *
  76.  * Revision 1.4  2001/06/25 12:51:56  knoaman
  77.  * Add constraint checking on elements in complex types to prevent same
  78.  * element names from having different definitions - use substitueGroups.
  79.  *
  80.  * Revision 1.3  2001/05/11 13:27:36  tng
  81.  * Copyright update.
  82.  *
  83.  * Revision 1.2  2001/04/19 17:43:18  knoaman
  84.  * More schema implementation classes.
  85.  *
  86.  * Revision 1.1  2001/03/21 21:56:33  tng
  87.  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  88.  *
  89.  */
  90. // ---------------------------------------------------------------------------
  91. //  Includes
  92. // ---------------------------------------------------------------------------
  93. #include <validators/schema/SchemaGrammar.hpp>
  94. #include <validators/schema/NamespaceScope.hpp>
  95. #include <validators/schema/ComplexTypeInfo.hpp>
  96. #include <validators/schema/SchemaSymbols.hpp>
  97. #include <validators/schema/XercesGroupInfo.hpp>
  98. #include <validators/schema/XercesAttGroupInfo.hpp>
  99. // ---------------------------------------------------------------------------
  100. //  SchemaGrammar: Constructors and Destructor
  101. // ---------------------------------------------------------------------------
  102. SchemaGrammar::SchemaGrammar() :
  103.     fTargetNamespace(0)
  104.     , fElemDeclPool(0)
  105.     , fGroupElemDeclPool(0)
  106.     , fNotationDeclPool(0)
  107.     , fAttributeDeclRegistry(0)
  108.     , fComplexTypeRegistry(0)
  109.     , fGroupInfoRegistry(0)
  110.     , fAttGroupInfoRegistry(0)
  111.     , fDatatypeRegistry(0)
  112.     , fNamespaceScope(0)
  113.     , fValidSubstitutionGroups(0)
  114.     , fIDRefList(0)
  115.     , fUPAChecked(false)
  116. {
  117.     //
  118.     //  Init all the pool members.
  119.     //
  120.     //  <TBD> Investigate what the optimum values would be for the various
  121.     //  pools.
  122.     //
  123.     fElemDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(109);
  124.     fGroupElemDeclPool = new RefHash3KeysIdPool<SchemaElementDecl>(109, false);
  125.     fNotationDeclPool = new NameIdPool<XMLNotationDecl>(109);
  126.     fIDRefList = new RefHashTableOf<XMLRefInfo>(29);
  127.     //
  128.     //  Call our own reset method. This lets us have the pool setup stuff
  129.     //  done in just one place (because this stame setup stuff has to be
  130.     //  done every time we are reset.)
  131.     //
  132.     reset();
  133. }
  134. SchemaGrammar::~SchemaGrammar()
  135. {
  136.     delete fElemDeclPool;
  137.     delete fGroupElemDeclPool;
  138.     delete fNotationDeclPool;
  139.     delete [] fTargetNamespace;
  140.     delete fAttributeDeclRegistry;
  141.     delete fComplexTypeRegistry;
  142.     delete fGroupInfoRegistry;
  143.     delete fAttGroupInfoRegistry;
  144.     delete fNamespaceScope;
  145.     delete fValidSubstitutionGroups;
  146.     delete fIDRefList;
  147. }
  148. // -----------------------------------------------------------------------
  149. //  Virtual methods
  150. // -----------------------------------------------------------------------
  151. XMLElementDecl* SchemaGrammar::findOrAddElemDecl (const   unsigned int    uriId
  152.         , const XMLCh* const    baseName
  153.         , const XMLCh* const    prefixName
  154.         , const XMLCh* const    qName
  155.         , unsigned int          scope
  156.         ,       bool&           wasAdded )
  157. {
  158.     // See it it exists
  159.     SchemaElementDecl* retVal = fElemDeclPool->getByKey(baseName, uriId, scope);
  160.     if (!retVal) {
  161.         retVal = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
  162.     }
  163.     // if not, then add this in
  164.     if (!retVal)
  165.     {
  166.         retVal = new SchemaElementDecl(prefixName, baseName, uriId, SchemaElementDecl::Any);
  167.         const unsigned int elemId = fElemDeclPool->put((void*)baseName, uriId, scope, retVal);
  168.         retVal->setId(elemId);
  169.         wasAdded = true;
  170.     }
  171.      else
  172.     {
  173.         wasAdded = false;
  174.     }
  175.     return retVal;
  176. }
  177. XMLElementDecl* SchemaGrammar::putElemDecl (const   unsigned int    uriId
  178.         , const XMLCh* const    baseName
  179.         , const XMLCh* const    prefixName
  180.         , const XMLCh* const    qName
  181.         , unsigned int          scope)
  182. {
  183.     SchemaElementDecl* retVal = new SchemaElementDecl(prefixName, baseName, uriId, SchemaElementDecl::Any);
  184.     const unsigned int elemId = fElemDeclPool->put((void*)baseName, uriId, scope, retVal);
  185.     retVal->setId(elemId);
  186.     return retVal;
  187. }
  188. void SchemaGrammar::reset()
  189. {
  190.     //
  191.     //  We need to reset all of the pools.
  192.     //
  193.     fElemDeclPool->removeAll();
  194.     fGroupElemDeclPool->removeAll();
  195.     fNotationDeclPool->removeAll();
  196.     fUPAChecked = false;
  197. }