1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XERCESTOXALANNODEMAP_HEADER_GUARD_1357924680)
19 #define XERCESTOXALANNODEMAP_HEADER_GUARD_1357924680
20 
21 
22 
23 #include <xalanc/XercesParserLiaison/XercesParserLiaisonDefinitions.hpp>
24 
25 
26 
27 #include <map>
28 
29 
30 
31 #if XERCES_VERSION_MAJOR >= 2
32 #include <xercesc/dom/deprecated/DOM_Node.hpp>
33 #else
34 #include <xercesc/dom/DOM_Node.hpp>
35 #endif
36 
37 
38 
39 #include <xalanc/XercesParserLiaison/Deprecated/XercesDOM_NodeHack.hpp>
40 
41 
42 
43 namespace XERCES_CPP_NAMESPACE
44 {
45     class NodeImpl;
46 }
47 
48 
49 
50 namespace XALAN_CPP_NAMESPACE {
51 
52 
53 
54 class XalanNode;
55 
56 
57 /**
58  * This class is deprecated.
59  *
60  * @deprecated This class works with the deprecated Xerces DOM bridge.
61  */
62 class XALAN_XERCESPARSERLIAISON_EXPORT XercesToXalanNodeMap
63 {
64 public:
65 
66     typedef xercesc::DOM_Node     DOM_NodeType;
67     typedef xercesc::NodeImpl     NodeImplType;
68 
69     typedef std::map<XalanNode*, NodeImplType*>     XalanNodeMapType;
70 
71     typedef std::map<NodeImplType*, XalanNode*>     XercesNodeMapType;
72 
73     XercesToXalanNodeMap();
74 
75     ~XercesToXalanNodeMap();
76 
77     void
78     addAssociation(
79             const DOM_NodeType&     theXercesNode,
80             XalanNode*              theXalanNode);
81 
82     void
83     clear();
84 
85     XalanNode*
getNode(const DOM_NodeType & theXercesNode) const86     getNode(const DOM_NodeType&     theXercesNode) const
87     {
88         return getNode(XercesDOM_NodeHack::getImpl(theXercesNode));
89     }
90 
91     XalanNode*
getNode(NodeImplType * theXercesNodeImpl) const92     getNode(NodeImplType*   theXercesNodeImpl) const
93     {
94         const XercesNodeMapType::const_iterator     i =
95                 m_xercesMap.find(theXercesNodeImpl);
96 
97         if (i == m_xercesMap.end())
98         {
99             return 0;
100         }
101         else
102         {
103             return (*i).second;
104         }
105     }
106 
107     DOM_NodeType
getNode(const XalanNode * theXalanNode) const108     getNode(const XalanNode*    theXalanNode) const
109     {
110         return XercesDOM_NodeHack(getNodeImpl(theXalanNode));
111     }
112 
113     NodeImplType*
114     getNodeImpl(const XalanNode*    theXalanNode) const;
115 
116     class NameMapEqualsFunctor
117     {
118     public:
119 
NameMapEqualsFunctor(const XalanNode * theXalanNode)120         NameMapEqualsFunctor(const XalanNode*   theXalanNode) :
121             m_value(theXalanNode)
122         {
123         }
124 
125         bool
operator ()(const XercesNodeMapType::value_type & thePair) const126         operator()(const XercesNodeMapType::value_type&     thePair) const
127         {
128             return m_value == thePair.second;
129         }
130 
131     private:
132 
133         const XalanNode*    m_value;
134     };
135 
136     NodeImplType*
getNodeImpl(const DOM_NodeType & theXercesNode) const137     getNodeImpl(const DOM_NodeType&     theXercesNode) const
138     {
139         return XercesDOM_NodeHack::getImpl(theXercesNode);
140     }
141 
142 private:
143 
144     XalanNodeMapType    m_xalanMap;
145 
146     XercesNodeMapType   m_xercesMap;
147 };
148 
149 
150 
151 }
152 
153 
154 
155 #endif  // !defined(XERCESTOXALANNODEMAP_HEADER_GUARD_1357924680)
156