xsd_namespace keyword for thrift

Summary: So you can Spaceify the Shiznits

Reviewed By: fett


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664959 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index d07be91..757009f 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -110,10 +110,15 @@
   string f_xsd_name = string(T_XSD_DIR)+"/"+tservice->get_name()+".xsd";
   f_xsd_.open(f_xsd_name.c_str());
 
+  string ns = program_->get_xsd_namespace();
+  if (ns.size() > 0) {
+    ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\"";
+  }
+
   // Print the XSD header
   f_xsd_ <<
     "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl <<
-    "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" << endl <<
+    "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" << ns << ">" << endl <<
     endl <<
     "<!-- Yo yo yo, this XSD woz be generated by Thrift. -->" << endl <<
     endl;
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 9a86621..7f7af44 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -130,6 +130,13 @@
     return java_package_;
   }
 
+  void set_xsd_namespace(std::string xsd_namespace) {
+    xsd_namespace_ = xsd_namespace;
+  }
+
+  const std::string& get_xsd_namespace() const {
+    return xsd_namespace_;
+  }
 
  private:
 
@@ -168,6 +175,9 @@
   // Java package
   std::string java_package_;
 
+  // XSD namespace
+  std::string xsd_namespace_;
+
 };
 
 #endif
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 855443b..d54a2ad 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -61,6 +61,7 @@
 "php_namespace" { return tok_php_namespace; }
 "xsd_all"       { return tok_xsd_all;       }
 "xsd_optional"  { return tok_xsd_optional;  }
+"xsd_namespace" { return tok_xsd_namespace; }
 "include"       { return tok_include;       }
 
 "void"          { return tok_void;          }
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index d8f3435..a90d64b 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -68,6 +68,7 @@
 %token tok_java_package
 %token tok_xsd_all
 %token tok_xsd_optional
+%token tok_xsd_namespace
 
 /**
  * Base datatype keywords
@@ -218,6 +219,13 @@
         g_program->set_java_package($2);
       }
     }
+| tok_xsd_namespace tok_literal
+    {
+      pdebug("Header -> tok_xsd_namespace tok_literal");
+      if (g_parse_mode == PROGRAM) {
+        g_program->set_xsd_namespace($2);
+      }
+    }
 
 Include:
   tok_include tok_literal