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 #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
23 #include <xercesc/validators/schema/SchemaGrammar.hpp>
24 #include <xercesc/framework/psvi/XSModel.hpp>
25 #include <xercesc/framework/psvi/XSAnnotation.hpp>
26 #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
27
28 XERCES_CPP_NAMESPACE_BEGIN
29
30 // ---------------------------------------------------------------------------
31 // XSNamespaceItem: Constructors and Destructors
32 // ---------------------------------------------------------------------------
XSNamespaceItem(XSModel * const xsModel,SchemaGrammar * const grammar,MemoryManager * const manager)33 XSNamespaceItem::XSNamespaceItem(XSModel* const xsModel,
34 SchemaGrammar* const grammar,
35 MemoryManager* const manager)
36 : fMemoryManager(manager)
37 , fGrammar(grammar)
38 , fXSModel(xsModel)
39 , fXSAnnotationList(0)
40 , fSchemaNamespace(grammar->getTargetNamespace())
41 {
42 // Populate XSNamedMaps by going through the components
43 for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
44 {
45 switch (i+1)
46 {
47 case XSConstants::ATTRIBUTE_DECLARATION:
48 case XSConstants::ELEMENT_DECLARATION:
49 case XSConstants::TYPE_DEFINITION:
50 case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
51 case XSConstants::MODEL_GROUP_DEFINITION:
52 case XSConstants::NOTATION_DECLARATION:
53 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
54 (
55 20, // size
56 29, // modulus
57 fXSModel->getURIStringPool(),
58 false, // adoptElems
59 fMemoryManager
60 );
61 fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
62 (
63 29,
64 false,
65 fMemoryManager
66 );
67 break;
68 default:
69 // ATTRIBUTE_USE
70 // MODEL_GROUP
71 // PARTICLE
72 // IDENTITY_CONSTRAINT
73 // WILDCARD
74 // ANNOTATION
75 // FACET
76 // MULTIVALUE
77 fComponentMap[i] = 0;
78 fHashMap[i] = 0;
79 break;
80 }
81 }
82
83 fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
84 }
85
XSNamespaceItem(XSModel * const xsModel,const XMLCh * const schemaNamespace,MemoryManager * const manager)86 XSNamespaceItem::XSNamespaceItem(XSModel* const xsModel,
87 const XMLCh* const schemaNamespace,
88 MemoryManager* const manager)
89 : fMemoryManager(manager)
90 , fGrammar(0)
91 , fXSModel(xsModel)
92 , fXSAnnotationList(0)
93 , fSchemaNamespace(schemaNamespace)
94 {
95 // Populate XSNamedMaps by going through the components
96 for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
97 {
98 switch (i+1)
99 {
100 case XSConstants::ATTRIBUTE_DECLARATION:
101 case XSConstants::ELEMENT_DECLARATION:
102 case XSConstants::TYPE_DEFINITION:
103 case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
104 case XSConstants::MODEL_GROUP_DEFINITION:
105 case XSConstants::NOTATION_DECLARATION:
106 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
107 (
108 20, // size
109 29, // modulus
110 fXSModel->getURIStringPool(),
111 false, // adoptElems
112 fMemoryManager
113 );
114 fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
115 (
116 29,
117 false,
118 fMemoryManager
119 );
120 break;
121 default:
122 // ATTRIBUTE_USE
123 // MODEL_GROUP
124 // PARTICLE
125 // IDENTITY_CONSTRAINT
126 // WILDCARD
127 // ANNOTATION
128 // FACET
129 // MULTIVALUE
130 fComponentMap[i] = 0;
131 fHashMap[i] = 0;
132 break;
133 }
134 }
135
136 fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
137 }
138
~XSNamespaceItem()139 XSNamespaceItem::~XSNamespaceItem()
140 {
141 for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
142 {
143 switch (i+1)
144 {
145 case XSConstants::ATTRIBUTE_DECLARATION:
146 case XSConstants::ELEMENT_DECLARATION:
147 case XSConstants::TYPE_DEFINITION:
148 case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
149 case XSConstants::MODEL_GROUP_DEFINITION:
150 case XSConstants::NOTATION_DECLARATION:
151 delete fComponentMap[i];
152 delete fHashMap[i];
153 break;
154 }
155 }
156
157 delete fXSAnnotationList;
158 }
159
160 // ---------------------------------------------------------------------------
161 // XSNamespaceItem: access methods
162 // ---------------------------------------------------------------------------
getComponents(XSConstants::COMPONENT_TYPE objectType)163 XSNamedMap<XSObject> *XSNamespaceItem::getComponents(XSConstants::COMPONENT_TYPE objectType)
164 {
165 return fComponentMap[objectType -1];
166 }
167
getElementDeclaration(const XMLCh * name)168 XSElementDeclaration *XSNamespaceItem::getElementDeclaration(const XMLCh *name)
169 {
170 if (name)
171 return (XSElementDeclaration*) fHashMap[XSConstants::ELEMENT_DECLARATION -1]->get(name);
172 return 0;
173 }
174
getAttributeDeclaration(const XMLCh * name)175 XSAttributeDeclaration *XSNamespaceItem::getAttributeDeclaration(const XMLCh *name)
176 {
177 if (name)
178 return (XSAttributeDeclaration*) fHashMap[XSConstants::ATTRIBUTE_DECLARATION -1]->get(name);
179 return 0;
180 }
181
getTypeDefinition(const XMLCh * name)182 XSTypeDefinition *XSNamespaceItem::getTypeDefinition(const XMLCh *name)
183 {
184 if (name)
185 return (XSTypeDefinition*) fHashMap[XSConstants::TYPE_DEFINITION -1]->get(name);
186 return 0;
187 }
188
getAttributeGroup(const XMLCh * name)189 XSAttributeGroupDefinition *XSNamespaceItem::getAttributeGroup(const XMLCh *name)
190 {
191 if (name)
192 return (XSAttributeGroupDefinition*) fHashMap[XSConstants::ATTRIBUTE_GROUP_DEFINITION -1]->get(name);
193 return 0;
194 }
195
getModelGroupDefinition(const XMLCh * name)196 XSModelGroupDefinition *XSNamespaceItem::getModelGroupDefinition(const XMLCh *name)
197 {
198 if (name)
199 return (XSModelGroupDefinition*) fHashMap[XSConstants::MODEL_GROUP_DEFINITION -1]->get(name);
200 return 0;
201 }
202
getNotationDeclaration(const XMLCh * name)203 XSNotationDeclaration *XSNamespaceItem::getNotationDeclaration(const XMLCh *name)
204 {
205 if (name)
206 return (XSNotationDeclaration*) fHashMap[XSConstants::NOTATION_DECLARATION -1]->get(name);
207 return 0;
208 }
209
getDocumentLocations()210 const StringList *XSNamespaceItem::getDocumentLocations()
211 {
212 if (fGrammar)
213 return ((XMLSchemaDescriptionImpl*) fGrammar->getGrammarDescription())->getLocationHints();
214
215 return 0;
216 }
217
218 XERCES_CPP_NAMESPACE_END
219