[2674] | 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: MixedContentModel.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #if !defined(MIXEDCONTENTMODEL_HPP) |
---|
| 24 | #define MIXEDCONTENTMODEL_HPP |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/ValueVectorOf.hpp> |
---|
| 27 | #include <xercesc/framework/XMLContentModel.hpp> |
---|
| 28 | #include <xercesc/validators/common/ContentLeafNameTypeVector.hpp> |
---|
| 29 | |
---|
| 30 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 31 | |
---|
| 32 | class ContentSpecNode; |
---|
| 33 | |
---|
| 34 | // |
---|
| 35 | // MixedContentModel is a derivative of the abstract content model base |
---|
| 36 | // class that handles the special case of mixed model elements. If an element |
---|
| 37 | // is mixed model, it has PCDATA as its first possible content, followed |
---|
| 38 | // by an alternation of the possible children. The children cannot have any |
---|
| 39 | // numeration or order, so it must look like this: |
---|
| 40 | // |
---|
| 41 | // <!ELEMENT Foo ((#PCDATA|a|b|c|)*)> |
---|
| 42 | // |
---|
| 43 | // So, all we have to do is to keep an array of the possible children and |
---|
| 44 | // validate by just looking up each child being validated by looking it up |
---|
| 45 | // in the list. |
---|
| 46 | // |
---|
| 47 | class MixedContentModel : public XMLContentModel |
---|
| 48 | { |
---|
| 49 | public : |
---|
| 50 | // ----------------------------------------------------------------------- |
---|
| 51 | // Constructors and Destructor |
---|
| 52 | // ----------------------------------------------------------------------- |
---|
| 53 | MixedContentModel |
---|
| 54 | ( |
---|
| 55 | const bool dtd |
---|
| 56 | , ContentSpecNode* const parentContentSpec |
---|
| 57 | , const bool ordered = false |
---|
| 58 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 59 | ); |
---|
| 60 | |
---|
| 61 | ~MixedContentModel(); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // ----------------------------------------------------------------------- |
---|
| 65 | // Getter methods |
---|
| 66 | // ----------------------------------------------------------------------- |
---|
| 67 | bool hasDups() const; |
---|
| 68 | |
---|
| 69 | // ----------------------------------------------------------------------- |
---|
| 70 | // Implementation of the ContentModel virtual interface |
---|
| 71 | // ----------------------------------------------------------------------- |
---|
| 72 | virtual int validateContent |
---|
| 73 | ( |
---|
| 74 | QName** const children |
---|
| 75 | , const unsigned int childCount |
---|
| 76 | , const unsigned int emptyNamespaceId |
---|
| 77 | ) const; |
---|
| 78 | |
---|
| 79 | virtual int validateContentSpecial |
---|
| 80 | ( |
---|
| 81 | QName** const children |
---|
| 82 | , const unsigned int childCount |
---|
| 83 | , const unsigned int emptyNamespaceId |
---|
| 84 | , GrammarResolver* const pGrammarResolver |
---|
| 85 | , XMLStringPool* const pStringPool |
---|
| 86 | ) const; |
---|
| 87 | |
---|
| 88 | virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ; |
---|
| 89 | |
---|
| 90 | virtual unsigned int getNextState(const unsigned int currentState, |
---|
| 91 | const unsigned int elementIndex) const; |
---|
| 92 | |
---|
| 93 | virtual void checkUniqueParticleAttribution |
---|
| 94 | ( |
---|
| 95 | SchemaGrammar* const pGrammar |
---|
| 96 | , GrammarResolver* const pGrammarResolver |
---|
| 97 | , XMLStringPool* const pStringPool |
---|
| 98 | , XMLValidator* const pValidator |
---|
| 99 | , unsigned int* const pContentSpecOrgURI |
---|
| 100 | , const XMLCh* pComplexTypeName = 0 |
---|
| 101 | ) ; |
---|
| 102 | |
---|
| 103 | private : |
---|
| 104 | // ----------------------------------------------------------------------- |
---|
| 105 | // Private helper methods |
---|
| 106 | // ----------------------------------------------------------------------- |
---|
| 107 | void buildChildList |
---|
| 108 | ( |
---|
| 109 | ContentSpecNode* const curNode |
---|
| 110 | , ValueVectorOf<QName*>& toFill |
---|
| 111 | , ValueVectorOf<ContentSpecNode::NodeTypes>& toType |
---|
| 112 | ); |
---|
| 113 | |
---|
| 114 | // ----------------------------------------------------------------------- |
---|
| 115 | // Unimplemented constructors and operators |
---|
| 116 | // ----------------------------------------------------------------------- |
---|
| 117 | MixedContentModel(); |
---|
| 118 | MixedContentModel(const MixedContentModel&); |
---|
| 119 | MixedContentModel& operator=(const MixedContentModel&); |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | // ----------------------------------------------------------------------- |
---|
| 123 | // Private data members |
---|
| 124 | // |
---|
| 125 | // fCount |
---|
| 126 | // The count of possible children in the fChildren member. |
---|
| 127 | // |
---|
| 128 | // fChildren |
---|
| 129 | // The list of possible children that we have to accept. This array |
---|
| 130 | // is allocated as large as needed in the constructor. |
---|
| 131 | // |
---|
| 132 | // fChildTypes |
---|
| 133 | // The type of the children to support ANY. |
---|
| 134 | // |
---|
| 135 | // fOrdered |
---|
| 136 | // True if mixed content model is ordered. DTD mixed content models |
---|
| 137 | // are <em>always</em> unordered. |
---|
| 138 | // |
---|
| 139 | // fDTD |
---|
| 140 | // Boolean to allow DTDs to validate even with namespace support. |
---|
| 141 | // |
---|
| 142 | // ----------------------------------------------------------------------- |
---|
| 143 | unsigned int fCount; |
---|
| 144 | QName** fChildren; |
---|
| 145 | ContentSpecNode::NodeTypes* fChildTypes; |
---|
| 146 | bool fOrdered; |
---|
| 147 | bool fDTD; |
---|
| 148 | MemoryManager* fMemoryManager; |
---|
| 149 | }; |
---|
| 150 | |
---|
| 151 | inline ContentLeafNameTypeVector* MixedContentModel::getContentLeafNameTypeVector() const |
---|
| 152 | { |
---|
| 153 | return 0; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | inline unsigned int |
---|
| 157 | MixedContentModel::getNextState(const unsigned int, |
---|
| 158 | const unsigned int) const { |
---|
| 159 | |
---|
| 160 | return XMLContentModel::gInvalidTrans; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | inline void MixedContentModel::checkUniqueParticleAttribution |
---|
| 164 | ( |
---|
| 165 | SchemaGrammar* const |
---|
| 166 | , GrammarResolver* const |
---|
| 167 | , XMLStringPool* const |
---|
| 168 | , XMLValidator* const |
---|
| 169 | , unsigned int* const pContentSpecOrgURI |
---|
| 170 | , const XMLCh* /*pComplexTypeName*/ /*= 0*/ |
---|
| 171 | ) |
---|
| 172 | { |
---|
| 173 | // rename back |
---|
| 174 | unsigned int i = 0; |
---|
| 175 | for (i = 0; i < fCount; i++) { |
---|
| 176 | unsigned int orgURIIndex = fChildren[i]->getURI(); |
---|
| 177 | if ((orgURIIndex != XMLContentModel::gEOCFakeId) && |
---|
| 178 | (orgURIIndex != XMLElementDecl::fgInvalidElemId) && |
---|
| 179 | (orgURIIndex != XMLElementDecl::fgPCDataElemId)) |
---|
| 180 | fChildren[i]->setURI(pContentSpecOrgURI[orgURIIndex]); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | // for mixed content model, it's only a sequence |
---|
| 184 | // UPA checking is not necessary |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | XERCES_CPP_NAMESPACE_END |
---|
| 188 | |
---|
| 189 | #endif |
---|