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