GME  13
XSNamespaceItem.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XSNamespaceItem.cpp 674012 2008-07-04 11:18:21Z borisk $
00020  */
00021 
00022 #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
00023 #include <xercesc/validators/schema/SchemaGrammar.hpp>
00024 #include <xercesc/framework/psvi/XSModel.hpp>
00025 #include <xercesc/framework/psvi/XSAnnotation.hpp>
00026 #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00030 // ---------------------------------------------------------------------------
00031 //  XSNamespaceItem: Constructors and Destructors
00032 // ---------------------------------------------------------------------------
00033 XSNamespaceItem::XSNamespaceItem(XSModel* const       xsModel,
00034                                  SchemaGrammar* const grammar,
00035                                  MemoryManager* const manager)
00036     : fMemoryManager(manager)
00037     , fGrammar(grammar)
00038     , fXSModel(xsModel)
00039     , fXSAnnotationList(0)
00040     , fSchemaNamespace(grammar->getTargetNamespace())
00041 {
00042     // Populate XSNamedMaps by going through the components
00043     for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00044     {
00045         switch (i+1)
00046         {
00047             case XSConstants::ATTRIBUTE_DECLARATION:
00048             case XSConstants::ELEMENT_DECLARATION:
00049             case XSConstants::TYPE_DEFINITION:
00050             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00051             case XSConstants::MODEL_GROUP_DEFINITION:
00052             case XSConstants::NOTATION_DECLARATION:
00053                 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
00054                 (
00055                     20,     // size
00056                     29,     // modulus
00057                     fXSModel->getURIStringPool(),
00058                     false,  // adoptElems
00059                     fMemoryManager
00060                 );
00061                 fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
00062                 (
00063                     29,
00064                     false,
00065                     fMemoryManager
00066                 );
00067                 break;
00068             default:
00069                 // ATTRIBUTE_USE
00070                 // MODEL_GROUP
00071                 // PARTICLE
00072                 // IDENTITY_CONSTRAINT
00073                 // WILDCARD
00074                 // ANNOTATION
00075                 // FACET
00076                 // MULTIVALUE
00077                 fComponentMap[i] = 0;
00078                 fHashMap[i] = 0;
00079                 break;
00080         }
00081     }
00082 
00083     fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
00084 }
00085 
00086 XSNamespaceItem::XSNamespaceItem(XSModel* const       xsModel,
00087                                  const XMLCh* const   schemaNamespace,
00088                                  MemoryManager* const manager)
00089     : fMemoryManager(manager)
00090     , fGrammar(0)
00091     , fXSModel(xsModel)
00092     , fXSAnnotationList(0)
00093     , fSchemaNamespace(schemaNamespace)
00094 {
00095     // Populate XSNamedMaps by going through the components
00096     for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00097     {
00098         switch (i+1)
00099         {
00100             case XSConstants::ATTRIBUTE_DECLARATION:
00101             case XSConstants::ELEMENT_DECLARATION:
00102             case XSConstants::TYPE_DEFINITION:
00103             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00104             case XSConstants::MODEL_GROUP_DEFINITION:
00105             case XSConstants::NOTATION_DECLARATION:
00106                 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
00107                 (
00108                     20,     // size
00109                     29,     // modulus
00110                     fXSModel->getURIStringPool(),
00111                     false,  // adoptElems
00112                     fMemoryManager
00113                 );
00114                 fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
00115                 (
00116                     29,
00117                     false,
00118                     fMemoryManager
00119                 );
00120                 break;
00121             default:
00122                 // ATTRIBUTE_USE
00123                 // MODEL_GROUP
00124                 // PARTICLE
00125                 // IDENTITY_CONSTRAINT
00126                 // WILDCARD
00127                 // ANNOTATION
00128                 // FACET
00129                 // MULTIVALUE
00130                 fComponentMap[i] = 0;
00131                 fHashMap[i] = 0;
00132                 break;
00133         }
00134     }
00135 
00136     fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
00137 }
00138 
00139 XSNamespaceItem::~XSNamespaceItem()
00140 {
00141     for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00142     {
00143         switch (i+1)
00144         {
00145             case XSConstants::ATTRIBUTE_DECLARATION:
00146             case XSConstants::ELEMENT_DECLARATION:
00147             case XSConstants::TYPE_DEFINITION:
00148             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00149             case XSConstants::MODEL_GROUP_DEFINITION:
00150             case XSConstants::NOTATION_DECLARATION:
00151                 delete fComponentMap[i];
00152                 delete fHashMap[i];
00153                 break;
00154         }
00155     }
00156 
00157     delete fXSAnnotationList;
00158 }
00159 
00160 // ---------------------------------------------------------------------------
00161 //  XSNamespaceItem: access methods
00162 // ---------------------------------------------------------------------------
00163 XSNamedMap<XSObject> *XSNamespaceItem::getComponents(XSConstants::COMPONENT_TYPE objectType)
00164 {
00165     return fComponentMap[objectType -1];
00166 }
00167 
00168 XSElementDeclaration *XSNamespaceItem::getElementDeclaration(const XMLCh *name)
00169 {
00170     if (name)
00171         return (XSElementDeclaration*) fHashMap[XSConstants::ELEMENT_DECLARATION -1]->get(name);
00172     return 0;
00173 }
00174 
00175 XSAttributeDeclaration *XSNamespaceItem::getAttributeDeclaration(const XMLCh *name)
00176 {
00177     if (name)
00178         return (XSAttributeDeclaration*) fHashMap[XSConstants::ATTRIBUTE_DECLARATION -1]->get(name);
00179     return 0;
00180 }
00181 
00182 XSTypeDefinition *XSNamespaceItem::getTypeDefinition(const XMLCh *name)
00183 {
00184     if (name)
00185         return (XSTypeDefinition*) fHashMap[XSConstants::TYPE_DEFINITION -1]->get(name);
00186     return 0;
00187 }
00188 
00189 XSAttributeGroupDefinition *XSNamespaceItem::getAttributeGroup(const XMLCh *name)
00190 {
00191     if (name)
00192         return (XSAttributeGroupDefinition*) fHashMap[XSConstants::ATTRIBUTE_GROUP_DEFINITION -1]->get(name);
00193     return 0;
00194 }
00195 
00196 XSModelGroupDefinition *XSNamespaceItem::getModelGroupDefinition(const XMLCh *name)
00197 {
00198     if (name)
00199         return (XSModelGroupDefinition*) fHashMap[XSConstants::MODEL_GROUP_DEFINITION -1]->get(name);
00200     return 0;
00201 }
00202 
00203 XSNotationDeclaration *XSNamespaceItem::getNotationDeclaration(const XMLCh *name)
00204 {
00205     if (name)
00206         return (XSNotationDeclaration*) fHashMap[XSConstants::NOTATION_DECLARATION -1]->get(name);
00207     return 0;
00208 }
00209 
00210 const StringList *XSNamespaceItem::getDocumentLocations()
00211 {
00212     if (fGrammar)
00213         return ((XMLSchemaDescriptionImpl*) fGrammar->getGrammarDescription())->getLocationHints();
00214 
00215     return 0;
00216 }
00217 
00218 XERCES_CPP_NAMESPACE_END