Repository: thrift
Updated Branches:
  refs/heads/master a6b120301 -> eeb51962f


THRIFT-3417: "namespace xsd" is not really working
Client: XSD
Patch: Benjamin Gould

This closes #691


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/cc193c1b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/cc193c1b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/cc193c1b

Branch: refs/heads/master
Commit: cc193c1becb78b75fbbb178a6e2e0e5aaa0f5b24
Parents: a6b1203
Author: BCG <[email protected]>
Authored: Thu Nov 12 21:02:51 2015 -0500
Committer: Jens Geyer <[email protected]>
Committed: Sat Nov 14 14:28:09 2015 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_xsd_generator.cc |  5 +++++
 compiler/cpp/src/parse/t_program.h           | 12 ++++++++++++
 compiler/cpp/src/thrifty.yy                  |  6 +++++-
 test/ThriftTest.thrift                       |  1 +
 4 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/generate/t_xsd_generator.cc
----------------------------------------------------------------------
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 @@ void t_xsd_generator::generate_service(t_service* 
tservice) {
   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\"";

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/parse/t_program.h
----------------------------------------------------------------------
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 @@ public:
   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 @@ private:
   // 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_;
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/thrifty.yy
----------------------------------------------------------------------
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 @@ Header:
     {
       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
     {

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/test/ThriftTest.thrift
----------------------------------------------------------------------
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index f545227..414f9a5 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -36,6 +36,7 @@ namespace php ThriftTest
 namespace delphi Thrift.Test
 namespace cocoa ThriftTest
 namespace lua ThriftTest
+namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
 
 // Presence of namespaces and sub-namespaces for which there is
 // no generator should compile with warnings only

Reply via email to