THRIFT-3417: "namespace xsd" is not really working
Client: XSD
Patch: Benjamin Gould
This closes #691
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index fd3685d..1301656 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -260,6 +260,11 @@
f_xsd_.open(f_xsd_name.c_str());
string ns = program_->get_namespace("xsd");
+ const std::map<std::string, std::string> annot = program_->get_namespace_annotations("xsd");
+ const std::map<std::string, std::string>::const_iterator uri = annot.find("uri");
+ if (uri != annot.end()) {
+ ns = uri->second;
+ }
if (ns.size() > 0) {
ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" "
+ "elementFormDefault=\"qualified\"";
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 556ee6c..c973b13 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -324,6 +324,15 @@
const std::map<std::string, std::string>& get_all_namespaces(){
return namespaces_;
}
+
+ void set_namespace_annotations(std::string language, std::map<std::string, std::string> annotations) {
+ namespace_annotations_[language] = annotations;
+ }
+
+ const std::map<std::string, std::string>& get_namespace_annotations(std::string language) {
+ return namespace_annotations_[language];
+ }
+
// Language specific namespace / packaging
void add_cpp_include(std::string path) { cpp_includes_.push_back(path); }
@@ -371,6 +380,9 @@
// Dynamic namespaces
std::map<std::string, std::string> namespaces_;
+ // Annotations for dynamic namespaces
+ std::map<std::string, std::map<std::string, std::string>> namespace_annotations_;
+
// C++ extra includes
std::vector<std::string> cpp_includes_;
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index e0dde8c..59f6b4f 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -297,13 +297,17 @@
{
pdebug("Header -> Include");
}
-| tok_namespace tok_identifier tok_identifier
+| tok_namespace tok_identifier tok_identifier TypeAnnotations
{
pdebug("Header -> tok_namespace tok_identifier tok_identifier");
declare_valid_program_doctext();
if (g_parse_mode == PROGRAM) {
g_program->set_namespace($2, $3);
}
+ if ($4 != NULL) {
+ g_program->set_namespace_annotations($2, $4->annotations_);
+ delete $4;
+ }
}
| tok_namespace '*' tok_identifier
{