source: icXML/icXML-devel/src/xercesc/validators/schema/identity/IC_Selector.cpp @ 3565

Last change on this file since 3565 was 3565, checked in by cameron, 6 years ago

Updates to xercesc sources

File size: 6.5 KB
Line 
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: IC_Selector.cpp 803869 2009-08-13 12:56:21Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <icxercesc/framework/XMLAttr.hpp>
26#include <xercesc/validators/schema/identity/IC_Selector.hpp>
27#include <xercesc/validators/schema/identity/XercesXPath.hpp>
28#include <icxercesc/validators/schema/identity/IdentityConstraint.hpp>
29#include <xercesc/validators/schema/identity/FieldActivator.hpp>
30#include <xercesc/util/StringPool.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34// ---------------------------------------------------------------------------
35//  SelectorMatcher: Constructors and Destructor
36// ---------------------------------------------------------------------------
37SelectorMatcher::SelectorMatcher
38(
39    XercesXPath* const xpath
40    , IC_Selector* const selector
41    , FieldActivator* const fieldActivator
42    , const int initialDepth
43    , XMLStringPool * stringPool
44    , MemoryManager* const manager
45)
46: XPathMatcher(xpath, selector->getIdentityConstraint(), stringPool, manager)
47, fInitialDepth(initialDepth)
48, fElementDepth(0)
49, fMatchedDepth(-1)
50, fSelector(selector)
51, fStringPool(stringPool)
52, fFieldActivator(fieldActivator)
53{
54
55}
56
57
58
59// ---------------------------------------------------------------------------
60//  FieldMatcher: XMLDocumentHandler methods
61// ---------------------------------------------------------------------------
62void SelectorMatcher::startDocumentFragment() {
63
64    XPathMatcher::startDocumentFragment();
65    fElementDepth = 0;
66    fMatchedDepth = -1;
67}
68
69void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
70                                   const unsigned int urlId,
71                                   const XMLCh* const elemPrefix,
72                                   const RefVectorOf<XMLAttr>& attrList,
73                                   const XMLSize_t attrCount,
74                                   ValidationContext* validationContext /*=0*/) 
75{
76
77    XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext);
78    fElementDepth++;
79
80    // activate the fields, if selector is matched
81    unsigned char matched = isMatched();
82    if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED)) || ((matched & XP_MATCHED_D) == XP_MATCHED_D))
83    {
84        IdentityConstraint* ic = fSelector->getIdentityConstraint();
85        XMLSize_t count = ic->getFieldCount();
86
87        fMatchedDepth = fElementDepth;
88        fFieldActivator->startValueScopeFor(ic, fInitialDepth);
89
90        for (XMLSize_t i = 0; i < count; i++)
91        {
92            XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fStringPool, fInitialDepth);
93            matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext);
94        }
95    }
96}
97
98void SelectorMatcher::endElement(const XMLElementDecl& elemDecl,
99                                 const XMLCh* const elemContent, 
100                                 ValidationContext* validationContext /*=0*/,
101                                 DatatypeValidator* actualValidator /*=0*/) 
102{
103
104    XPathMatcher::endElement(elemDecl, elemContent, validationContext, actualValidator);
105
106    if (fElementDepth-- == fMatchedDepth) {
107
108        fMatchedDepth = -1;
109        fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), fInitialDepth);
110    }
111}
112
113// ---------------------------------------------------------------------------
114//  IC_Selector: Constructors and Destructor
115// ---------------------------------------------------------------------------
116IC_Selector::IC_Selector(XercesXPath* const xpath,
117                         IdentityConstraint* const identityConstraint)
118    : fXPath(xpath)
119    , fIdentityConstraint(identityConstraint)
120{
121}
122
123
124IC_Selector::~IC_Selector()
125{
126    delete fXPath;
127}
128
129// ---------------------------------------------------------------------------
130//  IC_Selector: operators
131// ---------------------------------------------------------------------------
132bool IC_Selector::operator ==(const IC_Selector& other) const {
133
134    return (*fXPath == *(other.fXPath));
135}
136
137bool IC_Selector::operator !=(const IC_Selector& other) const {
138
139    return !operator==(other);
140}
141
142// ---------------------------------------------------------------------------
143//  IC_Selector: Factory methods
144// ---------------------------------------------------------------------------
145XPathMatcher* IC_Selector::createMatcher
146(
147    FieldActivator* const   fieldActivator
148    , const int             initialDepth
149    , XMLStringPool *       stringPool
150    , MemoryManager * const manager
151)
152{
153    return new (manager) SelectorMatcher(fXPath, this, fieldActivator, initialDepth, stringPool, manager);
154}
155
156/***
157 * Support for Serialization/De-serialization
158 ***/
159
160IMPL_XSERIALIZABLE_TOCREATE(IC_Selector)
161
162void IC_Selector::serialize(XSerializeEngine& serEng)
163{
164    if (serEng.isStoring())
165    {
166        serEng<<fXPath;
167       
168        IdentityConstraint::storeIC(serEng, fIdentityConstraint);
169    }
170    else
171    {
172        serEng>>fXPath;
173
174        fIdentityConstraint = IdentityConstraint::loadIC(serEng);
175    }
176
177}
178
179IC_Selector::IC_Selector(MemoryManager* const )
180:fXPath(0)
181,fIdentityConstraint(0)
182{
183}
184
185XPathMatcher* IC_Selector::createMatcher
186(
187    FieldActivator* const
188    , const int
189    , MemoryManager* const
190)
191{
192    DEPRECATED_FEATURE_IN_ICXML;
193}
194
195SelectorMatcher::SelectorMatcher(XercesXPath* const,
196                                 IC_Selector* const,
197                                 FieldActivator* const,
198                                 const int,
199                                 MemoryManager* const)
200: XPathMatcher(NULL, NULL, NULL, NULL)
201{
202    DEPRECATED_FEATURE_IN_ICXML;
203}
204
205XERCES_CPP_NAMESPACE_END
206
207/**
208  * End of file IC_Selector.cpp
209  */
210
Note: See TracBrowser for help on using the repository browser.