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