source: NonGTP/Xerces/xerces/include/xercesc/framework/psvi/XSModel.hpp @ 358

Revision 358, 14.3 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2003,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 * $Log: XSModel.hpp,v $
19 * Revision 1.12  2004/09/08 13:56:08  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.11  2004/05/04 19:02:40  cargilld
23 * Enable IDs to work on all kinds of schema components
24 *
25 * Revision 1.10  2003/12/24 17:42:02  knoaman
26 * Misc. PSVI updates
27 *
28 * Revision 1.9  2003/11/26 16:12:23  knoaman
29 * Add a method to return the XSObject mapped to a schema grammar component
30 *
31 * Revision 1.8  2003/11/21 22:34:45  neilg
32 * More schema component model implementation, thanks to David Cargill.
33 * In particular, this cleans up and completes the XSModel, XSNamespaceItem,
34 * XSAttributeDeclaration and XSAttributeGroup implementations.
35 *
36 * Revision 1.7  2003/11/21 17:25:09  knoaman
37 * Use XSObjectFactory to create various components.
38 *
39 * Revision 1.6  2003/11/15 21:18:39  neilg
40 * fixes for compilation under gcc
41 *
42 * Revision 1.5  2003/11/14 22:47:53  neilg
43 * fix bogus log message from previous commit...
44 *
45 * Revision 1.4  2003/11/14 22:33:30  neilg
46 * Second phase of schema component model implementation. 
47 * Implement XSModel, XSNamespaceItem, and the plumbing necessary
48 * to connect them to the other components.
49 * Thanks to David Cargill.
50 *
51 * Revision 1.3  2003/11/06 15:30:04  neilg
52 * first part of PSVI/schema component model implementation, thanks to David Cargill.  This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse.
53 *
54 * Revision 1.2  2003/10/10 18:37:51  neilg
55 * update XSModel and XSObject interface so that IDs can be used to query components in XSModels, and so that those IDs can be recovered from components
56 *
57 * Revision 1.1  2003/09/16 14:33:36  neilg
58 * PSVI/schema component model classes, with Makefile/configuration changes necessary to build them
59 *
60 */
61
62#if !defined(XSMODEL_HPP)
63#define XSMODEL_HPP
64
65#include <xercesc/util/PlatformUtils.hpp>
66#include <xercesc/framework/psvi/XSObject.hpp>
67#include <xercesc/framework/psvi/XSNamedMap.hpp>
68
69#include <xercesc/util/ValueVectorOf.hpp>
70#include <xercesc/validators/schema/SchemaElementDecl.hpp>
71
72XERCES_CPP_NAMESPACE_BEGIN
73
74/**
75 * This class contains all properties of the Schema infoitem as determined
76 * after an entire validation episode.  That is, it contains all the properties
77 * of all the Schema Namespace Information objects that went into
78 * the validation episode.
79 * Since it is not like other components, it  does not
80 * inherit from the XSObject interface.
81 * This is *always* owned by the validator /parser object from which
82 * it is obtained.  It is designed to be subclassed; subclasses will
83 * specify under what conditions it may be relied upon to have meaningful contents.
84 */
85
86// forward declarations
87class Grammar;
88class XMLGrammarPool;
89class XSAnnotation;
90class XSAttributeDeclaration;
91class XSAttributeGroupDefinition;
92class XSElementDeclaration;
93class XSModelGroupDefinition;
94class XSNamespaceItem;
95class XSNotationDeclaration;
96class XSTypeDefinition;
97class XSObjectFactory;
98
99class XMLPARSER_EXPORT XSModel : public XMemory
100{
101public:
102
103    //  Constructors and Destructor
104    // -----------------------------------------------------------------------
105    /** @name Constructors */
106    //@{
107
108    /**
109      * The constructor to be used when a grammar pool contains all needed info
110      * @param grammarPool  the grammar pool containing the underlying data structures
111      * @param manager      The configurable memory manager
112      */
113    XSModel( XMLGrammarPool *grammarPool
114                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
115
116    /**
117      * The constructor to be used when the XSModel must represent all
118      * components in the union of an existing XSModel and a newly-created
119      * Grammar(s) from the GrammarResolver
120      *
121      * @param baseModel  the XSModel upon which this one is based
122      * @param grammarResolver  the grammar(s) whose components are to be merged
123      * @param manager     The configurable memory manager
124      */
125    XSModel( XSModel *baseModel
126                , GrammarResolver *grammarResolver
127                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
128
129    //@};
130
131    /** @name Destructor */
132    //@{
133    ~XSModel();
134    //@}
135
136    //---------------------
137    /** @name XSModel methods */
138
139    //@{
140
141    /**
142     * Convenience method. Returns a list of all namespaces that belong to
143     * this schema. The value <code>null</code> is not a valid namespace
144     * name, but if there are components that don't have a target namespace,
145     * <code>null</code> is included in this list.
146     */
147    StringList *getNamespaces();
148
149    /**
150     * A set of namespace schema information information items ( of type
151     * <code>XSNamespaceItem</code>), one for each namespace name which
152     * appears as the target namespace of any schema component in the schema
153     * used for that assessment, and one for absent if any schema component
154     * in the schema had no target namespace. For more information see
155     * schema information.
156     */
157    XSNamespaceItemList *getNamespaceItems();
158
159    /**
160     * [schema components]: a list of top-level components, i.e. element
161     * declarations, attribute declarations, etc.
162     * @param objectType The type of the declaration, i.e.
163     *   <code>ELEMENT_DECLARATION</code>,
164     *   <code>TYPE_DEFINITION</code> and any other component type that
165     * may be a property of a schema component.
166     * @return A list of top-level definition of the specified type in
167     *   <code>objectType</code> or <code>null</code>.
168     */
169    XSNamedMap<XSObject> *getComponents(XSConstants::COMPONENT_TYPE objectType);
170
171    /**
172     * Convenience method. Returns a list of top-level component declarations
173     * that are defined within the specified namespace, i.e. element
174     * declarations, attribute declarations, etc.
175     * @param objectType The type of the declaration, i.e.
176     *   <code>ELEMENT_DECLARATION</code>.
177     * @param compNamespace The namespace to which declaration belongs or
178     *   <code>null</code> (for components with no target namespace).
179     * @return A list of top-level definitions of the specified type in
180     *   <code>objectType</code> and defined in the specified
181     *   <code>namespace</code> or <code>null</code>.
182     */
183    XSNamedMap<XSObject> *getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType,
184                                               const XMLCh *compNamespace);
185
186    /**
187     *  [annotations]: a set of annotations.
188     */
189    XSAnnotationList *getAnnotations();
190
191    /**
192     * Convenience method. Returns a top-level element declaration.
193     * @param name The name of the declaration.
194     * @param compNamespace The namespace of the declaration, null if absent.
195     * @return A top-level element declaration or <code>null</code> if such
196     *   declaration does not exist.
197     */
198    XSElementDeclaration *getElementDeclaration(const XMLCh *name
199            , const XMLCh *compNamespace);
200
201    /**
202     * Convenience method. Returns a top-level attribute declaration.
203     * @param name The name of the declaration.
204     * @param compNamespace The namespace of the declaration, null if absent.
205     * @return A top-level attribute declaration or <code>null</code> if such
206     *   declaration does not exist.
207     */
208    XSAttributeDeclaration *getAttributeDeclaration(const XMLCh *name
209            , const XMLCh *compNamespace);
210
211    /**
212     * Convenience method. Returns a top-level simple or complex type
213     * definition.
214     * @param name The name of the definition.
215     * @param compNamespace The namespace of the declaration, null if absent.
216     * @return An <code>XSTypeDefinition</code> or <code>null</code> if such
217     *   definition does not exist.
218     */
219    XSTypeDefinition *getTypeDefinition(const XMLCh *name
220            , const XMLCh *compNamespace);
221
222    /**
223     * Convenience method. Returns a top-level attribute group definition.
224     * @param name The name of the definition.
225     * @param compNamespace The namespace of the declaration, null if absent.
226     * @return A top-level attribute group definition or <code>null</code> if
227     *   such definition does not exist.
228     */
229    XSAttributeGroupDefinition *getAttributeGroup(const XMLCh *name
230            , const XMLCh *compNamespace);
231
232    /**
233     * Convenience method. Returns a top-level model group definition.
234     * @param name The name of the definition.
235     * @param compNamespace The namespace of the declaration, null if absent.
236     * @return A top-level model group definition definition or
237     *   <code>null</code> if such definition does not exist.
238     */
239    XSModelGroupDefinition *getModelGroupDefinition(const XMLCh *name
240            , const XMLCh *compNamespace);
241
242    /**
243     * Convenience method. Returns a top-level notation declaration.
244     * @param name The name of the declaration.
245     * @param compNamespace The namespace of the declaration, null if absent.
246     * @return A top-level notation declaration or <code>null</code> if such
247     *   declaration does not exist.
248     */
249    XSNotationDeclaration *getNotationDeclaration(const XMLCh *name
250            , const XMLCh *compNamespace);
251
252    /**
253      * Optional.  Return a component given a component type and a unique Id. 
254      * May not be supported for all component types.
255      * @param compId unique Id of the component within its type
256      * @param compType type of the component
257      * @return the component of the given type with the given Id, or 0
258      * if no such component exists or this is unsupported for
259      * this type of component.
260      */
261    XSObject *getXSObjectById(unsigned int  compId
262                , XSConstants::COMPONENT_TYPE compType);
263
264    //@}
265
266    //----------------------------------
267    /** methods needed by implementation */
268
269    //@{
270    XMLStringPool*  getURIStringPool();
271
272    XSNamespaceItem* getNamespaceItem(const XMLCh* const key);
273
274    /**
275      * Get the XSObject (i.e. XSElementDeclaration) that corresponds to
276      * to a schema grammar component (i.e. SchemaElementDecl)
277      * @param key schema component object
278      *
279      * @return the corresponding XSObject
280      */
281    XSObject* getXSObject(void* key);
282
283    //@}
284private:
285
286    // -----------------------------------------------------------------------
287    //  Helper methods
288    // -----------------------------------------------------------------------
289    void addGrammarToXSModel
290    (
291        XSNamespaceItem* namespaceItem
292    );
293    void addS4SToXSModel
294    (
295        XSNamespaceItem* const namespaceItem
296        , RefHashTableOf<DatatypeValidator>* const builtInDV
297    );
298    void addComponentToNamespace
299    (
300         XSNamespaceItem* const namespaceItem
301         , XSObject* const component
302         , int componentIndex
303         , bool addToXSModel = true
304    );
305
306    void addComponentToIdVector
307    (
308        XSObject* const component
309        , int componentIndex
310    );
311
312    // -----------------------------------------------------------------------
313    //  Unimplemented constructors and operators
314    // -----------------------------------------------------------------------
315    XSModel(const XSModel&);
316    XSModel & operator=(const XSModel &);
317
318protected:
319    friend class XSObjectFactory;
320    friend class XSObject;
321
322    // -----------------------------------------------------------------------
323    //  data members
324    // -----------------------------------------------------------------------
325    // fMemoryManager:
326    //  used for any memory allocations
327    MemoryManager* const                    fMemoryManager;
328 
329    StringList*                             fNamespaceStringList;
330    XSNamespaceItemList*                    fXSNamespaceItemList;
331
332    RefVectorOf<XSObject>*                  fIdVector[XSConstants::MULTIVALUE_FACET];   
333
334    /* Need a XSNamedMap for each component    top-level?
335              ATTRIBUTE_DECLARATION     = 1,       
336              ELEMENT_DECLARATION       = 2,       
337              TYPE_DEFINITION           = 3,       
338              ATTRIBUTE_USE             = 4,       no
339              ATTRIBUTE_GROUP_DEFINITION= 5,       
340              MODEL_GROUP_DEFINITION    = 6,       
341              MODEL_GROUP               = 7,       no
342              PARTICLE                  = 8,       no
343              WILDCARD                  = 9,       no
344              IDENTITY_CONSTRAINT       = 10,      no
345              NOTATION_DECLARATION      = 11,       
346              ANNOTATION                = 12,      no
347              FACET                     = 13,      no
348              MULTIVALUE_FACET          = 14       no
349    */
350    XSNamedMap<XSObject>*                   fComponentMap[XSConstants::MULTIVALUE_FACET];
351    XMLStringPool*                          fURIStringPool;
352    XSAnnotationList*                       fXSAnnotationList;
353    RefHashTableOf<XSNamespaceItem>*        fHashNamespace;
354    XSObjectFactory*                        fObjFactory;
355    RefVectorOf<XSNamespaceItem>*           fDeleteNamespace;
356    XSModel*                                fParent;
357    bool                                    fDeleteParent;
358    bool                                    fAddedS4SGrammar;
359};
360
361inline XMLStringPool*  XSModel::getURIStringPool()
362{
363    return fURIStringPool;
364}
365
366inline StringList *XSModel::getNamespaces()
367{
368    return fNamespaceStringList;
369}
370
371inline XSNamespaceItemList *XSModel::getNamespaceItems()
372{
373    return fXSNamespaceItemList;
374}
375
376XERCES_CPP_NAMESPACE_END
377
378#endif
Note: See TracBrowser for help on using the repository browser.