Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:19

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_XPATHMATCHER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XPATHMATCHER_HPP
0024 
0025 
0026 // ---------------------------------------------------------------------------
0027 //  Includes
0028 // ---------------------------------------------------------------------------
0029 #include <xercesc/util/ValueStackOf.hpp>
0030 #include <xercesc/util/RefVectorOf.hpp>
0031 #include <xercesc/framework/XMLBuffer.hpp>
0032 
0033 XERCES_CPP_NAMESPACE_BEGIN
0034 
0035 // ---------------------------------------------------------------------------
0036 //  Forward Declaration
0037 // ---------------------------------------------------------------------------
0038 class XMLElementDecl;
0039 class XercesXPath;
0040 class IdentityConstraint;
0041 class DatatypeValidator;
0042 class XMLStringPool;
0043 class XercesLocationPath;
0044 class XMLAttr;
0045 class XercesNodeTest;
0046 class QName;
0047 class ValidationContext;
0048 
0049 class VALIDATORS_EXPORT XPathMatcher : public XMemory
0050 {
0051 public:
0052     // -----------------------------------------------------------------------
0053     //  Constructors/Destructor
0054     // -----------------------------------------------------------------------
0055     XPathMatcher(XercesXPath* const xpath,
0056                  MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0057     XPathMatcher(XercesXPath* const xpath,
0058                  IdentityConstraint* const ic,
0059                  MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0060     virtual ~XPathMatcher();
0061 
0062     // -----------------------------------------------------------------------
0063     //  Getter methods
0064     // -----------------------------------------------------------------------
0065     IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
0066     MemoryManager* getMemoryManager() const { return fMemoryManager; }
0067 
0068     // -----------------------------------------------------------------------
0069     //  Match methods
0070     // -----------------------------------------------------------------------
0071     /**
0072       * Returns true if XPath has been matched.
0073       */
0074     unsigned char isMatched();
0075     virtual int getInitialDepth() const;
0076 
0077     // -----------------------------------------------------------------------
0078     //  XMLDocumentHandler methods
0079     // -----------------------------------------------------------------------
0080     virtual void startDocumentFragment();
0081     virtual void startElement(const XMLElementDecl& elemDecl,
0082                               const unsigned int urlId,
0083                               const XMLCh* const elemPrefix,
0084                               const RefVectorOf<XMLAttr>& attrList,
0085                               const XMLSize_t attrCount,
0086                               ValidationContext* validationContext = 0);
0087     virtual void endElement(const XMLElementDecl& elemDecl,
0088                             const XMLCh* const elemContent,
0089                             ValidationContext* validationContext = 0,
0090                             DatatypeValidator* actualValidator = 0);
0091 
0092     enum
0093     {
0094         XP_MATCHED = 1        // matched any way
0095         , XP_MATCHED_A = 3    // matched on the attribute axis
0096         , XP_MATCHED_D = 5    // matched on the descendant-or-self axixs
0097         , XP_MATCHED_DP = 13  // matched some previous (ancestor) node on the
0098                               // descendant-or-self-axis, but not this node
0099     };
0100 
0101 protected:
0102 
0103     // -----------------------------------------------------------------------
0104     //  Match methods
0105     // -----------------------------------------------------------------------
0106     /**
0107       * This method is called when the XPath handler matches the XPath
0108       * expression. Subclasses can override this method to provide default
0109       * handling upon a match.
0110       */
0111     virtual void matched(const XMLCh* const content,
0112                          DatatypeValidator* const dv, const bool isNil);
0113 
0114     bool matches(const XercesNodeTest* nodeTest, const QName* qName);
0115 
0116 private:
0117     // -----------------------------------------------------------------------
0118     //  Unimplemented constructors and operators
0119     // -----------------------------------------------------------------------
0120     XPathMatcher(const XPathMatcher&);
0121     XPathMatcher& operator=(const XPathMatcher&);
0122 
0123     // -----------------------------------------------------------------------
0124     //  Helper methods
0125     // -----------------------------------------------------------------------
0126     void init(XercesXPath* const xpath);
0127     void cleanUp();
0128 
0129 protected:
0130     // -----------------------------------------------------------------------
0131     //  Data members
0132     //
0133     //  fMatched
0134     //      Indicates whether XPath has been matched or not
0135     //
0136     //  fNoMatchDepth
0137     //      Indicates whether matching is successful for the given xpath
0138     //      expression.
0139     //
0140     //  fCurrentStep
0141     //      Stores current step.
0142     //
0143     //  fStepIndexes
0144     //      Integer stack of step indexes.
0145     //
0146     //  fLocationPaths
0147     //  fLocationPathSize
0148     //      XPath location path, and its size.
0149     //
0150     //  fIdentityConstraint
0151     //      The identity constraint we're the matcher for.  Only used for
0152     //      selectors.
0153     //
0154     // -----------------------------------------------------------------------
0155     XMLSize_t                               fLocationPathSize;
0156     unsigned char*                          fMatched;
0157     XMLSize_t*                              fNoMatchDepth;
0158     XMLSize_t*                              fCurrentStep;
0159     RefVectorOf<ValueStackOf<XMLSize_t> >*  fStepIndexes;
0160     RefVectorOf<XercesLocationPath>*        fLocationPaths;
0161     IdentityConstraint*                     fIdentityConstraint;
0162     MemoryManager*                          fMemoryManager;
0163 };
0164 
0165 // ---------------------------------------------------------------------------
0166 //  XPathMatcher: Helper methods
0167 // ---------------------------------------------------------------------------
0168 inline void XPathMatcher::cleanUp() {
0169 
0170     fMemoryManager->deallocate(fMatched);//delete [] fMatched;
0171     fMemoryManager->deallocate(fNoMatchDepth);//delete [] fNoMatchDepth;
0172     fMemoryManager->deallocate(fCurrentStep);//delete [] fCurrentStep;
0173     delete fStepIndexes;
0174 }
0175 
0176 XERCES_CPP_NAMESPACE_END
0177 
0178 #endif
0179 
0180 /**
0181   * End of file XPathMatcher.hpp
0182   */
0183