GME
13
|
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: DOMImplementationRegistry.cpp 676911 2008-07-15 13:27:32Z amassari $ 00020 */ 00021 00022 #include <xercesc/util/Mutexes.hpp> 00023 #include <xercesc/util/RefVectorOf.hpp> 00024 #include <xercesc/util/PlatformUtils.hpp> 00025 #include <xercesc/util/XMLInitializer.hpp> 00026 #include <xercesc/dom/DOMImplementationRegistry.hpp> 00027 #include <xercesc/dom/DOMImplementationSource.hpp> 00028 #include <xercesc/dom/DOMImplementation.hpp> 00029 #include "DOMImplementationImpl.hpp" 00030 #include "DOMImplementationListImpl.hpp" 00031 00032 XERCES_CPP_NAMESPACE_BEGIN 00033 00034 // Points to the singleton instance of a registry of DOMImplementationSource. 00035 // 00036 static RefVectorOf<DOMImplementationSource>* gDOMImplSrcVector = 0; 00037 00038 // Global mutex that is used to synchronize access to the vector. 00039 // 00040 static XMLMutex* gDOMImplSrcVectorMutex = 0; 00041 00042 void XMLInitializer::initializeDOMImplementationRegistry() 00043 { 00044 gDOMImplSrcVectorMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); 00045 gDOMImplSrcVector = new RefVectorOf<DOMImplementationSource>(3, false); 00046 } 00047 00048 void XMLInitializer::terminateDOMImplementationRegistry() 00049 { 00050 delete gDOMImplSrcVector; 00051 gDOMImplSrcVector = 0; 00052 00053 delete gDOMImplSrcVectorMutex; 00054 gDOMImplSrcVectorMutex = 0; 00055 } 00056 00057 // ----------------------------------------------------------------------- 00058 // DOMImplementationRegistry Functions 00059 // ----------------------------------------------------------------------- 00060 DOMImplementation *DOMImplementationRegistry::getDOMImplementation(const XMLCh* features) { 00061 00062 XMLMutexLock lock(gDOMImplSrcVectorMutex); 00063 00064 XMLSize_t len = gDOMImplSrcVector->size(); 00065 00066 // Put our defined source there 00067 if (len == 0) { 00068 gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl()); 00069 00070 len = gDOMImplSrcVector->size(); 00071 } 00072 00073 for (XMLSize_t i = len; i > 0; i--) { 00074 DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1); 00075 DOMImplementation* impl = source->getDOMImplementation(features); 00076 if (impl) 00077 return impl; 00078 } 00079 00080 return 0; 00081 } 00082 00083 DOMImplementationList* DOMImplementationRegistry::getDOMImplementationList(const XMLCh* features) { 00084 00085 DOMImplementationListImpl* list = new DOMImplementationListImpl; 00086 00087 XMLMutexLock lock(gDOMImplSrcVectorMutex); 00088 00089 XMLSize_t len = gDOMImplSrcVector->size(); 00090 00091 // Put our defined source there 00092 if (len == 0) 00093 gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl()); 00094 00095 len = gDOMImplSrcVector->size(); 00096 00097 for (XMLSize_t i = len; i > 0; i--) { 00098 DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1); 00099 DOMImplementationList* oneList = source->getDOMImplementationList(features); 00100 XMLSize_t oneListLen=oneList->getLength(); 00101 for(XMLSize_t j=0; j<oneListLen; j++) 00102 list->add(oneList->item(j)); 00103 oneList->release(); 00104 } 00105 00106 return list; 00107 } 00108 00109 void DOMImplementationRegistry::addSource (DOMImplementationSource* source) 00110 { 00111 XMLMutexLock lock(gDOMImplSrcVectorMutex); 00112 gDOMImplSrcVector->addElement(source); 00113 } 00114 00115 00116 XERCES_CPP_NAMESPACE_END 00117