source: NonGTP/Xerces/xercesc/validators/schema/identity/ValueStoreCache.hpp @ 188

Revision 188, 9.0 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: ValueStoreCache.hpp,v 1.6 2003/05/16 21:43:22 knoaman Exp $
59 */
60
61#if !defined(VALUESTORECACHE_HPP)
62#define VALUESTORECACHE_HPP
63
64/**
65  * This class is used to store the values for identity constraints.
66  *
67  * Sketch of algorithm:
68  *  - When a constraint is first encountered, its values are stored in the
69  *    (local) fIC2ValueStoreMap;
70  *  - Once it is validated (i.e., wen it goes out of scope), its values are
71  *    merged into the fGlobalICMap;
72  *  - As we encounter keyref's, we look at the global table to validate them.
73  *  - Validation always occurs against the fGlobalIDConstraintMap (which
74  *    comprises all the "eligible" id constraints). When an endelement is
75  *    found, this Hashtable is merged with the one below in the stack. When a
76  *    start tag is encountered, we create a new fGlobalICMap.
77  *    i.e., the top of the fGlobalIDMapStack always contains the preceding
78  *    siblings' eligible id constraints; the fGlobalICMap contains
79  *    descendants+self. Keyrefs can only match descendants+self.
80  */
81
82// ---------------------------------------------------------------------------
83//  Includes
84// ---------------------------------------------------------------------------
85#include <xercesc/util/RefVectorOf.hpp>
86#include <xercesc/util/RefHashTableOf.hpp>
87#include <xercesc/util/RefHash2KeysTableOf.hpp>
88#include <xercesc/util/RefStackOf.hpp>
89#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
90#include <xercesc/validators/schema/identity/IC_Field.hpp>
91
92XERCES_CPP_NAMESPACE_BEGIN
93
94// ---------------------------------------------------------------------------
95//  Forward Declcaration
96// ---------------------------------------------------------------------------
97class ValueStore;
98class SchemaElementDecl;
99class XMLScanner;
100
101
102class VALIDATORS_EXPORT ValueStoreCache : public XMemory
103{
104public:
105    // -----------------------------------------------------------------------
106    //  Constructors/Destructor
107    // -----------------------------------------------------------------------
108    ValueStoreCache(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
109        ~ValueStoreCache();
110
111        // -----------------------------------------------------------------------
112    //  Setter Methods
113    // -----------------------------------------------------------------------
114    void setScanner(XMLScanner* const scanner);
115
116        // -----------------------------------------------------------------------
117    //  Document Handling methods
118    // -----------------------------------------------------------------------
119    void startDocument();
120    void startElement();
121    void endElement();
122    void endDocument();
123
124        // -----------------------------------------------------------------------
125    //  Initialization methods
126    // -----------------------------------------------------------------------
127    void initValueStoresFor(SchemaElementDecl* const elemDecl, const int initialDepth);
128
129
130        // -----------------------------------------------------------------------
131    //  Access methods
132    // -----------------------------------------------------------------------
133    ValueStore* getValueStoreFor(const IC_Field* const field, const int initialDepth);
134    ValueStore* getValueStoreFor(const IdentityConstraint* const ic, const int intialDepth);
135    ValueStore* getGlobalValueStoreFor(const IdentityConstraint* const ic);
136
137        // -----------------------------------------------------------------------
138    //  Helper methods
139    // -----------------------------------------------------------------------
140    /** This method takes the contents of the (local) ValueStore associated
141      * with ic and moves them into the global hashtable, if ic is a <unique>
142      * or a <key>. If it's a <keyRef>, then we leave it for later.
143      */
144    void transplant(IdentityConstraint* const ic, const int initialDepth);
145
146private:
147    // -----------------------------------------------------------------------
148    //  Unimplemented contstructors and operators
149    // -----------------------------------------------------------------------
150    ValueStoreCache(const ValueStoreCache& other);
151    ValueStoreCache& operator= (const ValueStoreCache& other);
152
153    // -----------------------------------------------------------------------
154    //  Helper methods
155    // -----------------------------------------------------------------------
156    void init();
157    void cleanUp();
158
159    // -----------------------------------------------------------------------
160    //  Data
161    // -----------------------------------------------------------------------
162    RefVectorOf<ValueStore>*                 fValueStores;
163    RefHashTableOf<ValueStore>*              fGlobalICMap;
164    RefHash2KeysTableOf<ValueStore>*         fIC2ValueStoreMap;
165    RefStackOf<RefHashTableOf<ValueStore> >* fGlobalMapStack;
166    XMLScanner*                              fScanner;
167    MemoryManager*                           fMemoryManager;
168};
169
170// ---------------------------------------------------------------------------
171//  ValueStoreCache: Access methods
172// ---------------------------------------------------------------------------
173inline void ValueStoreCache::setScanner(XMLScanner* const scanner) {
174
175    fScanner = scanner;
176}
177
178// ---------------------------------------------------------------------------
179//  ValueStoreCache: Access methods
180// ---------------------------------------------------------------------------
181inline ValueStore*
182ValueStoreCache::getValueStoreFor(const IC_Field* const field, const int initialDepth) {
183
184    return fIC2ValueStoreMap->get(field->getIdentityConstraint(), initialDepth);
185}
186
187inline ValueStore*
188ValueStoreCache::getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth) {
189
190    return fIC2ValueStoreMap->get(ic, initialDepth);
191}
192
193inline ValueStore*
194ValueStoreCache::getGlobalValueStoreFor(const IdentityConstraint* const ic) {
195
196    return fGlobalICMap->get(ic);
197}
198
199// ---------------------------------------------------------------------------
200//  ValueStoreCache: Document handling methods
201// ---------------------------------------------------------------------------
202inline void ValueStoreCache::endDocument() {
203}
204
205XERCES_CPP_NAMESPACE_END
206
207#endif
208
209/**
210  * End of file ValueStoreCache.hpp
211  */
212
Note: See TracBrowser for help on using the repository browser.