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