Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / ACEXML / common / NamespaceSupport.cpp
blob938ad0bd23d8b628962fd3baf56cd5872015e7f0
1 // -*- C++ -*-
3 #include "ACEXML/common/NamespaceSupport.h"
4 #include "ace/OS_NS_string.h"
6 static const ACEXML_Char ACEXML_XMLNS_PREFIX_name[] = ACE_TEXT ("xmlns");
8 const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name;
10 static const ACEXML_Char ACEXML_DEFAULT_NS_PREFIX[] = {0};
12 static const ACEXML_Char ACEXML_TABOO_NS_PREFIX[] = ACE_TEXT ("xml");
14 static const ACEXML_Char ACEXML_XMLNS_URI_name[] = ACE_TEXT ("http://www.w3.org/XML/1998/namespace");
15 const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS = ACEXML_XMLNS_URI_name;
17 ACEXML_Namespace_Context_Stack::ACEXML_Namespace_Context_Stack ()
21 ACEXML_Namespace_Context_Stack::~ACEXML_Namespace_Context_Stack ()
23 // Clean up stuff.
26 int
27 ACEXML_Namespace_Context_Stack::push (ACEXML_NS_CONTEXT *nsc)
29 return (this->stack_.push (nsc) < 0);
32 ACEXML_NS_CONTEXT *
33 ACEXML_Namespace_Context_Stack::pop ()
35 if (this->stack_.size() <= 0)
36 return 0;
38 ACEXML_NS_CONTEXT* temp = 0;
39 int retval = this->stack_.pop (temp);
40 if (retval != 0)
42 ACE_ERROR ((LM_ERROR, "Unable to pop Namespace context from stack\n"));
43 return 0;
45 return temp;
48 int
49 ACEXML_NamespaceSupport::popContext ()
51 delete this->effective_context_;
53 if ((this->effective_context_ = this->ns_stack_.pop ()) == 0)
54 return -1;
55 return 0;
58 int
59 ACEXML_NamespaceSupport::pushContext ()
61 ACEXML_NS_CONTEXT *temp = this->effective_context_;
62 ACE_NEW_RETURN (this->effective_context_,
63 ACEXML_NS_CONTEXT (),
64 -1);
66 // @@ Copy everything from the old context to the new one.
67 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
69 for (ACEXML_NS_CONTEXT_ITER iter (*temp);
70 iter.next (entry) != 0;
71 iter.advance ())
72 this->effective_context_->bind (entry->ext_id_,
73 entry->int_id_);
74 this->ns_stack_.push (temp);
75 return 0;
78 ACEXML_NamespaceSupport::ACEXML_NamespaceSupport ()
79 : ns_stack_ (),
80 effective_context_ (0)
83 int
84 ACEXML_NamespaceSupport::init ()
86 // @@ No way to tell if the new fails.
87 ACE_NEW_RETURN (effective_context_, ACEXML_NS_CONTEXT(), -1);
89 ACEXML_String prefix (ACEXML_TABOO_NS_PREFIX, 0, false);
90 ACEXML_String uri (ACEXML_XMLNS_URI_name, 0, false);
91 return this->effective_context_->bind (prefix, uri);
94 ACEXML_NamespaceSupport::~ACEXML_NamespaceSupport ()
96 while (this->popContext () == 0)
101 ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char *prefix,
102 const ACEXML_Char *uri)
104 if (!prefix || !uri)
105 return -1;
107 // Unless predefined by w3.org(?) NS prefix can never start with
108 // "xml".
109 if (ACE_OS::strcmp (ACEXML_TABOO_NS_PREFIX, prefix) == 0)
110 return -1;
112 ACEXML_String ns_prefix (prefix, 0, false);
113 ACEXML_String ns_uri (uri, 0, false);
115 return this->effective_context_->rebind (ns_prefix, ns_uri);
119 ACEXML_NamespaceSupport::getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const
121 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
123 // The prefix for default namespace (empty string) is included in
124 // the return list.
125 for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
126 iter.next (entry) != 0;
127 iter.advance ())
128 prefixes.enqueue_tail (entry->ext_id_.c_str ());
130 return 0;
133 const ACEXML_Char *
134 ACEXML_NamespaceSupport::getPrefix (const ACEXML_Char *uri) const
136 if (!uri || *uri == 0)
137 return 0;
139 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
141 for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
142 iter.next (entry) != 0;
143 iter.advance ())
144 if (entry->int_id_ == ACEXML_String (uri, 0, false))
145 return entry->ext_id_.c_str ();
147 return 0; // Nothing found.
151 ACEXML_NamespaceSupport::getPrefixes (ACEXML_STR_LIST &prefixes) const
153 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
155 // The prefix for default namespace (empty string) is not included
156 // in the return list.
157 for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
158 iter.next (entry) != 0;
159 iter.advance ())
160 prefixes.enqueue_tail (entry->ext_id_.c_str ());
161 return 0;
165 ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri,
166 ACEXML_STR_LIST &prefixes) const
168 if (!uri)
169 return -1;
171 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
173 for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
174 iter.next (entry) != 0;
175 iter.advance ())
176 if (entry->int_id_ == ACEXML_String (uri, 0, false) &&
177 entry->ext_id_ != ACEXML_String (ACEXML_DEFAULT_NS_PREFIX, 0, false))
178 prefixes.enqueue_tail (entry->ext_id_.c_str ());
179 else
180 continue;
182 return 0; // Nothing found.
185 const ACEXML_Char *
186 ACEXML_NamespaceSupport::getURI (const ACEXML_Char *prefix) const
188 if (!prefix)
189 return 0;
191 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
193 if (this->effective_context_->find (ACEXML_String (prefix, 0, false),
194 entry) == 0)
195 return entry->int_id_.c_str ();
196 return 0;
200 ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName,
201 const ACEXML_Char *&uri,
202 const ACEXML_Char *&name,
203 int is_attribute) const
205 int qlen = static_cast<int> (ACE_OS::strlen (qName));
206 int len = -1;
207 for (int i = 0; i < qlen; ++i)
208 if (qName [i] == ':')
210 len = i;
211 break;
214 ACEXML_String prefix (ACE_TEXT (""), 0, false);
215 if (len == -1)
216 name = qName;
217 else
219 prefix.set (qName, len, 1);
220 name = qName + len + 1;
223 if (is_attribute && len == -1) {
224 uri = ACEXML_DEFAULT_NS_PREFIX;
225 return 0;
228 ACEXML_NS_CONTEXT_ENTRY *entry = 0;
230 if (this->effective_context_->find (prefix, entry) == 0)
231 uri = entry->int_id_.c_str ();
232 else
234 uri = ACEXML_DEFAULT_NS_PREFIX;
235 return -1;
237 return 0;
241 ACEXML_NamespaceSupport::reset ()
243 while (this->popContext() != -1)
245 return 0;