IC_Selector.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

C/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.3  2001/11/23 18:35:33  tng
  59.  * Eliminate Warning from AIX xlC 3.6:1540-399: (W) "XMLAttr" is undefined.  The delete operator will not call a destructor.
  60.  *
  61.  * Revision 1.2  2001/11/15 17:10:19  knoaman
  62.  * Particle derivation checking support.
  63.  *
  64.  * Revision 1.1  2001/11/02 14:08:40  knoaman
  65.  * Add support for identity constraints.
  66.  *
  67.  */
  68. // ---------------------------------------------------------------------------
  69. //  Includes
  70. // ---------------------------------------------------------------------------
  71. #include <framework/XMLAttr.hpp>
  72. #include <validators/schema/identity/IC_Selector.hpp>
  73. #include <validators/schema/identity/XercesXPath.hpp>
  74. #include <validators/schema/identity/IdentityConstraint.hpp>
  75. #include <validators/schema/identity/FieldActivator.hpp>
  76. // ---------------------------------------------------------------------------
  77. //  SelectorMatcher: Constructors and Destructor
  78. // ---------------------------------------------------------------------------
  79. SelectorMatcher::SelectorMatcher(XercesXPath* const xpath,
  80.                                  IC_Selector* const selector,
  81.                                  FieldActivator* const fieldActivator)
  82.     : XPathMatcher(xpath, false, selector->getIdentityConstraint())
  83.     , fElementDepth(0)
  84.     , fMatchedDepth(-1)
  85.     , fSelector(selector)
  86.     , fFieldActivator(fieldActivator)
  87. {
  88. }
  89. // ---------------------------------------------------------------------------
  90. //  FieldMatcher: XMLDocumentHandler methods
  91. // ---------------------------------------------------------------------------
  92. void SelectorMatcher::startDocumentFragment() {
  93.     XPathMatcher::startDocumentFragment();
  94.     fElementDepth = 0;
  95.     fMatchedDepth = -1;
  96. }
  97. void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
  98.                                    const unsigned int urlId,
  99.                                    const XMLCh* const elemPrefix,
  100.                                    const RefVectorOf<XMLAttr>& attrList,
  101.                                    const unsigned int attrCount) {
  102.     XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
  103.     fElementDepth++;
  104.     // activate the fields, if selector is matched
  105.     if (fMatchedDepth == -1 && isMatched()) {
  106.         IdentityConstraint* ic = fSelector->getIdentityConstraint();
  107.         int count = ic->getFieldCount();
  108.         fMatchedDepth = fElementDepth;
  109.         fFieldActivator->startValueScopeFor(ic);
  110.         for (int i = 0; i < count; i++) {
  111.             IC_Field* field = ic->getFieldAt(i);
  112.             XPathMatcher* matcher = fFieldActivator->activateField(field);
  113.             matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
  114.         }
  115.     }
  116. }
  117. void SelectorMatcher::endElement(const XMLElementDecl& elemDecl) {
  118.     XPathMatcher::endElement(elemDecl);
  119.     if (fElementDepth-- == fMatchedDepth) {
  120.         fMatchedDepth = -1;
  121.         fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint());
  122.     }
  123. }
  124. // ---------------------------------------------------------------------------
  125. //  IC_Selector: Constructors and Destructor
  126. // ---------------------------------------------------------------------------
  127. IC_Selector::IC_Selector(XercesXPath* const xpath,
  128.                          IdentityConstraint* const identityConstraint)
  129.     : fXPath(xpath)
  130.     , fIdentityConstraint(identityConstraint)
  131. {
  132. }
  133. IC_Selector::~IC_Selector()
  134. {
  135.     delete fXPath;
  136. }
  137. // ---------------------------------------------------------------------------
  138. //  IC_Selector: operators
  139. // ---------------------------------------------------------------------------
  140. bool IC_Selector::operator ==(const IC_Selector& other) const {
  141.     return (*fXPath == *(other.fXPath));
  142. }
  143. bool IC_Selector::operator !=(const IC_Selector& other) const {
  144.     return !operator==(other);
  145. }
  146. // ---------------------------------------------------------------------------
  147. //  IC_Selector: Factory methods
  148. // ---------------------------------------------------------------------------
  149. XPathMatcher* IC_Selector::createMatcher(FieldActivator* const fieldActivator) {
  150.     return new SelectorMatcher(fXPath, this, fieldActivator);
  151. }
  152. /**
  153.   * End of file IC_Selector.cpp
  154.   */