IC_Selector.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:8k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: IC_Selector.cpp,v $
  58.  * Revision 1.5  2003/05/15 18:59:34  knoaman
  59.  * Partial implementation of the configurable memory manager.
  60.  *
  61.  * Revision 1.4  2003/01/13 16:30:19  knoaman
  62.  * [Bug 14469] Validator doesn't enforce xsd:key.
  63.  *
  64.  * Revision 1.3  2002/11/04 14:47:41  tng
  65.  * C++ Namespace Support.
  66.  *
  67.  * Revision 1.2  2002/08/27 05:56:19  knoaman
  68.  * Identity Constraint: handle case of recursive elements.
  69.  *
  70.  * Revision 1.1.1.1  2002/02/01 22:22:50  peiyongz
  71.  * sane_include
  72.  *
  73.  * Revision 1.3  2001/11/23 18:35:33  tng
  74.  * Eliminate Warning from AIX xlC 3.6:1540-399: (W) "XMLAttr" is undefined.  The delete operator will not call a destructor.
  75.  *
  76.  * Revision 1.2  2001/11/15 17:10:19  knoaman
  77.  * Particle derivation checking support.
  78.  *
  79.  * Revision 1.1  2001/11/02 14:08:40  knoaman
  80.  * Add support for identity constraints.
  81.  *
  82.  */
  83. // ---------------------------------------------------------------------------
  84. //  Includes
  85. // ---------------------------------------------------------------------------
  86. #include <xercesc/framework/XMLAttr.hpp>
  87. #include <xercesc/validators/schema/identity/IC_Selector.hpp>
  88. #include <xercesc/validators/schema/identity/XercesXPath.hpp>
  89. #include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
  90. #include <xercesc/validators/schema/identity/FieldActivator.hpp>
  91. XERCES_CPP_NAMESPACE_BEGIN
  92. // ---------------------------------------------------------------------------
  93. //  SelectorMatcher: Constructors and Destructor
  94. // ---------------------------------------------------------------------------
  95. SelectorMatcher::SelectorMatcher(XercesXPath* const xpath,
  96.                                  IC_Selector* const selector,
  97.                                  FieldActivator* const fieldActivator,
  98.                                  const int initialDepth,
  99.                                  MemoryManager* const manager)
  100.     : XPathMatcher(xpath, selector->getIdentityConstraint(), manager)
  101.     , fInitialDepth(initialDepth)
  102.     , fElementDepth(0)
  103.     , fMatchedDepth(-1)
  104.     , fSelector(selector)
  105.     , fFieldActivator(fieldActivator)
  106. {
  107. }
  108. // ---------------------------------------------------------------------------
  109. //  FieldMatcher: XMLDocumentHandler methods
  110. // ---------------------------------------------------------------------------
  111. void SelectorMatcher::startDocumentFragment() {
  112.     XPathMatcher::startDocumentFragment();
  113.     fElementDepth = 0;
  114.     fMatchedDepth = -1;
  115. }
  116. void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
  117.                                    const unsigned int urlId,
  118.                                    const XMLCh* const elemPrefix,
  119.                                    const RefVectorOf<XMLAttr>& attrList,
  120.                                    const unsigned int attrCount) {
  121.     XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
  122.     fElementDepth++;
  123.     // activate the fields, if selector is matched
  124.     int matched = isMatched();
  125.     if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
  126.         || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {
  127.         IdentityConstraint* ic = fSelector->getIdentityConstraint();
  128.         int count = ic->getFieldCount();
  129.         fMatchedDepth = fElementDepth;
  130.         fFieldActivator->startValueScopeFor(ic, fInitialDepth);
  131.         for (int i = 0; i < count; i++) {
  132.             XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
  133.             matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
  134.         }
  135.     }
  136. }
  137. void SelectorMatcher::endElement(const XMLElementDecl& elemDecl,
  138.                                  const XMLCh* const elemContent) {
  139.     XPathMatcher::endElement(elemDecl, elemContent);
  140.     if (fElementDepth-- == fMatchedDepth) {
  141.         fMatchedDepth = -1;
  142.         fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), fInitialDepth);
  143.     }
  144. }
  145. // ---------------------------------------------------------------------------
  146. //  IC_Selector: Constructors and Destructor
  147. // ---------------------------------------------------------------------------
  148. IC_Selector::IC_Selector(XercesXPath* const xpath,
  149.                          IdentityConstraint* const identityConstraint)
  150.     : fXPath(xpath)
  151.     , fIdentityConstraint(identityConstraint)
  152. {
  153. }
  154. IC_Selector::~IC_Selector()
  155. {
  156.     delete fXPath;
  157. }
  158. // ---------------------------------------------------------------------------
  159. //  IC_Selector: operators
  160. // ---------------------------------------------------------------------------
  161. bool IC_Selector::operator ==(const IC_Selector& other) const {
  162.     return (*fXPath == *(other.fXPath));
  163. }
  164. bool IC_Selector::operator !=(const IC_Selector& other) const {
  165.     return !operator==(other);
  166. }
  167. // ---------------------------------------------------------------------------
  168. //  IC_Selector: Factory methods
  169. // ---------------------------------------------------------------------------
  170. XPathMatcher* IC_Selector::createMatcher(FieldActivator* const fieldActivator,
  171.                                          const int initialDepth,
  172.                                          MemoryManager* const manager) {
  173.     return new (manager) SelectorMatcher(fXPath, this, fieldActivator, initialDepth, manager);
  174. }
  175. XERCES_CPP_NAMESPACE_END
  176. /**
  177.   * End of file IC_Selector.cpp
  178.   */