Xerces 3 revisions.
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.cpp
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * Namespace.cpp
19  * 
20  * Representing XML namespace attributes 
21  */
22
23 #include "internal.h"
24 #include "Namespace.h"
25
26 using namespace xmltooling;
27
28 using xercesc::XMLString;
29
30 Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix, bool alwaysDeclare) : m_pinned(alwaysDeclare)
31 {
32 #ifndef HAVE_GOOD_STL
33     m_uri=m_prefix=NULL;
34 #endif
35     setNamespaceURI(uri);
36     setNamespacePrefix(prefix);
37 }
38
39 Namespace::~Namespace()
40 {
41 #ifndef HAVE_GOOD_STL
42     XMLString::release(&m_uri);
43     XMLString::release(&m_prefix);
44 #endif
45 }
46
47 void Namespace::setNamespacePrefix(const XMLCh* prefix)
48 {
49 #ifdef HAVE_GOOD_STL
50     if (prefix)
51         m_prefix=prefix;
52     else
53         m_prefix.erase();
54 #else
55     if (m_prefix)
56         XMLString::release(&m_prefix);
57     m_prefix=XMLString::replicate(prefix);
58 #endif
59 }
60
61 void Namespace::setNamespaceURI(const XMLCh* uri)
62 {
63 #ifdef HAVE_GOOD_STL
64     if (uri)
65         m_uri=uri;
66     else
67         m_uri.erase();
68 #else
69     if (m_uri)
70         XMLString::release(&m_uri);
71     m_uri=XMLString::replicate(uri);
72 #endif
73 }
74
75 #ifndef HAVE_GOOD_STL
76 Namespace::Namespace(const Namespace& src)
77 {
78     m_uri=XMLString::replicate(src.getNamespaceURI());
79     m_prefix=XMLString::replicate(src.getNamespacePrefix());
80     m_pinned=src.alwaysDeclare();
81 }
82
83 Namespace& Namespace::operator=(const Namespace& src)
84 {
85     m_uri=XMLString::replicate(src.getNamespaceURI());
86     m_prefix=XMLString::replicate(src.getNamespacePrefix());
87     m_pinned=src.alwaysDeclare();
88     return *this;
89 }
90
91 bool xmltooling::operator==(const Namespace& op1, const Namespace& op2)
92 {
93     if (&op1 == &op2)
94         return true;
95     return (XMLString::equals(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
96             XMLString::equals(op1.getNamespacePrefix(),op2.getNamespacePrefix()));
97 }
98 #endif
99
100 bool xmltooling::operator<(const Namespace& op1, const Namespace& op2)
101 {
102     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
103     if (i<0)
104         return true;
105     else if (i==0)
106         return (XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix())<0);
107     else
108         return false;
109 }