source: icXML/icXML-devel/src/xercesc/dom/impl/DOMImplementationRegistry.cpp @ 2777

Last change on this file since 2777 was 2777, checked in by cameron, 7 years ago

Set up to use xercesc/icxercesc root-relative paths for all includes

File size: 3.9 KB
Line 
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: DOMImplementationRegistry.cpp 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22#include <xercesc/util/Mutexes.hpp>
23#include <xercesc/util/RefVectorOf.hpp>
24#include <icxercesc/util/PlatformUtils.hpp>
25#include <xercesc/util/XMLInitializer.hpp>
26#include <xercesc/dom/DOMImplementationRegistry.hpp>
27#include <xercesc/dom/DOMImplementationSource.hpp>
28#include <xercesc/dom/DOMImplementation.hpp>
29#include <xercesc/dom/impl/DOMImplementationImpl.hpp>
30#include <xercesc/dom/impl/DOMImplementationListImpl.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34// Points to the singleton instance of a registry of DOMImplementationSource.
35//
36static RefVectorOf<DOMImplementationSource>* gDOMImplSrcVector = 0;
37
38//  Global mutex that is used to synchronize access to the vector.
39//
40static XMLMutex* gDOMImplSrcVectorMutex = 0;
41
42void XMLInitializer::initializeDOMImplementationRegistry()
43{
44    gDOMImplSrcVectorMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager);
45    gDOMImplSrcVector = new RefVectorOf<DOMImplementationSource>(3, false);
46}
47
48void XMLInitializer::terminateDOMImplementationRegistry()
49{
50    delete gDOMImplSrcVector;
51    gDOMImplSrcVector = 0;
52
53    delete gDOMImplSrcVectorMutex;
54    gDOMImplSrcVectorMutex = 0;
55}
56
57// -----------------------------------------------------------------------
58//  DOMImplementationRegistry Functions
59// -----------------------------------------------------------------------
60DOMImplementation *DOMImplementationRegistry::getDOMImplementation(const XMLCh* features) {
61
62    XMLMutexLock lock(gDOMImplSrcVectorMutex);
63
64    XMLSize_t len = gDOMImplSrcVector->size();
65
66    // Put our defined source there
67    if (len == 0) {
68        gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl());
69
70        len = gDOMImplSrcVector->size();
71    }
72
73    for (XMLSize_t i = len; i > 0; i--) {
74        DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1);
75        DOMImplementation* impl = source->getDOMImplementation(features);
76        if (impl)
77            return impl;
78    }
79
80    return 0;
81}
82
83DOMImplementationList* DOMImplementationRegistry::getDOMImplementationList(const XMLCh* features) {
84
85    DOMImplementationListImpl* list = new DOMImplementationListImpl;
86
87    XMLMutexLock lock(gDOMImplSrcVectorMutex);
88
89    XMLSize_t len = gDOMImplSrcVector->size();
90
91    // Put our defined source there
92    if (len == 0)
93        gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl());
94
95    len = gDOMImplSrcVector->size();
96
97    for (XMLSize_t i = len; i > 0; i--) {
98        DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1);
99        DOMImplementationList* oneList = source->getDOMImplementationList(features);
100        XMLSize_t oneListLen=oneList->getLength();
101        for(XMLSize_t j=0; j<oneListLen; j++)
102            list->add(oneList->item(j));
103        oneList->release();
104    }
105
106    return list;
107}
108
109void DOMImplementationRegistry::addSource (DOMImplementationSource* source)
110{
111    XMLMutexLock lock(gDOMImplSrcVectorMutex);
112    gDOMImplSrcVector->addElement(source);
113}
114
115
116XERCES_CPP_NAMESPACE_END
117
Note: See TracBrowser for help on using the repository browser.