Skip to content
This repository

namespace binding conflict #84

Closed
eed3si9n opened this Issue September 15, 2011 · 2 comments

2 participants

eugene yokota John Stanford
eugene yokota
Owner

steps

  1. compile two schemas defining namespace binding to different URI using the same prefix.

problem

the generates default scope using both.

expectation

do something to avoid the naming conflict.

John Stanford

I think I found the place where this is all happening in GenProtocol.scala, so I wrote a makeDistinct method that should detect duplicate prefixes and append a number. Here's the diff:

jstanford-mbp:xsd jstanford$  git diff GenProtocol.scala 
diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/GenProtocol.scala b/cli/src/main/scala/scalaxb/compiler/xsd/GenProtocol
index eafdd10..6f5a75b 100644
--- a/cli/src/main/scala/scalaxb/compiler/xsd/GenProtocol.scala
+++ b/cli/src/main/scala/scalaxb/compiler/xsd/GenProtocol.scala
@@ -40,9 +40,27 @@ abstract class GenProtocol(val context: XsdContext) extends ContextProcessor {
       case _ => Nil
     }

+    def makeDistinct(list: List[(Option[String], String)], counter: Int): List[(Option[String], String)] = {
+      def sortOption(a: (Option[String], String), b: (Option[String], String)) = {
+        (a._1, b._1) match {
+          case (None, _) => true
+          case (_, None) => false
+          case (a, b) => a.get < b.get
+        }
+      }
+
+      val sortedList = list.sortWith((a, b) => sortOption(a, b))
+      sortedList match {
+        case x :: l if x._1.isEmpty => { x :: makeDistinct(l, counter) }
+        case x :: l if !l.isEmpty && x._1.get == l.head._1.get => { (x._1.map(_ + counter.toString), x._2) :: makeDistinct(
+        case x :: l => { x :: makeDistinct(l, counter) }
+        case _ => Nil
+      }
+    }
+
     // including XS_URL into the default scope prints out the xsi:type, which is necessary for anyType round trip.
-    val scopes = (makeScopes(scopeSchemas.toList) :::
-      List((Some(XSI_PREFIX) -> XSI_URL), (Some(XS_PREFIX) -> XS_URL))).distinct
+    val scopes = makeDistinct((makeScopes(scopeSchemas.toList) :::
+      List((Some(XSI_PREFIX) -> XSI_URL), (Some(XS_PREFIX) -> XS_URL))).distinct, 0)
     val packageString = config.protocolPackageName map { "package " + _ + newline } getOrElse{""}
     val packageValueString = config.protocolPackageName map { x => x } getOrElse {""}

The root project compiles, but for some reason, I was not able to get the sbt-scalaxb project to compile. Hopefully this helps though. Also will send you the file in an email since the comment block is not handling the diff output very well...

eugene yokota
Owner

Nice! Can't express how happy I am. For sbt-scalaxb, it's bound to 2.8.1, so try + publish-local.

eugene yokota eed3si9n closed this in 7f58a93 September 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.