Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:52

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XSMODEL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XSMODEL_HPP
0024 
0025 #include <xercesc/util/PlatformUtils.hpp>
0026 #include <xercesc/framework/psvi/XSObject.hpp>
0027 #include <xercesc/framework/psvi/XSNamedMap.hpp>
0028 
0029 #include <xercesc/util/ValueVectorOf.hpp>
0030 #include <xercesc/validators/schema/SchemaElementDecl.hpp>
0031 
0032 XERCES_CPP_NAMESPACE_BEGIN
0033 
0034 /**
0035  * This class contains all properties of the Schema infoitem as determined
0036  * after an entire validation episode.  That is, it contains all the properties
0037  * of all the Schema Namespace Information objects that went into
0038  * the validation episode.
0039  * Since it is not like other components, it  does not
0040  * inherit from the XSObject interface.
0041  * This is *always* owned by the validator /parser object from which
0042  * it is obtained.  It is designed to be subclassed; subclasses will
0043  * specify under what conditions it may be relied upon to have meaningful contents.
0044  */
0045 
0046 // forward declarations
0047 class Grammar;
0048 class XMLGrammarPool;
0049 class XSAnnotation;
0050 class XSAttributeDeclaration;
0051 class XSAttributeGroupDefinition;
0052 class XSElementDeclaration;
0053 class XSModelGroupDefinition;
0054 class XSNamespaceItem;
0055 class XSNotationDeclaration;
0056 class XSTypeDefinition;
0057 class XSObjectFactory;
0058 
0059 class XMLPARSER_EXPORT XSModel : public XMemory
0060 {
0061 public:
0062 
0063     //  Constructors and Destructor
0064     // -----------------------------------------------------------------------
0065     /** @name Constructors */
0066     //@{
0067 
0068     /**
0069       * The constructor to be used when a grammar pool contains all needed info
0070       * @param grammarPool  the grammar pool containing the underlying data structures
0071       * @param manager      The configurable memory manager
0072       */
0073     XSModel( XMLGrammarPool *grammarPool
0074                 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0075 
0076     /**
0077       * The constructor to be used when the XSModel must represent all
0078       * components in the union of an existing XSModel and a newly-created
0079       * Grammar(s) from the GrammarResolver
0080       *
0081       * @param baseModel  the XSModel upon which this one is based
0082       * @param grammarResolver  the grammar(s) whose components are to be merged
0083       * @param manager     The configurable memory manager
0084       */
0085     XSModel( XSModel *baseModel
0086                 , GrammarResolver *grammarResolver
0087                 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0088 
0089     //@};
0090 
0091     /** @name Destructor */
0092     //@{
0093     ~XSModel();
0094     //@}
0095 
0096     //---------------------
0097     /** @name XSModel methods */
0098 
0099     //@{
0100 
0101     /**
0102      * Convenience method. Returns a list of all namespaces that belong to
0103      * this schema. The value <code>null</code> is not a valid namespace
0104      * name, but if there are components that don't have a target namespace,
0105      * <code>null</code> is included in this list.
0106      */
0107     StringList *getNamespaces();
0108 
0109     /**
0110      * A set of namespace schema information information items ( of type
0111      * <code>XSNamespaceItem</code>), one for each namespace name which
0112      * appears as the target namespace of any schema component in the schema
0113      * used for that assessment, and one for absent if any schema component
0114      * in the schema had no target namespace. For more information see
0115      * schema information.
0116      */
0117     XSNamespaceItemList *getNamespaceItems();
0118 
0119     /**
0120      * [schema components]: a list of top-level components, i.e. element
0121      * declarations, attribute declarations, etc.
0122      * @param objectType The type of the declaration, i.e.
0123      *   <code>ELEMENT_DECLARATION</code>,
0124      *   <code>TYPE_DEFINITION</code> and any other component type that
0125      * may be a property of a schema component.
0126      * @return A list of top-level definition of the specified type in
0127      *   <code>objectType</code> or <code>null</code>.
0128      */
0129     XSNamedMap<XSObject> *getComponents(XSConstants::COMPONENT_TYPE objectType);
0130 
0131     /**
0132      * Convenience method. Returns a list of top-level component declarations
0133      * that are defined within the specified namespace, i.e. element
0134      * declarations, attribute declarations, etc.
0135      * @param objectType The type of the declaration, i.e.
0136      *   <code>ELEMENT_DECLARATION</code>.
0137      * @param compNamespace The namespace to which declaration belongs or
0138      *   <code>null</code> (for components with no target namespace).
0139      * @return A list of top-level definitions of the specified type in
0140      *   <code>objectType</code> and defined in the specified
0141      *   <code>namespace</code> or <code>null</code>.
0142      */
0143     XSNamedMap<XSObject> *getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType,
0144                                                const XMLCh *compNamespace);
0145 
0146     /**
0147      *  [annotations]: a set of annotations.
0148      */
0149     XSAnnotationList *getAnnotations();
0150 
0151     /**
0152      * Convenience method. Returns a top-level element declaration.
0153      * @param name The name of the declaration.
0154      * @param compNamespace The namespace of the declaration, null if absent.
0155      * @return A top-level element declaration or <code>null</code> if such
0156      *   declaration does not exist.
0157      */
0158     XSElementDeclaration *getElementDeclaration(const XMLCh *name
0159             , const XMLCh *compNamespace);
0160 
0161     /**
0162      * Convenience method. Returns a top-level attribute declaration.
0163      * @param name The name of the declaration.
0164      * @param compNamespace The namespace of the declaration, null if absent.
0165      * @return A top-level attribute declaration or <code>null</code> if such
0166      *   declaration does not exist.
0167      */
0168     XSAttributeDeclaration *getAttributeDeclaration(const XMLCh *name
0169             , const XMLCh *compNamespace);
0170 
0171     /**
0172      * Convenience method. Returns a top-level simple or complex type
0173      * definition.
0174      * @param name The name of the definition.
0175      * @param compNamespace The namespace of the declaration, null if absent.
0176      * @return An <code>XSTypeDefinition</code> or <code>null</code> if such
0177      *   definition does not exist.
0178      */
0179     XSTypeDefinition *getTypeDefinition(const XMLCh *name
0180             , const XMLCh *compNamespace);
0181 
0182     /**
0183      * Convenience method. Returns a top-level attribute group definition.
0184      * @param name The name of the definition.
0185      * @param compNamespace The namespace of the declaration, null if absent.
0186      * @return A top-level attribute group definition or <code>null</code> if
0187      *   such definition does not exist.
0188      */
0189     XSAttributeGroupDefinition *getAttributeGroup(const XMLCh *name
0190             , const XMLCh *compNamespace);
0191 
0192     /**
0193      * Convenience method. Returns a top-level model group definition.
0194      * @param name The name of the definition.
0195      * @param compNamespace The namespace of the declaration, null if absent.
0196      * @return A top-level model group definition definition or
0197      *   <code>null</code> if such definition does not exist.
0198      */
0199     XSModelGroupDefinition *getModelGroupDefinition(const XMLCh *name
0200             , const XMLCh *compNamespace);
0201 
0202     /**
0203      * Convenience method. Returns a top-level notation declaration.
0204      * @param name The name of the declaration.
0205      * @param compNamespace The namespace of the declaration, null if absent.
0206      * @return A top-level notation declaration or <code>null</code> if such
0207      *   declaration does not exist.
0208      */
0209     XSNotationDeclaration *getNotationDeclaration(const XMLCh *name
0210             , const XMLCh *compNamespace);
0211 
0212     /**
0213       * Optional.  Return a component given a component type and a unique Id.
0214       * May not be supported for all component types.
0215       * @param compId unique Id of the component within its type
0216       * @param compType type of the component
0217       * @return the component of the given type with the given Id, or 0
0218       * if no such component exists or this is unsupported for
0219       * this type of component.
0220       */
0221     XSObject *getXSObjectById(XMLSize_t compId,
0222                               XSConstants::COMPONENT_TYPE compType);
0223 
0224     //@}
0225 
0226     //----------------------------------
0227     /** methods needed by implementation */
0228 
0229     //@{
0230     XMLStringPool*  getURIStringPool();
0231 
0232     XSNamespaceItem* getNamespaceItem(const XMLCh* const key);
0233 
0234     /**
0235       * Get the XSObject (i.e. XSElementDeclaration) that corresponds to
0236       * to a schema grammar component (i.e. SchemaElementDecl)
0237       * @param key schema component object
0238       *
0239       * @return the corresponding XSObject
0240       */
0241     XSObject* getXSObject(void* key);
0242 
0243     //@}
0244 private:
0245 
0246     // -----------------------------------------------------------------------
0247     //  Helper methods
0248     // -----------------------------------------------------------------------
0249     void addGrammarToXSModel
0250     (
0251         XSNamespaceItem* namespaceItem
0252     );
0253     void addS4SToXSModel
0254     (
0255         XSNamespaceItem* const namespaceItem
0256         , RefHashTableOf<DatatypeValidator>* const builtInDV
0257     );
0258     void addComponentToNamespace
0259     (
0260          XSNamespaceItem* const namespaceItem
0261          , XSObject* const component
0262          , XMLSize_t componentIndex
0263          , bool addToXSModel = true
0264     );
0265 
0266     void addComponentToIdVector
0267     (
0268         XSObject* const component
0269         , XMLSize_t componentIndex
0270     );
0271 
0272     // -----------------------------------------------------------------------
0273     //  Unimplemented constructors and operators
0274     // -----------------------------------------------------------------------
0275     XSModel(const XSModel&);
0276     XSModel & operator=(const XSModel &);
0277 
0278 protected:
0279     friend class XSObjectFactory;
0280     friend class XSObject;
0281 
0282     // -----------------------------------------------------------------------
0283     //  data members
0284     // -----------------------------------------------------------------------
0285     // fMemoryManager:
0286     //  used for any memory allocations
0287     MemoryManager* const                    fMemoryManager;
0288 
0289     StringList*                             fNamespaceStringList;
0290     XSNamespaceItemList*                    fXSNamespaceItemList;
0291 
0292     RefVectorOf<XSObject>*                  fIdVector[XSConstants::MULTIVALUE_FACET];
0293 
0294     /* Need a XSNamedMap for each component    top-level?
0295           ATTRIBUTE_DECLARATION     = 1,
0296           ELEMENT_DECLARATION       = 2,
0297           TYPE_DEFINITION           = 3,
0298           ATTRIBUTE_USE             = 4,       no
0299           ATTRIBUTE_GROUP_DEFINITION= 5,
0300           MODEL_GROUP_DEFINITION    = 6,
0301           MODEL_GROUP               = 7,       no
0302           PARTICLE                  = 8,       no
0303           WILDCARD                  = 9,       no
0304           IDENTITY_CONSTRAINT       = 10,      no
0305           NOTATION_DECLARATION      = 11,
0306           ANNOTATION                = 12,      no
0307           FACET                     = 13,      no
0308           MULTIVALUE_FACET          = 14       no
0309     */
0310     XSNamedMap<XSObject>*                   fComponentMap[XSConstants::MULTIVALUE_FACET];
0311     XMLStringPool*                          fURIStringPool;
0312     XSAnnotationList*                       fXSAnnotationList;
0313     RefHashTableOf<XSNamespaceItem>*        fHashNamespace;
0314     XSObjectFactory*                        fObjFactory;
0315     RefVectorOf<XSNamespaceItem>*           fDeleteNamespace;
0316     XSModel*                                fParent;
0317     bool                                    fDeleteParent;
0318     bool                                    fAddedS4SGrammar;
0319 };
0320 
0321 inline XMLStringPool*  XSModel::getURIStringPool()
0322 {
0323     return fURIStringPool;
0324 }
0325 
0326 inline StringList *XSModel::getNamespaces()
0327 {
0328     return fNamespaceStringList;
0329 }
0330 
0331 inline XSNamespaceItemList *XSModel::getNamespaceItems()
0332 {
0333     return fXSNamespaceItemList;
0334 }
0335 
0336 XERCES_CPP_NAMESPACE_END
0337 
0338 #endif