source: NonGTP/Xerces/xercesc/framework/psvi/XSModel.hpp @ 188

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