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 | |
---|
31 | XERCES_CPP_NAMESPACE_BEGIN |
---|
32 | |
---|
33 | // --------------------------------------------------------------------------- |
---|
34 | // SelectorMatcher: Constructors and Destructor |
---|
35 | // --------------------------------------------------------------------------- |
---|
36 | SelectorMatcher::SelectorMatcher(XercesXPath* const xpath, |
---|
37 | IC_Selector* const selector, |
---|
38 | FieldActivator* const fieldActivator, |
---|
39 | const int initialDepth, |
---|
40 | MemoryManager* const manager) |
---|
41 | : XPathMatcher(xpath, selector->getIdentityConstraint(), manager) |
---|
42 | , fInitialDepth(initialDepth) |
---|
43 | , fElementDepth(0) |
---|
44 | , fMatchedDepth(-1) |
---|
45 | , fSelector(selector) |
---|
46 | , fFieldActivator(fieldActivator) |
---|
47 | { |
---|
48 | } |
---|
49 | |
---|
50 | // --------------------------------------------------------------------------- |
---|
51 | // FieldMatcher: XMLDocumentHandler methods |
---|
52 | // --------------------------------------------------------------------------- |
---|
53 | void SelectorMatcher::startDocumentFragment() { |
---|
54 | |
---|
55 | XPathMatcher::startDocumentFragment(); |
---|
56 | fElementDepth = 0; |
---|
57 | fMatchedDepth = -1; |
---|
58 | } |
---|
59 | |
---|
60 | void SelectorMatcher::startElement(const XMLElementDecl& elemDecl, |
---|
61 | const unsigned int urlId, |
---|
62 | const XMLCh* const elemPrefix, |
---|
63 | const RefVectorOf<XMLAttr>& attrList, |
---|
64 | const XMLSize_t attrCount, |
---|
65 | ValidationContext* validationContext /*=0*/) |
---|
66 | { |
---|
67 | |
---|
68 | XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext); |
---|
69 | fElementDepth++; |
---|
70 | |
---|
71 | // activate the fields, if selector is matched |
---|
72 | unsigned char matched = isMatched(); |
---|
73 | if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED)) |
---|
74 | || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) { |
---|
75 | |
---|
76 | IdentityConstraint* ic = fSelector->getIdentityConstraint(); |
---|
77 | XMLSize_t count = ic->getFieldCount(); |
---|
78 | |
---|
79 | fMatchedDepth = fElementDepth; |
---|
80 | fFieldActivator->startValueScopeFor(ic, fInitialDepth); |
---|
81 | |
---|
82 | for (XMLSize_t i = 0; i < count; i++) { |
---|
83 | |
---|
84 | XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth); |
---|
85 | matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void SelectorMatcher::endElement(const XMLElementDecl& elemDecl, |
---|
91 | const XMLCh* const elemContent, |
---|
92 | ValidationContext* validationContext /*=0*/, |
---|
93 | DatatypeValidator* actualValidator /*=0*/) |
---|
94 | { |
---|
95 | |
---|
96 | XPathMatcher::endElement(elemDecl, elemContent, validationContext, actualValidator); |
---|
97 | |
---|
98 | if (fElementDepth-- == fMatchedDepth) { |
---|
99 | |
---|
100 | fMatchedDepth = -1; |
---|
101 | fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), fInitialDepth); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | // --------------------------------------------------------------------------- |
---|
106 | // IC_Selector: Constructors and Destructor |
---|
107 | // --------------------------------------------------------------------------- |
---|
108 | IC_Selector::IC_Selector(XercesXPath* const xpath, |
---|
109 | IdentityConstraint* const identityConstraint) |
---|
110 | : fXPath(xpath) |
---|
111 | , fIdentityConstraint(identityConstraint) |
---|
112 | { |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | IC_Selector::~IC_Selector() |
---|
117 | { |
---|
118 | delete fXPath; |
---|
119 | } |
---|
120 | |
---|
121 | // --------------------------------------------------------------------------- |
---|
122 | // IC_Selector: operators |
---|
123 | // --------------------------------------------------------------------------- |
---|
124 | bool IC_Selector::operator ==(const IC_Selector& other) const { |
---|
125 | |
---|
126 | return (*fXPath == *(other.fXPath)); |
---|
127 | } |
---|
128 | |
---|
129 | bool IC_Selector::operator !=(const IC_Selector& other) const { |
---|
130 | |
---|
131 | return !operator==(other); |
---|
132 | } |
---|
133 | |
---|
134 | // --------------------------------------------------------------------------- |
---|
135 | // IC_Selector: Factory methods |
---|
136 | // --------------------------------------------------------------------------- |
---|
137 | XPathMatcher* IC_Selector::createMatcher(FieldActivator* const fieldActivator, |
---|
138 | const int initialDepth, |
---|
139 | MemoryManager* const manager) { |
---|
140 | |
---|
141 | return new (manager) SelectorMatcher(fXPath, this, fieldActivator, initialDepth, manager); |
---|
142 | } |
---|
143 | |
---|
144 | /*** |
---|
145 | * Support for Serialization/De-serialization |
---|
146 | ***/ |
---|
147 | |
---|
148 | IMPL_XSERIALIZABLE_TOCREATE(IC_Selector) |
---|
149 | |
---|
150 | void IC_Selector::serialize(XSerializeEngine& serEng) |
---|
151 | { |
---|
152 | if (serEng.isStoring()) |
---|
153 | { |
---|
154 | serEng<<fXPath; |
---|
155 | |
---|
156 | IdentityConstraint::storeIC(serEng, fIdentityConstraint); |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | serEng>>fXPath; |
---|
161 | |
---|
162 | fIdentityConstraint = IdentityConstraint::loadIC(serEng); |
---|
163 | } |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | IC_Selector::IC_Selector(MemoryManager* const ) |
---|
168 | :fXPath(0) |
---|
169 | ,fIdentityConstraint(0) |
---|
170 | { |
---|
171 | } |
---|
172 | |
---|
173 | XERCES_CPP_NAMESPACE_END |
---|
174 | |
---|
175 | /** |
---|
176 | * End of file IC_Selector.cpp |
---|
177 | */ |
---|
178 | |
---|