[2720] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: AllContentModel.hpp 901107 2010-01-20 08:45:02Z borisk $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(XERCESC_INCLUDE_GUARD_ALLCONTENTMODEL_HPP) |
---|
| 23 | #define XERCESC_INCLUDE_GUARD_ALLCONTENTMODEL_HPP |
---|
| 24 | |
---|
| 25 | #include <xercesc/framework/XMLContentModel.hpp> |
---|
| 26 | #include <xercesc/util/ValueVectorOf.hpp> |
---|
| 27 | #include <xercesc/validators/common/ContentLeafNameTypeVector.hpp> |
---|
| 28 | |
---|
| 29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 30 | |
---|
| 31 | class ContentSpecNode; |
---|
| 32 | |
---|
| 33 | // |
---|
| 34 | // AllContentModel is a derivative of the abstract content model base |
---|
| 35 | // class that handles the special case of <all> feature in schema. If a model |
---|
| 36 | // is <all>, all non-optional children must appear |
---|
| 37 | // |
---|
| 38 | // So, all we have to do is to keep an array of the possible children and |
---|
| 39 | // validate by just looking up each child being validated by looking it up |
---|
| 40 | // in the list, and make sure all non-optional children appear. |
---|
| 41 | // |
---|
| 42 | class AllContentModel : public XMLContentModel |
---|
| 43 | { |
---|
| 44 | public : |
---|
| 45 | // ----------------------------------------------------------------------- |
---|
| 46 | // Constructors and Destructor |
---|
| 47 | // ----------------------------------------------------------------------- |
---|
| 48 | AllContentModel |
---|
| 49 | ( |
---|
| 50 | ContentSpecNode* const parentContentSpec |
---|
| 51 | , const bool isMixed |
---|
| 52 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 53 | ); |
---|
| 54 | |
---|
| 55 | ~AllContentModel(); |
---|
| 56 | |
---|
| 57 | // ----------------------------------------------------------------------- |
---|
| 58 | // Implementation of the ContentModel virtual interface |
---|
| 59 | // ----------------------------------------------------------------------- |
---|
| 60 | |
---|
| 61 | virtual bool validateContent |
---|
| 62 | ( |
---|
| 63 | #ifdef STORE_CHILDREN_INFORMATION_IN_PARSER |
---|
| 64 | XMLElementDecl ** const children |
---|
| 65 | #else |
---|
| 66 | QName** const children |
---|
| 67 | #endif |
---|
| 68 | , XMLSize_t childCount |
---|
| 69 | , XMLSize_t* indexFailingChild |
---|
| 70 | , MemoryManager* const manager |
---|
| 71 | ) const; |
---|
| 72 | |
---|
| 73 | virtual bool validateContentSpecial |
---|
| 74 | ( |
---|
| 75 | #ifdef STORE_CHILDREN_INFORMATION_IN_PARSER |
---|
| 76 | XMLElementDecl ** const children |
---|
| 77 | #else |
---|
| 78 | QName** const children |
---|
| 79 | #endif |
---|
| 80 | , XMLSize_t childCount |
---|
| 81 | , GrammarResolver* const pGrammarResolver |
---|
| 82 | , XMLNamespaceResolver* const pUriResolver |
---|
| 83 | , XMLSize_t* indexFailingChild |
---|
| 84 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 85 | ) const; |
---|
| 86 | |
---|
| 87 | virtual void checkUniqueParticleAttribution |
---|
| 88 | ( |
---|
| 89 | SchemaGrammar* const pGrammar |
---|
| 90 | , GrammarResolver* const pGrammarResolver |
---|
| 91 | , XMLNamespaceResolver* const pUriResolver |
---|
| 92 | , XMLValidator* const pValidator |
---|
| 93 | , unsigned int* const pContentSpecOrgURI |
---|
| 94 | , const XMLCh* pComplexTypeName = 0 |
---|
| 95 | ); |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ; |
---|
| 99 | |
---|
| 100 | virtual unsigned int getNextState(unsigned int currentState, |
---|
| 101 | XMLSize_t elementIndex) const; |
---|
| 102 | |
---|
| 103 | virtual bool handleRepetitions( const QName* const curElem, |
---|
| 104 | unsigned int curState, |
---|
| 105 | unsigned int currentLoop, |
---|
| 106 | unsigned int& nextState, |
---|
| 107 | unsigned int& nextLoop, |
---|
| 108 | XMLSize_t elementIndex, |
---|
| 109 | SubstitutionGroupComparator * comparator) const; |
---|
| 110 | |
---|
| 111 | /** @@@ DEPRECATED @@@ **/ |
---|
| 112 | virtual bool validateContent |
---|
| 113 | ( |
---|
| 114 | QName** const children |
---|
| 115 | , XMLSize_t childCount |
---|
| 116 | , unsigned int emptyNamespaceId |
---|
| 117 | , XMLSize_t* indexFailingChild |
---|
| 118 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 119 | ) const; |
---|
| 120 | |
---|
| 121 | /** @@@ DEPRECATED @@@ **/ |
---|
| 122 | virtual bool validateContentSpecial |
---|
| 123 | ( |
---|
| 124 | QName** const children |
---|
| 125 | , XMLSize_t childCount |
---|
| 126 | , unsigned int emptyNamespaceId |
---|
| 127 | , GrammarResolver* const pGrammarResolver |
---|
| 128 | , XMLStringPool* const pStringPool |
---|
| 129 | , XMLSize_t* indexFailingChild |
---|
| 130 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 131 | ) const; |
---|
| 132 | |
---|
| 133 | /** @@@ DEPRECATED @@@ **/ |
---|
| 134 | virtual void checkUniqueParticleAttribution |
---|
| 135 | ( |
---|
| 136 | SchemaGrammar* const pGrammar |
---|
| 137 | , GrammarResolver* const pGrammarResolver |
---|
| 138 | , XMLStringPool* const pStringPool |
---|
| 139 | , XMLValidator* const pValidator |
---|
| 140 | , unsigned int* const pContentSpecOrgURI |
---|
| 141 | , const XMLCh* pComplexTypeName = 0 |
---|
| 142 | ); |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | #ifdef PRINT_DEBUG_MESSAGE |
---|
| 146 | virtual void debug_out(std::ostream & out) const |
---|
| 147 | { |
---|
| 148 | out << "(AllContentModel: " |
---|
| 149 | << fCount |
---|
| 150 | << ','; |
---|
| 151 | if (fCount) |
---|
| 152 | { |
---|
| 153 | char leadingChar = '{'; |
---|
| 154 | for (XMLSize_t i = 0; i < fCount; i++) |
---|
| 155 | { |
---|
| 156 | out << leadingChar << fChildren[i] << ':' << fChildOptional[i]; |
---|
| 157 | leadingChar = ','; |
---|
| 158 | } |
---|
| 159 | out << '}'; |
---|
| 160 | } |
---|
| 161 | out << ',' << fNumRequired |
---|
| 162 | << ',' << fIsMixed |
---|
| 163 | << ',' << fHasOptionalContent |
---|
| 164 | << ')'; |
---|
| 165 | } |
---|
| 166 | #endif |
---|
| 167 | |
---|
| 168 | private : |
---|
| 169 | // ----------------------------------------------------------------------- |
---|
| 170 | // Private helper methods |
---|
| 171 | // ----------------------------------------------------------------------- |
---|
| 172 | void buildChildList |
---|
| 173 | ( |
---|
| 174 | ContentSpecNode* const curNode |
---|
| 175 | , ValueVectorOf<QName*>& toFill |
---|
| 176 | , ValueVectorOf<bool>& toType |
---|
| 177 | ); |
---|
| 178 | |
---|
| 179 | // ----------------------------------------------------------------------- |
---|
| 180 | // Unimplemented constructors and operators |
---|
| 181 | // ----------------------------------------------------------------------- |
---|
| 182 | AllContentModel(); |
---|
| 183 | AllContentModel(const AllContentModel&); |
---|
| 184 | AllContentModel& operator=(const AllContentModel&); |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | // ----------------------------------------------------------------------- |
---|
| 188 | // Private data members |
---|
| 189 | // |
---|
| 190 | // fCount |
---|
| 191 | // The count of possible children in the fChildren member. |
---|
| 192 | // |
---|
| 193 | // fChildren |
---|
| 194 | // The list of possible children that we have to accept. This array |
---|
| 195 | // is allocated as large as needed in the constructor. |
---|
| 196 | // |
---|
| 197 | // fChildOptional |
---|
| 198 | // The corresponding list of optional state of each child in fChildren |
---|
| 199 | // True if the child is optional (i.e. minOccurs = 0). |
---|
| 200 | // |
---|
| 201 | // fNumRequired |
---|
| 202 | // The number of required children in <all> (i.e. minOccurs = 1) |
---|
| 203 | // |
---|
| 204 | // fIsMixed |
---|
| 205 | // AllContentModel with mixed PCDATA. |
---|
| 206 | // ----------------------------------------------------------------------- |
---|
| 207 | MemoryManager* fMemoryManager; |
---|
| 208 | XMLSize_t fCount; |
---|
| 209 | QName** fChildren; |
---|
| 210 | bool* fChildOptional; |
---|
| 211 | unsigned int fNumRequired; |
---|
| 212 | bool fIsMixed; |
---|
| 213 | bool fHasOptionalContent; |
---|
| 214 | }; |
---|
| 215 | |
---|
| 216 | inline ContentLeafNameTypeVector* AllContentModel::getContentLeafNameTypeVector() const |
---|
| 217 | { |
---|
| 218 | return 0; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | inline unsigned int |
---|
| 222 | AllContentModel::getNextState(unsigned int, |
---|
| 223 | XMLSize_t) const { |
---|
| 224 | |
---|
| 225 | return XMLContentModel::gInvalidTrans; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | inline bool |
---|
| 229 | AllContentModel::handleRepetitions( const QName* const /*curElem*/, |
---|
| 230 | unsigned int /*curState*/, |
---|
| 231 | unsigned int /*currentLoop*/, |
---|
| 232 | unsigned int& /*nextState*/, |
---|
| 233 | unsigned int& /*nextLoop*/, |
---|
| 234 | XMLSize_t /*elementIndex*/, |
---|
| 235 | SubstitutionGroupComparator * /*comparator*/) const |
---|
| 236 | { |
---|
| 237 | return true; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | XERCES_CPP_NAMESPACE_END |
---|
| 241 | |
---|
| 242 | #endif |
---|