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: ValueStoreCache.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(VALUESTORECACHE_HPP) |
---|
23 | #define VALUESTORECACHE_HPP |
---|
24 | |
---|
25 | /** |
---|
26 | * This class is used to store the values for identity constraints. |
---|
27 | * |
---|
28 | * Sketch of algorithm: |
---|
29 | * - When a constraint is first encountered, its values are stored in the |
---|
30 | * (local) fIC2ValueStoreMap; |
---|
31 | * - Once it is validated (i.e., wen it goes out of scope), its values are |
---|
32 | * merged into the fGlobalICMap; |
---|
33 | * - As we encounter keyref's, we look at the global table to validate them. |
---|
34 | * - Validation always occurs against the fGlobalIDConstraintMap (which |
---|
35 | * comprises all the "eligible" id constraints). When an endelement is |
---|
36 | * found, this Hashtable is merged with the one below in the stack. When a |
---|
37 | * start tag is encountered, we create a new fGlobalICMap. |
---|
38 | * i.e., the top of the fGlobalIDMapStack always contains the preceding |
---|
39 | * siblings' eligible id constraints; the fGlobalICMap contains |
---|
40 | * descendants+self. Keyrefs can only match descendants+self. |
---|
41 | */ |
---|
42 | |
---|
43 | // --------------------------------------------------------------------------- |
---|
44 | // Includes |
---|
45 | // --------------------------------------------------------------------------- |
---|
46 | #include <xercesc/util/RefVectorOf.hpp> |
---|
47 | #include <xercesc/util/RefHashTableOf.hpp> |
---|
48 | #include <xercesc/util/RefHash2KeysTableOf.hpp> |
---|
49 | #include <xercesc/util/RefStackOf.hpp> |
---|
50 | #include <xercesc/validators/schema/identity/IdentityConstraint.hpp> |
---|
51 | #include <xercesc/validators/schema/identity/IC_Field.hpp> |
---|
52 | |
---|
53 | XERCES_CPP_NAMESPACE_BEGIN |
---|
54 | |
---|
55 | // --------------------------------------------------------------------------- |
---|
56 | // Forward Declcaration |
---|
57 | // --------------------------------------------------------------------------- |
---|
58 | class ValueStore; |
---|
59 | class SchemaElementDecl; |
---|
60 | class XMLScanner; |
---|
61 | |
---|
62 | |
---|
63 | class VALIDATORS_EXPORT ValueStoreCache : public XMemory |
---|
64 | { |
---|
65 | public: |
---|
66 | // ----------------------------------------------------------------------- |
---|
67 | // Constructors/Destructor |
---|
68 | // ----------------------------------------------------------------------- |
---|
69 | ValueStoreCache(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
70 | ~ValueStoreCache(); |
---|
71 | |
---|
72 | // ----------------------------------------------------------------------- |
---|
73 | // Setter Methods |
---|
74 | // ----------------------------------------------------------------------- |
---|
75 | void setScanner(XMLScanner* const scanner); |
---|
76 | |
---|
77 | // ----------------------------------------------------------------------- |
---|
78 | // Document Handling methods |
---|
79 | // ----------------------------------------------------------------------- |
---|
80 | void startDocument(); |
---|
81 | void startElement(); |
---|
82 | void endElement(); |
---|
83 | void endDocument(); |
---|
84 | |
---|
85 | // ----------------------------------------------------------------------- |
---|
86 | // Initialization methods |
---|
87 | // ----------------------------------------------------------------------- |
---|
88 | void initValueStoresFor(SchemaElementDecl* const elemDecl, const int initialDepth); |
---|
89 | |
---|
90 | |
---|
91 | // ----------------------------------------------------------------------- |
---|
92 | // Access methods |
---|
93 | // ----------------------------------------------------------------------- |
---|
94 | ValueStore* getValueStoreFor(const IC_Field* const field, const int initialDepth); |
---|
95 | ValueStore* getValueStoreFor(const IdentityConstraint* const ic, const int intialDepth); |
---|
96 | ValueStore* getGlobalValueStoreFor(const IdentityConstraint* const ic); |
---|
97 | |
---|
98 | // ----------------------------------------------------------------------- |
---|
99 | // Helper methods |
---|
100 | // ----------------------------------------------------------------------- |
---|
101 | /** This method takes the contents of the (local) ValueStore associated |
---|
102 | * with ic and moves them into the global hashtable, if ic is a <unique> |
---|
103 | * or a <key>. If it's a <keyRef>, then we leave it for later. |
---|
104 | */ |
---|
105 | void transplant(IdentityConstraint* const ic, const int initialDepth); |
---|
106 | |
---|
107 | private: |
---|
108 | // ----------------------------------------------------------------------- |
---|
109 | // Unimplemented contstructors and operators |
---|
110 | // ----------------------------------------------------------------------- |
---|
111 | ValueStoreCache(const ValueStoreCache& other); |
---|
112 | ValueStoreCache& operator= (const ValueStoreCache& other); |
---|
113 | |
---|
114 | // ----------------------------------------------------------------------- |
---|
115 | // Helper methods |
---|
116 | // ----------------------------------------------------------------------- |
---|
117 | void init(); |
---|
118 | void cleanUp(); |
---|
119 | |
---|
120 | // ----------------------------------------------------------------------- |
---|
121 | // Data |
---|
122 | // ----------------------------------------------------------------------- |
---|
123 | RefVectorOf<ValueStore>* fValueStores; |
---|
124 | RefHashTableOf<ValueStore>* fGlobalICMap; |
---|
125 | RefHash2KeysTableOf<ValueStore>* fIC2ValueStoreMap; |
---|
126 | RefStackOf<RefHashTableOf<ValueStore> >* fGlobalMapStack; |
---|
127 | XMLScanner* fScanner; |
---|
128 | MemoryManager* fMemoryManager; |
---|
129 | }; |
---|
130 | |
---|
131 | // --------------------------------------------------------------------------- |
---|
132 | // ValueStoreCache: Access methods |
---|
133 | // --------------------------------------------------------------------------- |
---|
134 | inline void ValueStoreCache::setScanner(XMLScanner* const scanner) { |
---|
135 | |
---|
136 | fScanner = scanner; |
---|
137 | } |
---|
138 | |
---|
139 | // --------------------------------------------------------------------------- |
---|
140 | // ValueStoreCache: Access methods |
---|
141 | // --------------------------------------------------------------------------- |
---|
142 | inline ValueStore* |
---|
143 | ValueStoreCache::getValueStoreFor(const IC_Field* const field, const int initialDepth) { |
---|
144 | |
---|
145 | return fIC2ValueStoreMap->get(field->getIdentityConstraint(), initialDepth); |
---|
146 | } |
---|
147 | |
---|
148 | inline ValueStore* |
---|
149 | ValueStoreCache::getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth) { |
---|
150 | |
---|
151 | return fIC2ValueStoreMap->get(ic, initialDepth); |
---|
152 | } |
---|
153 | |
---|
154 | inline ValueStore* |
---|
155 | ValueStoreCache::getGlobalValueStoreFor(const IdentityConstraint* const ic) { |
---|
156 | |
---|
157 | return fGlobalICMap->get(ic); |
---|
158 | } |
---|
159 | |
---|
160 | // --------------------------------------------------------------------------- |
---|
161 | // ValueStoreCache: Document handling methods |
---|
162 | // --------------------------------------------------------------------------- |
---|
163 | inline void ValueStoreCache::endDocument() { |
---|
164 | } |
---|
165 | |
---|
166 | XERCES_CPP_NAMESPACE_END |
---|
167 | |
---|
168 | #endif |
---|
169 | |
---|
170 | /** |
---|
171 | * End of file ValueStoreCache.hpp |
---|
172 | */ |
---|
173 | |
---|