source: NonGTP/Xerces/xerces/include/xercesc/validators/schema/GeneralAttributeCheck.hpp @ 358

Revision 358, 9.3 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2001-2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: GeneralAttributeCheck.hpp,v 1.13 2004/09/08 13:56:56 peiyongz Exp $
19 */
20
21#if !defined(GENERALATTRIBUTECHECK_HPP)
22#define GENERALATTRIBUTECHECK_HPP
23
24/**
25  * A general purpose class to check for valid values of attributes, as well
26  * as check for proper association with corresponding schema elements.
27  */
28
29// ---------------------------------------------------------------------------
30//  Includes
31// ---------------------------------------------------------------------------
32#include <xercesc/util/RefHashTableOf.hpp>
33#include <xercesc/util/ValueHashTableOf.hpp>
34#include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
35#include <xercesc/framework/ValidationContext.hpp>
36
37XERCES_CPP_NAMESPACE_BEGIN
38
39// ---------------------------------------------------------------------------
40//  Forward declaration
41// ---------------------------------------------------------------------------
42class TraverseSchema;
43class DOMElement;
44class DOMNode;
45
46class VALIDATORS_EXPORT GeneralAttributeCheck : public XMemory
47{
48public:
49    // -----------------------------------------------------------------------
50    //  Constants
51    // -----------------------------------------------------------------------
52    //Elements
53    enum
54    {
55        E_All,
56        E_Annotation,
57        E_Any,
58        E_AnyAttribute,
59        E_Appinfo,
60        E_AttributeGlobal,
61        E_AttributeLocal,
62        E_AttributeRef,
63        E_AttributeGroupGlobal,
64        E_AttributeGroupRef,
65        E_Choice,
66        E_ComplexContent,
67        E_ComplexTypeGlobal,
68        E_ComplexTypeLocal,
69        E_Documentation,
70        E_ElementGlobal,
71        E_ElementLocal,
72        E_ElementRef,
73        E_Enumeration,
74        E_Extension,
75        E_Field,
76        E_FractionDigits,
77        E_GroupGlobal,
78        E_GroupRef,
79        E_Import,
80        E_Include,
81        E_Key,
82        E_KeyRef,
83        E_Length,
84        E_List,
85        E_MaxExclusive,
86        E_MaxInclusive,
87        E_MaxLength,
88        E_MinExclusive,
89        E_MinInclusive,
90        E_MinLength,
91        E_Notation,
92        E_Pattern,
93        E_Redefine,
94        E_Restriction,
95        E_Schema,
96        E_Selector,
97        E_Sequence,
98        E_SimpleContent,
99        E_SimpleTypeGlobal,
100        E_SimpleTypeLocal,
101        E_TotalDigits,
102        E_Union,
103        E_Unique,
104        E_WhiteSpace,
105
106        E_Count,
107        E_Invalid = -1
108    };
109
110    //Attributes
111    enum
112    {
113        A_Abstract,
114        A_AttributeFormDefault,
115        A_Base,
116        A_Block,
117        A_BlockDefault,
118        A_Default,
119        A_ElementFormDefault,
120        A_Final,
121        A_FinalDefault,
122        A_Fixed,
123        A_Form,
124        A_ID,
125        A_ItemType,
126        A_MaxOccurs,
127        A_MemberTypes,
128        A_MinOccurs,
129        A_Mixed,
130        A_Name,
131        A_Namespace,
132        A_Nillable,
133        A_ProcessContents,
134        A_Public,
135        A_Ref,
136        A_Refer,
137        A_SchemaLocation,
138        A_Source,
139        A_SubstitutionGroup,
140        A_System,
141        A_TargetNamespace,
142        A_Type,
143        A_Use,
144        A_Value,
145        A_Version,
146        A_XPath,
147
148        A_Count,
149        A_Invalid = -1
150    };
151
152    //Validators
153    enum {
154
155        DV_String = 0,
156        DV_AnyURI = 4,
157        DV_NonNegInt = 8,
158        DV_Boolean = 16,
159        DV_ID = 32,
160        DV_Form = 64,
161        DV_MaxOccurs = 128,
162        DV_MaxOccurs1 = 256,
163        DV_MinOccurs1 = 512,
164        DV_ProcessContents = 1024,
165        DV_Use = 2048,
166        DV_WhiteSpace = 4096,
167
168        DV_Mask = (DV_AnyURI | DV_NonNegInt | DV_Boolean | DV_ID | DV_Form |
169                   DV_MaxOccurs | DV_MaxOccurs1 | DV_MinOccurs1 |
170                   DV_ProcessContents | DV_Use | DV_WhiteSpace)
171    };
172
173    // generate element-attributes map table
174#if defined(NEED_TO_GEN_ELEM_ATT_MAP_TABLE)
175    static void initCharFlagTable();
176#endif
177
178    // -----------------------------------------------------------------------
179    //  Constructor/Destructor
180    // -----------------------------------------------------------------------
181    GeneralAttributeCheck(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
182    ~GeneralAttributeCheck();
183
184    // -----------------------------------------------------------------------
185    //  Getter methods
186    // -----------------------------------------------------------------------
187    unsigned short getFacetId(const XMLCh* const facetName, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
188
189    // -----------------------------------------------------------------------
190    //  Setter methods
191    // -----------------------------------------------------------------------
192
193    //deprecated
194    void setIDRefList(RefHashTableOf<XMLRefInfo>* const refList);
195
196    inline void setValidationContext(ValidationContext* const);
197
198    // -----------------------------------------------------------------------
199    //  Validation methods
200    // -----------------------------------------------------------------------
201    void checkAttributes(const DOMElement* const elem,
202                         const unsigned short elemContext,
203                         TraverseSchema* const schema,
204                         const bool isTopLevel = false,
205                         ValueVectorOf<DOMNode*>* const nonXSAttList = 0);
206
207    // -----------------------------------------------------------------------
208    //  Notification that lazy data has been deleted
209    // -----------------------------------------------------------------------
210        static void reinitGeneralAttCheck();
211
212private:
213    // -----------------------------------------------------------------------
214    //  Unimplemented constructors and operators
215    // -----------------------------------------------------------------------
216    GeneralAttributeCheck(const GeneralAttributeCheck&);
217    GeneralAttributeCheck& operator=(const GeneralAttributeCheck&);
218
219    // -----------------------------------------------------------------------
220    //  Setup methods
221    // -----------------------------------------------------------------------
222    void setUpValidators();
223    void mapElements();
224    void mapAttributes();
225
226    // -----------------------------------------------------------------------
227    //  Validation methods
228    // -----------------------------------------------------------------------
229    void validate(const DOMElement* const elem, const XMLCh* const attName, const XMLCh* const attValue,
230                  const short dvIndex, TraverseSchema* const schema);
231
232    // -----------------------------------------------------------------------
233    //  Private Constants
234    // -----------------------------------------------------------------------
235    // optional vs. required attribute
236    enum {
237        Att_Required = 1,
238        Att_Optional = 2,
239        Att_Mask = 3
240    };
241
242    // -----------------------------------------------------------------------
243    //  Private data members
244    // -----------------------------------------------------------------------
245    static ValueHashTableOf<unsigned short>* fAttMap;
246    static ValueHashTableOf<unsigned short>* fFacetsMap;
247    static DatatypeValidator*                fNonNegIntDV;
248    static DatatypeValidator*                fBooleanDV;
249    static DatatypeValidator*                fAnyURIDV;
250    static unsigned short                    fgElemAttTable[E_Count][A_Count];
251    static const XMLCh*                      fAttNames[A_Count];
252    MemoryManager*                           fMemoryManager;
253    ValidationContext*                       fValidationContext;
254    IDDatatypeValidator                      fIDValidator;
255};
256
257
258// ---------------------------------------------------------------------------
259//  GeneralAttributeCheck: Getter methods
260// ---------------------------------------------------------------------------
261inline unsigned short
262GeneralAttributeCheck::getFacetId(const XMLCh* const facetName, MemoryManager* const manager) {
263
264    return fFacetsMap->get(facetName, manager);
265}
266
267// ---------------------------------------------------------------------------
268//  GeneralAttributeCheck: Setter methods
269// ---------------------------------------------------------------------------
270inline void GeneralAttributeCheck::setValidationContext(ValidationContext* const newValidationContext)
271{
272    fValidationContext = newValidationContext;
273}
274
275inline void
276GeneralAttributeCheck::setIDRefList(RefHashTableOf<XMLRefInfo>* const refList) {
277
278    fValidationContext->setIdRefList(refList);
279}
280
281XERCES_CPP_NAMESPACE_END
282
283#endif
284
285/**
286  * End of file GeneralAttributeCheck.hpp
287  */
288
Note: See TracBrowser for help on using the repository browser.