New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace binding conflict #84

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

Comments

Projects
None yet
2 participants
@eed3si9n
Owner

eed3si9n commented Sep 15, 2011

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.

@jxstanford

This comment has been minimized.

Show comment
Hide comment
@jxstanford

jxstanford Sep 15, 2011

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...

jxstanford commented Sep 15, 2011

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...

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 15, 2011

Owner

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

Owner

eed3si9n commented Sep 15, 2011

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

@eed3si9n eed3si9n closed this in 7f58a93 Sep 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment