GeneralAttributeCheck.hpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:11k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001-2002 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.  * $Id: GeneralAttributeCheck.hpp,v 1.9 2003/05/16 21:43:21 knoaman Exp $
  58.  */
  59. #if !defined(GENERALATTRIBUTECHECK_HPP)
  60. #define GENERALATTRIBUTECHECK_HPP
  61. /**
  62.   * A general purpose class to check for valid values of attributes, as well
  63.   * as check for proper association with corresponding schema elements.
  64.   */
  65. // ---------------------------------------------------------------------------
  66. //  Includes
  67. // ---------------------------------------------------------------------------
  68. #include <xercesc/util/RefHashTableOf.hpp>
  69. #include <xercesc/util/ValueHashTableOf.hpp>
  70. #include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
  71. XERCES_CPP_NAMESPACE_BEGIN
  72. // ---------------------------------------------------------------------------
  73. //  Forward declaration
  74. // ---------------------------------------------------------------------------
  75. class TraverseSchema;
  76. class DOMElement;
  77. class VALIDATORS_EXPORT GeneralAttributeCheck : public XMemory
  78. {
  79. public:
  80.     // -----------------------------------------------------------------------
  81.     //  Constants
  82.     // -----------------------------------------------------------------------
  83.     //Elements
  84.     enum
  85.     {
  86.         E_All,
  87.         E_Annotation,
  88.         E_Any,
  89.         E_AnyAttribute,
  90.         E_Appinfo,
  91.         E_AttributeGlobal,
  92.         E_AttributeLocal,
  93.         E_AttributeRef,
  94.         E_AttributeGroupGlobal,
  95.         E_AttributeGroupRef,
  96.         E_Choice,
  97.         E_ComplexContent,
  98.         E_ComplexTypeGlobal,
  99.         E_ComplexTypeLocal,
  100.         E_Documentation,
  101.         E_ElementGlobal,
  102.         E_ElementLocal,
  103.         E_ElementRef,
  104.         E_Enumeration,
  105.         E_Extension,
  106.         E_Field,
  107.         E_FractionDigits,
  108.         E_GroupGlobal,
  109.         E_GroupRef,
  110.         E_Import,
  111.         E_Include,
  112.         E_Key,
  113.         E_KeyRef,
  114.         E_Length,
  115.         E_List,
  116.         E_MaxExclusive,
  117.         E_MaxInclusive,
  118.         E_MaxLength,
  119.         E_MinExclusive,
  120.         E_MinInclusive,
  121.         E_MinLength,
  122.         E_Notation,
  123.         E_Pattern,
  124.         E_Redefine,
  125.         E_Restriction,
  126.         E_Schema,
  127.         E_Selector,
  128.         E_Sequence,
  129.         E_SimpleContent,
  130.         E_SimpleTypeGlobal,
  131.         E_SimpleTypeLocal,
  132.         E_TotalDigits,
  133.         E_Union,
  134.         E_Unique,
  135.         E_WhiteSpace,
  136.         E_Count,
  137.         E_Invalid = -1
  138.     };
  139.     //Attributes
  140.     enum
  141.     {
  142.         A_Abstract,
  143.         A_AttributeFormDefault,
  144.         A_Base,
  145.         A_Block,
  146.         A_BlockDefault,
  147.         A_Default,
  148.         A_ElementFormDefault,
  149.         A_Final,
  150.         A_FinalDefault,
  151.         A_Fixed,
  152.         A_Form,
  153.         A_ID,
  154.         A_ItemType,
  155.         A_MaxOccurs,
  156.         A_MemberTypes,
  157.         A_MinOccurs,
  158.         A_Mixed,
  159.         A_Name,
  160.         A_Namespace,
  161.         A_Nillable,
  162.         A_ProcessContents,
  163.         A_Public,
  164.         A_Ref,
  165.         A_Refer,
  166.         A_SchemaLocation,
  167.         A_Source,
  168.         A_SubstitutionGroup,
  169.         A_System,
  170.         A_TargetNamespace,
  171.         A_Type,
  172.         A_Use,
  173.         A_Value,
  174.         A_Version,
  175.         A_XPath,
  176.         A_Count,
  177.         A_Invalid = -1
  178.     };
  179.     //Validators
  180.     enum {
  181.         DV_String = 0,
  182.         DV_AnyURI = 4,
  183.         DV_NonNegInt = 8,
  184.         DV_Boolean = 16,
  185.         DV_ID = 32,
  186.         DV_Form = 64,
  187.         DV_MaxOccurs = 128,
  188.         DV_MaxOccurs1 = 256,
  189.         DV_MinOccurs1 = 512,
  190.         DV_ProcessContents = 1024,
  191.         DV_Use = 2048,
  192.         DV_WhiteSpace = 4096,
  193.         DV_Mask = (DV_AnyURI | DV_NonNegInt | DV_Boolean | DV_ID | DV_Form |
  194.                    DV_MaxOccurs | DV_MaxOccurs1 | DV_MinOccurs1 |
  195.                    DV_ProcessContents | DV_Use | DV_WhiteSpace)
  196.     };
  197.     // generate element-attributes map table
  198. #if defined(NEED_TO_GEN_ELEM_ATT_MAP_TABLE)
  199.     static void initCharFlagTable();
  200. #endif
  201.     // -----------------------------------------------------------------------
  202.     //  Constructor/Destructor
  203.     // -----------------------------------------------------------------------
  204.     GeneralAttributeCheck(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
  205.     ~GeneralAttributeCheck();
  206.     // -----------------------------------------------------------------------
  207.     //  Getter methods
  208.     // -----------------------------------------------------------------------
  209.     unsigned short getFacetId(const XMLCh* const facetName);
  210.     // -----------------------------------------------------------------------
  211.     //  Setter methods
  212.     // -----------------------------------------------------------------------
  213.     void setIDRefList(RefHashTableOf<XMLRefInfo>* const refList);
  214.     // -----------------------------------------------------------------------
  215.     //  Validation methods
  216.     // -----------------------------------------------------------------------
  217.     void checkAttributes(const DOMElement* const elem,
  218.                          const unsigned short elemContext,
  219.                          TraverseSchema* const schema,
  220.                          const bool isTopLevel = false);
  221.     // -----------------------------------------------------------------------
  222.     //  Notification that lazy data has been deleted
  223.     // -----------------------------------------------------------------------
  224. static void reinitGeneralAttCheck();
  225. private:
  226.     // -----------------------------------------------------------------------
  227.     //  Unimplemented constructors and operators
  228.     // -----------------------------------------------------------------------
  229.     GeneralAttributeCheck(const GeneralAttributeCheck&);
  230.     GeneralAttributeCheck& operator=(const GeneralAttributeCheck&);
  231.     // -----------------------------------------------------------------------
  232.     //  Setup methods
  233.     // -----------------------------------------------------------------------
  234.     void setUpValidators();
  235.     void mapElements();
  236.     void mapAttributes();
  237.     // -----------------------------------------------------------------------
  238.     //  Validation methods
  239.     // -----------------------------------------------------------------------
  240.     void validate(const DOMElement* const elem, const XMLCh* const attName, const XMLCh* const attValue,
  241.                   const short dvIndex, TraverseSchema* const schema);
  242.     // -----------------------------------------------------------------------
  243.     //  Private Constants
  244.     // -----------------------------------------------------------------------
  245.     // optional vs. required attribute
  246.     enum {
  247.         Att_Required = 1,
  248.         Att_Optional = 2,
  249.         Att_Mask = 3
  250.     };
  251.     // -----------------------------------------------------------------------
  252.     //  Private data members
  253.     // -----------------------------------------------------------------------
  254.     static ValueHashTableOf<unsigned short>* fAttMap;
  255.     static ValueHashTableOf<unsigned short>* fFacetsMap;
  256.     static DatatypeValidator*                fNonNegIntDV;
  257.     static DatatypeValidator*                fBooleanDV;
  258.     static DatatypeValidator*                fAnyURIDV;
  259.     static unsigned short                    fgElemAttTable[E_Count][A_Count];
  260.     static const XMLCh*                      fAttNames[A_Count];
  261.     MemoryManager*                           fMemoryManager;
  262.     RefHashTableOf<XMLRefInfo>*              fIDRefList;
  263.     IDDatatypeValidator                      fIDValidator;
  264. };
  265. // ---------------------------------------------------------------------------
  266. //  GeneralAttributeCheck: Getter methods
  267. // ---------------------------------------------------------------------------
  268. inline unsigned short
  269. GeneralAttributeCheck::getFacetId(const XMLCh* const facetName) {
  270.     return fFacetsMap->get(facetName);
  271. }
  272. // ---------------------------------------------------------------------------
  273. //  GeneralAttributeCheck: Setter methods
  274. // ---------------------------------------------------------------------------
  275. inline void
  276. GeneralAttributeCheck::setIDRefList(RefHashTableOf<XMLRefInfo>* const refList) {
  277.     fIDRefList = refList;
  278. }
  279. XERCES_CPP_NAMESPACE_END
  280. #endif
  281. /**
  282.   * End of file GeneralAttributeCheck.hpp
  283.   */