source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/validators/schema/identity/IdentityConstraint.hpp @ 2674

Revision 2674, 7.1 KB checked in by mattausch, 16 years ago (diff)
Line 
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: IdentityConstraint.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#if !defined(IDENTITYCONSTRAINT_HPP)
23#define IDENTITYCONSTRAINT_HPP
24
25
26/**
27  * The class act as a base class for schema identity constraints.
28  */
29
30// ---------------------------------------------------------------------------
31//  Includes
32// ---------------------------------------------------------------------------
33#include <xercesc/util/RefVectorOf.hpp>
34#include <xercesc/validators/schema/identity/IC_Field.hpp>
35
36#include <xercesc/internal/XSerializable.hpp>
37
38XERCES_CPP_NAMESPACE_BEGIN
39
40// ---------------------------------------------------------------------------
41//  Forward Declarations
42// ---------------------------------------------------------------------------
43class IC_Selector;
44
45class VALIDATORS_EXPORT IdentityConstraint : public XSerializable, public XMemory
46{
47public:
48    // -----------------------------------------------------------------------
49    //  Constants
50    // -----------------------------------------------------------------------
51    enum ICType {
52        UNIQUE = 0,
53        KEY = 1,
54        KEYREF = 2,
55        UNKNOWN
56    };
57
58    // -----------------------------------------------------------------------
59    //  Constructors/Destructor
60    // -----------------------------------------------------------------------
61        virtual ~IdentityConstraint();
62
63    // -----------------------------------------------------------------------
64    //  operators
65    // -----------------------------------------------------------------------
66    bool operator== (const IdentityConstraint& other) const;
67    bool operator!= (const IdentityConstraint& other) const;
68
69        // -----------------------------------------------------------------------
70    //  Getter methods
71    // -----------------------------------------------------------------------
72    virtual short getType() const = 0;
73    int           getFieldCount() const;
74    XMLCh*        getIdentityConstraintName() const;
75    XMLCh*        getElementName() const;
76    IC_Selector*  getSelector() const;
77    int           getNamespaceURI() const;
78
79        // -----------------------------------------------------------------------
80    //  Setter methods
81    // -----------------------------------------------------------------------
82    void setSelector(IC_Selector* const selector);
83    void setNamespaceURI(int uri);
84
85        // -----------------------------------------------------------------------
86    //  Access methods
87    // -----------------------------------------------------------------------
88    void addField(IC_Field* const field);
89    const IC_Field* getFieldAt(const unsigned int index) const;
90    IC_Field* getFieldAt(const unsigned int index);
91
92    /***
93     * Support for Serialization/De-serialization
94     ***/
95    DECL_XSERIALIZABLE(IdentityConstraint)
96
97        static void                storeIC(XSerializeEngine&         serEng
98                                     , IdentityConstraint* const ic);
99
100        static IdentityConstraint* loadIC(XSerializeEngine& serEng);
101
102protected:
103    // -----------------------------------------------------------------------
104    //  Constructors/Destructor
105    // -----------------------------------------------------------------------
106    IdentityConstraint(const XMLCh* const identityConstraintName,
107                       const XMLCh* const elementName,
108                                           MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
109
110private:
111    // -----------------------------------------------------------------------
112    //  Unimplemented contstructors and operators
113    // -----------------------------------------------------------------------
114    IdentityConstraint(const IdentityConstraint& other);
115    IdentityConstraint& operator= (const IdentityConstraint& other);
116
117    // -----------------------------------------------------------------------
118    //  CleanUp methods
119    // -----------------------------------------------------------------------
120    void cleanUp();
121
122    // -----------------------------------------------------------------------
123    //  Data members
124    //
125    //  fIdentityConstraintName
126    //      The identity constraint name
127    //
128    //  fElemName
129    //      The element name
130    //
131    //  fSelector
132    //      The selector information
133    //
134    //  fFields
135    //      The field(s) information
136    // -----------------------------------------------------------------------
137    XMLCh*                 fIdentityConstraintName;
138    XMLCh*                 fElemName;
139    IC_Selector*           fSelector;
140    RefVectorOf<IC_Field>* fFields;
141    MemoryManager*         fMemoryManager;
142    int                    fNamespaceURI;
143};
144
145
146// ---------------------------------------------------------------------------
147//  IdentityConstraint: Getter methods
148// ---------------------------------------------------------------------------
149inline int IdentityConstraint::getFieldCount() const {
150
151    if (fFields) {
152        return fFields->size();
153    }
154
155    return 0;
156}
157
158inline XMLCh* IdentityConstraint::getIdentityConstraintName() const {
159
160    return fIdentityConstraintName;
161}
162
163inline XMLCh* IdentityConstraint::getElementName() const {
164
165    return fElemName;
166}
167
168inline IC_Selector* IdentityConstraint::getSelector() const {
169
170    return fSelector;
171}
172
173inline int IdentityConstraint::getNamespaceURI() const
174{
175    return fNamespaceURI;
176}
177
178// ---------------------------------------------------------------------------
179//  IdentityConstraint: Setter methods
180// ---------------------------------------------------------------------------
181inline void IdentityConstraint::setNamespaceURI(int uri)
182{
183    fNamespaceURI = uri;
184}
185
186// ---------------------------------------------------------------------------
187//  IdentityConstraint: Access methods
188// ---------------------------------------------------------------------------
189inline void IdentityConstraint::addField(IC_Field* const field) {
190
191    if (!fFields) {
192        fFields = new (fMemoryManager) RefVectorOf<IC_Field>(4, true, fMemoryManager);
193    }
194
195    fFields->addElement(field);
196}
197
198inline const IC_Field* IdentityConstraint::getFieldAt(const unsigned int index) const {
199
200    if (fFields) {
201        return (fFields->elementAt(index));
202    }
203
204    return 0;
205}
206
207inline IC_Field* IdentityConstraint::getFieldAt(const unsigned int index) {
208
209    if (fFields) {
210        return (fFields->elementAt(index));
211    }
212
213    return 0;
214}
215
216XERCES_CPP_NAMESPACE_END
217
218#endif
219
220/**
221  * End of file IdentityConstraint.hpp
222  */
223
Note: See TracBrowser for help on using the repository browser.