GME  13
XSModel.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: XSModel.cpp 674012 2008-07-04 11:18:21Z borisk $
00020  */
00021 
00022 #include <xercesc/framework/psvi/XSModel.hpp>
00023 #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
00024 #include <xercesc/validators/schema/SchemaGrammar.hpp>
00025 #include <xercesc/validators/common/GrammarResolver.hpp>
00026 #include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
00027 #include <xercesc/validators/schema/XercesGroupInfo.hpp>
00028 #include <xercesc/internal/XSObjectFactory.hpp>
00029 #include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
00030 #include <xercesc/framework/psvi/XSElementDeclaration.hpp>
00031 #include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
00032 #include <xercesc/framework/psvi/XSNotationDeclaration.hpp>
00033 #include <xercesc/framework/psvi/XSAnnotation.hpp>
00034 #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
00035 #include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
00036 
00037 XERCES_CPP_NAMESPACE_BEGIN
00038 
00039 // ---------------------------------------------------------------------------
00040 //  XSModel: Constructors and Destructor
00041 // ---------------------------------------------------------------------------
00042 XSModel::XSModel( XMLGrammarPool *grammarPool
00043                 , MemoryManager* const manager)
00044     : fMemoryManager(manager)
00045     , fNamespaceStringList(0)
00046     , fXSNamespaceItemList(0)
00047     , fURIStringPool(0)
00048     , fXSAnnotationList(0)
00049     , fHashNamespace(0)
00050     , fObjFactory(0)
00051     , fDeleteNamespace(0)
00052     , fParent(0)
00053     , fDeleteParent(false)
00054     , fAddedS4SGrammar(false)
00055 {
00056     fURIStringPool = grammarPool->getURIStringPool();
00057     fObjFactory = new (fMemoryManager) XSObjectFactory(manager);
00058 
00059     // Populate XSNamedMaps by going through the components
00060     for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00061     {
00062         switch (i+1)
00063         {
00064             case XSConstants::ATTRIBUTE_DECLARATION:
00065             case XSConstants::ELEMENT_DECLARATION:
00066             case XSConstants::TYPE_DEFINITION:
00067             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00068             case XSConstants::MODEL_GROUP_DEFINITION:
00069             case XSConstants::NOTATION_DECLARATION:
00070                 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
00071                 (
00072                     20,     // size
00073                     29,     // modulus
00074                     fURIStringPool,
00075                     false,  // adoptElems
00076                     fMemoryManager
00077                 );
00078                 break;
00079             default:
00080                 // ATTRIBUTE_USE
00081                 // MODEL_GROUP
00082                 // PARTICLE
00083                 // IDENTITY_CONSTRAINT
00084                 // WILDCARD
00085                 // ANNOTATION
00086                 // FACET
00087                 // MULTIVALUE
00088                 fComponentMap[i] = 0;
00089                 break;
00090         }
00091         fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);
00092     }
00093 
00094     fNamespaceStringList        = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);
00095     fXSNamespaceItemList        = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);
00096     fXSAnnotationList           = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);
00097     fHashNamespace              = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);
00098 
00099     // Loop through all grammars in the grammar pool to create the XSNamespaceItem's
00100     //  which will have access to Annotation Information which can be used later when
00101     //  we create all the XS components.
00102     XSNamespaceItem* namespaceItem = 0;
00103     RefHashTableOfEnumerator<Grammar> grammarEnum = grammarPool->getGrammarEnumerator();
00104     while (grammarEnum.hasMoreElements())
00105     {
00106         SchemaGrammar& sGrammar = (SchemaGrammar&) grammarEnum.nextElement();
00107         if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType ||
00108             XMLString::equals(sGrammar.getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))
00109             continue;
00110 
00111         // NOTE: In the grammarpool, preprocessed grammars without targetnamespace
00112         //       will use an empty string...
00113         XMLCh* NameSpace = XMLString::replicate(sGrammar.getTargetNamespace(), manager);
00114         fNamespaceStringList->addElement(NameSpace);
00115         namespaceItem = new (manager) XSNamespaceItem(this, &sGrammar, manager);
00116         fXSNamespaceItemList->addElement(namespaceItem);
00117         fHashNamespace->put(NameSpace, namespaceItem);
00118     }
00119 
00120     // Now loop through all of the NamespaceItem's
00121     // First, we add S4S namespace (irrespective of whether we have any grammars)
00122     namespaceItem = new (manager) XSNamespaceItem
00123     (
00124         this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager
00125     );
00126 
00127     fNamespaceStringList->addElement
00128     (
00129         XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager)
00130     );
00131     fXSNamespaceItemList->addElement(namespaceItem);
00132     fHashNamespace->put
00133     (
00134         (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA
00135         , namespaceItem
00136     );
00137 
00138     DatatypeValidatorFactory dvFactory(manager);
00139     addS4SToXSModel
00140     (
00141         namespaceItem
00142         , dvFactory.getBuiltInRegistry()
00143     );
00144     // don't include  S4S (thus the -1)
00145     XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size() -1;
00146     for (XMLSize_t j = 0; j < numberOfNamespaces; j++)
00147         addGrammarToXSModel(fXSNamespaceItemList->elementAt(j));
00148 }
00149 
00150 XSModel::XSModel( XSModel *baseModel
00151                 , GrammarResolver *grammarResolver
00152                 , MemoryManager* const manager)
00153     : fMemoryManager(manager)
00154     , fNamespaceStringList(0)
00155     , fXSNamespaceItemList(0)
00156     , fURIStringPool(0)
00157     , fXSAnnotationList(0)
00158     , fHashNamespace(0)
00159     , fObjFactory(0)
00160     , fDeleteNamespace(0)
00161     , fParent(baseModel)
00162     , fDeleteParent(true)
00163     , fAddedS4SGrammar(false)
00164 {
00165     fURIStringPool = grammarResolver->getStringPool();
00166     fObjFactory = new (manager) XSObjectFactory(manager);
00167 
00168     XMLSize_t i;
00169     // Populate XSNamedMaps by going through the components
00170     for (i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00171     {
00172         switch (i+1)
00173         {
00174             case XSConstants::ATTRIBUTE_DECLARATION:
00175             case XSConstants::ELEMENT_DECLARATION:
00176             case XSConstants::TYPE_DEFINITION:
00177             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00178             case XSConstants::MODEL_GROUP_DEFINITION:
00179             case XSConstants::NOTATION_DECLARATION:
00180                 fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
00181                 (
00182                     20,     // size
00183                     29,     // modulus
00184                     fURIStringPool,
00185                     false,  // adoptElems
00186                     fMemoryManager
00187                 );
00188                 break;
00189             default:
00190                 // ATTRIBUTE_USE
00191                 // MODEL_GROUP
00192                 // PARTICLE
00193                 // IDENTITY_CONSTRAINT
00194                 // WILDCARD
00195                 // ANNOTATION
00196                 // FACET
00197                 // MULTIVALUE
00198                 fComponentMap[i] = 0;
00199                 break;
00200         }
00201         fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);
00202     }
00203 
00204     fNamespaceStringList        = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);
00205     fXSNamespaceItemList        = new (manager) RefVectorOf <XSNamespaceItem>(10, false, manager);
00206     fDeleteNamespace            = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);
00207     fXSAnnotationList           = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);
00208     fHashNamespace              = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);
00209 
00210     if (fParent)
00211     {
00212         if (fParent->fAddedS4SGrammar)
00213             fAddedS4SGrammar = true;
00214 
00215         // Need to copy information from parent so it can be returned in this object...
00216         for (i=0; i<fParent->fXSNamespaceItemList->size(); i++)
00217         {
00218             XSNamespaceItem* namespaceItem = fParent->fXSNamespaceItemList->elementAt(i);
00219             fXSNamespaceItemList->addElement(namespaceItem);
00220             fNamespaceStringList->addElement
00221             (
00222                 XMLString::replicate
00223                 (
00224                     namespaceItem->getSchemaNamespace(), manager
00225                 )
00226             );
00227         }
00228 
00229         for (i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00230         {
00231             switch (i+1)
00232             {
00233                 case XSConstants::ATTRIBUTE_DECLARATION:
00234                 case XSConstants::ELEMENT_DECLARATION:
00235                 case XSConstants::TYPE_DEFINITION:
00236                 case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00237                 case XSConstants::MODEL_GROUP_DEFINITION:
00238                 case XSConstants::NOTATION_DECLARATION:
00239                     for (XMLSize_t j=0; j<fParent->fComponentMap[i]->getLength(); j++)
00240                     {
00241                         XSObject* copyObj = fParent->fComponentMap[i]->item(j);
00242                         fComponentMap[i]->addElement(copyObj,
00243                                                      copyObj->getName(),
00244                                                      copyObj->getNamespace());
00245                     }
00246                 break;
00247             }
00248             for (XMLSize_t j=0; j<fParent->fIdVector[i]->size(); j++)
00249             {
00250                 fIdVector[i]->addElement(fParent->fIdVector[i]->elementAt(j));
00251             }
00252         }
00253 
00254         for (i=0; i<fParent->fXSAnnotationList->size(); i++)
00255         {
00256             fXSAnnotationList->addElement(fParent->fXSAnnotationList->elementAt(i));
00257         }
00258 
00259     } // end of copying parent info
00260 
00261     // Now add information from the new grammars but first create the
00262     // XSNamespaceItem's so we can have access to the XSAnnotations...
00263     ValueVectorOf<SchemaGrammar*>* grammarsToAdd = grammarResolver->getGrammarsToAddToXSModel();
00264     XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size();
00265     XMLSize_t numberOfNamespacesToAdd = 0;
00266     for (i=0; i < grammarsToAdd->size(); i++)
00267     {
00268         SchemaGrammar* lGrammar = grammarsToAdd->elementAt(i);
00269         if (lGrammar->getGrammarType() != Grammar::SchemaGrammarType ||
00270             XMLString::equals(lGrammar->getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))
00271             continue;
00272 
00273         XMLCh* NameSpace = XMLString::replicate(lGrammar->getTargetNamespace(), manager);
00274         fNamespaceStringList->addElement(NameSpace);
00275 
00276         XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem(this, lGrammar, manager);
00277         fXSNamespaceItemList->addElement(namespaceItem);
00278         fHashNamespace->put(NameSpace, namespaceItem);
00279         fDeleteNamespace->addElement(namespaceItem);
00280         ++numberOfNamespacesToAdd;
00281     }
00282 
00283     // Add S4S namespace if needed
00284     if (!fAddedS4SGrammar)
00285     {
00286         DatatypeValidatorFactory dvFactory(manager);
00287 
00288         XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem
00289         (
00290             this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager
00291         );
00292 
00293         fNamespaceStringList->addElement
00294         (
00295             XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager)
00296         );
00297         fXSNamespaceItemList->addElement(namespaceItem);
00298         fHashNamespace->put
00299         (
00300             (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA , namespaceItem
00301         );
00302         fDeleteNamespace->addElement(namespaceItem);
00303         addS4SToXSModel
00304         (
00305             namespaceItem
00306             , dvFactory.getBuiltInRegistry()
00307         );
00308     }
00309 
00310     // Now loop through all of the newly created NamespaceItem's
00311     for (i=numberOfNamespaces; i<(numberOfNamespaces+numberOfNamespacesToAdd); i++)
00312     {
00313         addGrammarToXSModel(fXSNamespaceItemList->elementAt(i));
00314     } // end of namespaceItem loop
00315 }
00316 
00317 XSModel::~XSModel()
00318 {
00319     for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
00320     {
00321         switch (i+1)
00322         {
00323             case XSConstants::ATTRIBUTE_DECLARATION:
00324             case XSConstants::ELEMENT_DECLARATION:
00325             case XSConstants::TYPE_DEFINITION:
00326             case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
00327             case XSConstants::MODEL_GROUP_DEFINITION:
00328             case XSConstants::NOTATION_DECLARATION:
00329                 delete fComponentMap[i];
00330                 break;
00331         }
00332         delete fIdVector[i];
00333     }
00334 
00335     delete fNamespaceStringList;
00336     delete fXSNamespaceItemList;
00337     delete fXSAnnotationList;
00338     delete fHashNamespace;
00339     delete fObjFactory;
00340 
00341     if (fDeleteNamespace)
00342         delete fDeleteNamespace;
00343 
00344     if (fDeleteParent && fParent && fParent->fDeleteParent)
00345         delete fParent;
00346 }
00347 
00348 // ---------------------------------------------------------------------------
00349 //  XSModel: Helper methods
00350 // ---------------------------------------------------------------------------
00351 void XSModel::addComponentToIdVector(XSObject* const component,
00352                                      XMLSize_t componentIndex)
00353 {
00354     component->setId(fIdVector[componentIndex]->size());
00355     fIdVector[componentIndex]->addElement(component);
00356 }
00357 
00358 
00359 void XSModel::addComponentToNamespace(XSNamespaceItem* const namespaceItem,
00360                                       XSObject* const component,
00361                                       XMLSize_t componentIndex,
00362                                       bool addToXSModel)
00363 {
00364     namespaceItem->fComponentMap[componentIndex]->addElement
00365     (
00366         component, component->getName(), namespaceItem->getSchemaNamespace()
00367     );
00368     namespaceItem->fHashMap[componentIndex]->put
00369     (
00370         (void *) component->getName(), component
00371     );
00372 
00373     if (addToXSModel)
00374     {
00375         fComponentMap[componentIndex]->addElement
00376         (
00377             component, component->getName(), namespaceItem->getSchemaNamespace()
00378         );
00379     }
00380 }
00381 
00382 void
00383 XSModel::addS4SToXSModel(XSNamespaceItem* const namespaceItem,
00384                          RefHashTableOf<DatatypeValidator>* const builtInDV)
00385 {
00386     addComponentToNamespace
00387     (
00388         namespaceItem
00389         , fObjFactory->addOrFind
00390           (
00391               ComplexTypeInfo::getAnyType
00392               (
00393                   fURIStringPool->getId(XMLUni::fgZeroLenString)
00394               )
00395               , this
00396           )
00397         , XSConstants::TYPE_DEFINITION - 1
00398     );
00399 
00400     // Loop through built-in simple types
00401     // First add 'anySimpleType' which is the base for the other built-ins
00402     DatatypeValidator* dv = builtInDV->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
00403     addComponentToNamespace
00404     (
00405         namespaceItem
00406         , fObjFactory->addOrFind(dv, this, true)
00407         , XSConstants::TYPE_DEFINITION - 1
00408     );
00409 
00410     // add remaining built-in
00411     RefHashTableOfEnumerator<DatatypeValidator> simpleEnum =
00412         RefHashTableOfEnumerator<DatatypeValidator> (builtInDV, false, fMemoryManager);
00413     while (simpleEnum.hasMoreElements())
00414     {
00415         DatatypeValidator& curSimple = simpleEnum.nextElement();
00416         if (&curSimple == dv)
00417             continue;
00418 
00419         addComponentToNamespace
00420         (
00421             namespaceItem
00422             , fObjFactory->addOrFind(&curSimple, this)
00423             , XSConstants::TYPE_DEFINITION - 1
00424         );
00425     }
00426 
00427     // Set flag to indicate that we have added S4S grammar info
00428     fAddedS4SGrammar = true;
00429 }
00430 
00431 
00432 void XSModel::addGrammarToXSModel(XSNamespaceItem* namespaceItem)
00433 {
00434     // Loop through top-level attribute declarations in the grammar...
00435     RefHashTableOf<XMLAttDef>* attDeclRegistry = namespaceItem->fGrammar->getAttributeDeclRegistry();
00436     if(attDeclRegistry) {
00437         RefHashTableOfEnumerator<XMLAttDef> attrEnum = RefHashTableOfEnumerator<XMLAttDef> (attDeclRegistry, false, fMemoryManager);
00438         while (attrEnum.hasMoreElements())
00439         {
00440             XSAttributeDeclaration* xsAttrDecl = fObjFactory->addOrFind
00441             (
00442                 (SchemaAttDef*) &(attrEnum.nextElement()), this
00443             );
00444 
00445             addComponentToNamespace
00446             (
00447                 namespaceItem, xsAttrDecl, XSConstants::ATTRIBUTE_DECLARATION - 1
00448             );
00449         } // end of attribute loop
00450     }
00451 
00452     // Loop through top-level elements in the grammar...
00453     RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = namespaceItem->fGrammar->getElemEnumerator();
00454     while (elemEnum.hasMoreElements())
00455     {
00456         SchemaElementDecl& curElem = elemEnum.nextElement();
00457         if (curElem.getEnclosingScope() == Grammar::TOP_LEVEL_SCOPE)
00458         {
00459             XSElementDeclaration* xsElemDecl = fObjFactory->addOrFind
00460             (
00461                 &curElem, this
00462             );
00463 
00464             addComponentToNamespace
00465             (
00466                 namespaceItem, xsElemDecl, XSConstants::ELEMENT_DECLARATION -1
00467             );
00468         }
00469     } // end of element loop
00470 
00471     // Now loop through top-level User Defined simple type definitions in the grammar...
00472     DVHashTable* dvHT = namespaceItem->fGrammar->getDatatypeRegistry()->getUserDefinedRegistry();
00473     if (dvHT)
00474     {
00475         RefHashTableOfEnumerator<DatatypeValidator> simpleUserEnum = RefHashTableOfEnumerator<DatatypeValidator> (dvHT, false, fMemoryManager);
00476         while (simpleUserEnum.hasMoreElements())
00477         {
00478             DatatypeValidator& curSimple = simpleUserEnum.nextElement();
00479             if (!curSimple.getAnonymous())
00480             {
00481                 addComponentToNamespace
00482                 (
00483                     namespaceItem
00484                     , fObjFactory->addOrFind(&curSimple, this)
00485                     , XSConstants::TYPE_DEFINITION - 1
00486                 );
00487             }
00488         } // end of simple User loop
00489     }
00490 
00491     // Loop through top-level COMPLEX type definitions in the grammar...
00492     RefHashTableOf<ComplexTypeInfo>* complexTypeRegistry = namespaceItem->fGrammar->getComplexTypeRegistry();
00493     if(complexTypeRegistry) {
00494         RefHashTableOfEnumerator<ComplexTypeInfo> complexEnum = RefHashTableOfEnumerator<ComplexTypeInfo> (complexTypeRegistry, false, fMemoryManager);
00495         while (complexEnum.hasMoreElements())
00496         {
00497             ComplexTypeInfo&  curComplex = complexEnum.nextElement();
00498             if (!curComplex.getAnonymous())
00499             {
00500                 addComponentToNamespace
00501                 (
00502                     namespaceItem
00503                     , fObjFactory->addOrFind(&curComplex, this)
00504                     , XSConstants::TYPE_DEFINITION - 1
00505                 );
00506             }
00507         }  // end of type definition loop
00508     }
00509 
00510     // Loop through top-level attribute group definitions in the grammar...
00511     RefHashTableOf<XercesAttGroupInfo>* attGroupInfoRegistry = namespaceItem->fGrammar->getAttGroupInfoRegistry();
00512     if(attGroupInfoRegistry) {
00513         RefHashTableOfEnumerator<XercesAttGroupInfo> attrGroupEnum = RefHashTableOfEnumerator<XercesAttGroupInfo> (attGroupInfoRegistry, false, fMemoryManager);
00514         while (attrGroupEnum.hasMoreElements())
00515         {
00516             addComponentToNamespace
00517             (
00518                 namespaceItem
00519                 , fObjFactory->createXSAttGroupDefinition
00520                   (
00521                       &(attrGroupEnum.nextElement()), this
00522                   )
00523                 , XSConstants::ATTRIBUTE_GROUP_DEFINITION - 1
00524             );
00525         } // end of attribute group loop
00526     }
00527 
00528     // Loop through top-level model group definitions in the grammar...
00529     RefHashTableOf<XercesGroupInfo>* groupInfoRegistry = namespaceItem->fGrammar->getGroupInfoRegistry();
00530     if(groupInfoRegistry) {
00531         RefHashTableOfEnumerator<XercesGroupInfo> modelGroupEnum = RefHashTableOfEnumerator<XercesGroupInfo> (groupInfoRegistry, false, fMemoryManager);
00532         while (modelGroupEnum.hasMoreElements())
00533         {
00534             addComponentToNamespace
00535             (
00536                 namespaceItem
00537                 , fObjFactory->createXSModelGroupDefinition
00538                   (
00539                       &(modelGroupEnum.nextElement()), this
00540                   )
00541                 , XSConstants::MODEL_GROUP_DEFINITION - 1
00542             );
00543         } // end of model group loop
00544     }
00545 
00546     // Loop through notations in the grammar...
00547     NameIdPoolEnumerator<XMLNotationDecl> notationEnum = namespaceItem->fGrammar->getNotationEnumerator();
00548     while (notationEnum.hasMoreElements())
00549     {
00550         addComponentToNamespace
00551         (
00552             namespaceItem
00553             , fObjFactory->addOrFind(&(notationEnum.nextElement()), this)
00554             , XSConstants::NOTATION_DECLARATION - 1
00555         );
00556     } // end of notation loop
00557 
00558     // Loop through annotations in the grammar...
00559     // As annotations are already created as XSAnnotations no need to create them
00560     // or store them in the XercesToXSMap.
00561     XSAnnotation* annot = namespaceItem->fGrammar->getAnnotation();
00562     while (annot)
00563     {
00564         fXSAnnotationList->addElement(annot);
00565         namespaceItem->fXSAnnotationList->addElement(annot);
00566         addComponentToIdVector(annot, XSConstants::ANNOTATION -1);
00567         annot = annot->getNext();
00568     } // end of annotation loop
00569 }
00570 
00571 
00572 
00573 
00574 // ---------------------------------------------------------------------------
00575 //  XSModel: Access methods
00576 // ---------------------------------------------------------------------------
00587 XSNamedMap <XSObject> *XSModel::getComponents(XSConstants::COMPONENT_TYPE objectType)
00588 {
00589     return fComponentMap[objectType -1];
00590 }
00591 
00604 XSNamedMap <XSObject> *XSModel::getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType,
00605                                                const XMLCh *compNamespace)
00606 {
00607     XSNamespaceItem* namespaceItem;
00608     if (compNamespace)
00609         namespaceItem = getNamespaceItem(compNamespace);
00610     else
00611         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00612 
00613     if (namespaceItem)
00614         return namespaceItem->getComponents(objectType);
00615 
00616     return 0;
00617 }
00618 
00622 XSAnnotationList *XSModel::getAnnotations()
00623 {
00624     return fXSAnnotationList;
00625 }
00626 
00634 XSElementDeclaration *XSModel::getElementDeclaration(const XMLCh *name
00635             , const XMLCh *compNamespace)
00636 {
00637     XSNamespaceItem* namespaceItem;
00638     if (compNamespace)
00639         namespaceItem = getNamespaceItem(compNamespace);
00640     else
00641         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00642 
00643     if (namespaceItem)
00644         return namespaceItem->getElementDeclaration(name);
00645 
00646     return 0;
00647 }
00648 
00656 XSAttributeDeclaration *XSModel::getAttributeDeclaration(const XMLCh *name
00657             , const XMLCh *compNamespace)
00658 {
00659     XSNamespaceItem* namespaceItem;
00660     if (compNamespace)
00661         namespaceItem = getNamespaceItem(compNamespace);
00662     else
00663         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00664 
00665     if (namespaceItem)
00666         return namespaceItem->getAttributeDeclaration(name);
00667 
00668     return 0;
00669 }
00670 
00679 XSTypeDefinition *XSModel::getTypeDefinition(const XMLCh *name
00680             , const XMLCh *compNamespace)
00681 {
00682     XSNamespaceItem* namespaceItem;
00683     if (compNamespace)
00684         namespaceItem = getNamespaceItem(compNamespace);
00685     else
00686         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00687 
00688     if (namespaceItem)
00689         return namespaceItem->getTypeDefinition(name);
00690 
00691     return 0;
00692 }
00693 
00701 XSAttributeGroupDefinition *XSModel::getAttributeGroup(const XMLCh *name
00702             , const XMLCh *compNamespace)
00703 {
00704     XSNamespaceItem* namespaceItem;
00705     if (compNamespace)
00706         namespaceItem = getNamespaceItem(compNamespace);
00707     else
00708         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00709 
00710     if (namespaceItem)
00711         return namespaceItem->getAttributeGroup(name);
00712 
00713     return 0;
00714 }
00715 
00723 XSModelGroupDefinition *XSModel::getModelGroupDefinition(const XMLCh *name
00724             , const XMLCh *compNamespace)
00725 {
00726     XSNamespaceItem* namespaceItem;
00727     if (compNamespace)
00728         namespaceItem = getNamespaceItem(compNamespace);
00729     else
00730         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00731 
00732     if (namespaceItem)
00733         return namespaceItem->getModelGroupDefinition(name);
00734 
00735     return 0;
00736 }
00737 
00745 XSNotationDeclaration *XSModel::getNotationDeclaration(const XMLCh *name
00746             , const XMLCh *compNamespace)
00747 {
00748     XSNamespaceItem* namespaceItem;
00749     if (compNamespace)
00750         namespaceItem = getNamespaceItem(compNamespace);
00751     else
00752         namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
00753 
00754     if (namespaceItem)
00755         return namespaceItem->getNotationDeclaration(name);
00756 
00757     return 0;
00758 }
00759 
00769 XSObject *XSModel::getXSObjectById(XMLSize_t  compId
00770             , XSConstants::COMPONENT_TYPE compType)
00771 {
00772     if (compId < fIdVector[compType -1]->size())
00773         return fIdVector[compType -1]->elementAt(compId);
00774 
00775     return 0;
00776 }
00777 
00778 XSNamespaceItem* XSModel::getNamespaceItem(const XMLCh* const key)
00779 {
00780     XSNamespaceItem* xsName = fHashNamespace->get(key);
00781     if (xsName)
00782         return xsName;
00783     if (fParent)
00784         return fParent->getNamespaceItem(key);
00785     return 0;
00786 }
00787 
00788 XSObject* XSModel::getXSObject(void* key)
00789 {
00790     XSObject* xsObj = fObjFactory->getObjectFromMap(key);
00791 
00792     if (!xsObj && fParent)
00793         xsObj = fParent->getXSObject(key);
00794 
00795     return xsObj;
00796 }
00797 
00798 
00799 XERCES_CPP_NAMESPACE_END