Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:34:31

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_MIXEDCONTENTMODEL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_MIXEDCONTENTMODEL_HPP
0024 
0025 #include <xercesc/util/ValueVectorOf.hpp>
0026 #include <xercesc/framework/XMLContentModel.hpp>
0027 #include <xercesc/validators/common/ContentLeafNameTypeVector.hpp>
0028 
0029 XERCES_CPP_NAMESPACE_BEGIN
0030 
0031 class ContentSpecNode;
0032 
0033 //
0034 //  MixedContentModel is a derivative of the abstract content model base
0035 //  class that handles the special case of mixed model elements. If an element
0036 //  is mixed model, it has PCDATA as its first possible content, followed
0037 //  by an alternation of the possible children. The children cannot have any
0038 //  numeration or order, so it must look like this:
0039 //
0040 //  <!ELEMENT Foo ((#PCDATA|a|b|c|)*)>
0041 //
0042 //  So, all we have to do is to keep an array of the possible children and
0043 //  validate by just looking up each child being validated by looking it up
0044 //  in the list.
0045 //
0046 class MixedContentModel : public XMLContentModel
0047 {
0048 public :
0049     // -----------------------------------------------------------------------
0050     //  Constructors and Destructor
0051     // -----------------------------------------------------------------------
0052     MixedContentModel
0053     (
0054         const bool                dtd
0055         , ContentSpecNode* const  parentContentSpec
0056         , const bool              ordered = false
0057         , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
0058     );
0059 
0060     ~MixedContentModel();
0061 
0062 
0063     // -----------------------------------------------------------------------
0064     //  Getter methods
0065     // -----------------------------------------------------------------------
0066     bool hasDups() const;
0067 
0068     // -----------------------------------------------------------------------
0069     //  Implementation of the ContentModel virtual interface
0070     // -----------------------------------------------------------------------
0071     virtual bool validateContent
0072     (
0073         QName** const         children
0074       , XMLSize_t             childCount
0075       , unsigned int          emptyNamespaceId
0076       , XMLSize_t*            indexFailingChild
0077       , MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
0078     )   const;
0079 
0080     virtual bool validateContentSpecial
0081     (
0082         QName** const           children
0083       , XMLSize_t               childCount
0084       , unsigned int            emptyNamespaceId
0085       , GrammarResolver*  const pGrammarResolver
0086       , XMLStringPool*    const pStringPool
0087       , XMLSize_t*              indexFailingChild
0088       , MemoryManager*    const manager = XMLPlatformUtils::fgMemoryManager
0089     ) const;
0090 
0091     virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ;
0092 
0093     virtual unsigned int getNextState(unsigned int currentState,
0094                                       XMLSize_t    elementIndex) const;
0095 
0096     virtual bool handleRepetitions( const QName* const curElem,
0097                                     unsigned int curState,
0098                                     unsigned int currentLoop,
0099                                     unsigned int& nextState,
0100                                     unsigned int& nextLoop,
0101                                     XMLSize_t elementIndex,
0102                                     SubstitutionGroupComparator * comparator) const;
0103 
0104     virtual void checkUniqueParticleAttribution
0105     (
0106         SchemaGrammar*    const pGrammar
0107       , GrammarResolver*  const pGrammarResolver
0108       , XMLStringPool*    const pStringPool
0109       , XMLValidator*     const pValidator
0110       , unsigned int*     const pContentSpecOrgURI
0111       , const XMLCh*            pComplexTypeName = 0
0112     ) ;
0113 
0114 private :
0115     // -----------------------------------------------------------------------
0116     //  Private helper methods
0117     // -----------------------------------------------------------------------
0118     void buildChildList
0119     (
0120         ContentSpecNode* const                     curNode
0121       , ValueVectorOf<QName*>&                     toFill
0122       , ValueVectorOf<ContentSpecNode::NodeTypes>& toType
0123     );
0124 
0125     // -----------------------------------------------------------------------
0126     //  Unimplemented constructors and operators
0127     // -----------------------------------------------------------------------
0128     MixedContentModel();
0129     MixedContentModel(const MixedContentModel&);
0130     MixedContentModel& operator=(const MixedContentModel&);
0131 
0132 
0133     // -----------------------------------------------------------------------
0134     //  Private data members
0135     //
0136     //  fCount
0137     //      The count of possible children in the fChildren member.
0138     //
0139     //  fChildren
0140     //      The list of possible children that we have to accept. This array
0141     //      is allocated as large as needed in the constructor.
0142     //
0143     //  fChildTypes
0144     //      The type of the children to support ANY.
0145     //
0146     //  fOrdered
0147     //      True if mixed content model is ordered. DTD mixed content models
0148     //      are <em>always</em> unordered.
0149     //
0150     //  fDTD
0151     //      Boolean to allow DTDs to validate even with namespace support.
0152     //
0153     // -----------------------------------------------------------------------
0154     XMLSize_t                   fCount;
0155     QName**                     fChildren;
0156     ContentSpecNode::NodeTypes* fChildTypes;
0157     bool                        fOrdered;
0158     bool                        fDTD;
0159     MemoryManager*              fMemoryManager;
0160 };
0161 
0162 inline ContentLeafNameTypeVector* MixedContentModel::getContentLeafNameTypeVector() const
0163 {
0164     return 0;
0165 }
0166 
0167 inline unsigned int
0168 MixedContentModel::getNextState(unsigned int,
0169                                 XMLSize_t) const {
0170 
0171     return XMLContentModel::gInvalidTrans;
0172 }
0173 
0174 inline bool
0175 MixedContentModel::handleRepetitions( const QName* const /*curElem*/,
0176                                       unsigned int /*curState*/,
0177                                       unsigned int /*currentLoop*/,
0178                                       unsigned int& /*nextState*/,
0179                                       unsigned int& /*nextLoop*/,
0180                                       XMLSize_t /*elementIndex*/,
0181                                       SubstitutionGroupComparator * /*comparator*/) const
0182 {
0183     return true;
0184 }
0185 
0186 inline void MixedContentModel::checkUniqueParticleAttribution
0187     (
0188         SchemaGrammar*    const
0189       , GrammarResolver*  const
0190       , XMLStringPool*    const
0191       , XMLValidator*     const
0192       , unsigned int*     const pContentSpecOrgURI
0193       , const XMLCh*            /*pComplexTypeName*/ /*= 0*/
0194     )
0195 {
0196     // rename back
0197     unsigned int i = 0;
0198     for (i = 0; i < fCount; i++) {
0199         unsigned int orgURIIndex = fChildren[i]->getURI();
0200         if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
0201             (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
0202             (orgURIIndex != XMLElementDecl::fgPCDataElemId))
0203             fChildren[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
0204     }
0205 
0206     // for mixed content model, it's only a sequence
0207     // UPA checking is not necessary
0208 }
0209 
0210 XERCES_CPP_NAMESPACE_END
0211 
0212 #endif