Skip to content

Commit

Permalink
fixes handling of cross-namespace extension. fixes #135
Browse files Browse the repository at this point in the history
when a complex type A is extended from another complex type B
from another namespace it was incorrectly expecting
the derived elements to be in the target namespace of A.
  • Loading branch information
eed3si9n committed Jan 31, 2012
1 parent aa46cdb commit 2463dc4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/src/main/scala/scalaxb/compiler/xsd/Lookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ trait Lookup extends ContextProcessor {
quote(namespace)

def elementNamespace(global: Boolean, namespace: Option[String], qualified: Boolean): Option[String] =
if (global) namespace
else if (qualified) schema.targetNamespace
if (global || qualified) namespace

else None

def elementNamespaceString(global: Boolean, namespace: Option[String], qualified: Boolean): String =
Expand Down
26 changes: 26 additions & 0 deletions integration/src/test/resources/GeneralUsage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object GeneralUsage {
testSubstitutionGroup
testExtraElement
testTypeAttribute
testCrossNamespaceExtension
true
}

Expand Down Expand Up @@ -576,4 +577,29 @@ object GeneralUsage {
}
println(document)
}

def testCrossNamespaceExtension {
println("testCrossNamespaceExtension")

import gimport.IntlAddress

val subject = <imp:shipTo xmlns:gen="http://www.example.com/general"
xmlns:imp="http://www.example.com/general_import"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<gen:street>1537 Paper Street</gen:street>
<gen:city>Wilmington</gen:city>
<gen:state>DE</gen:state>
<imp:postalCode>19886</imp:postalCode>
<imp:country>USA</imp:country>
</imp:shipTo>
val shipTo = scalaxb.fromXML[IntlAddress](subject)

def check(obj: IntlAddress) = obj match {
case IntlAddress(_, _, _, _, _) =>
case _ => error("match failed: " + obj.toString)
}
val document = scalaxb.toXML[IntlAddress](shipTo, Some("http://www.example.com/general_import"), Some("shipTo"), subject.scope)
println(document)
check(fromXML[IntlAddress](document))
}
}
11 changes: 11 additions & 0 deletions integration/src/test/resources/general_import.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@
<xs:import namespace="http://www.example.com/general"
schemaLocation="http://www.example.com/general"/>
<xs:element name="SubGroupMember3" type="xs:string" substitutionGroup="gen:subgroupHead"/>

<xs:complexType name="IntlAddress">
<xs:complexContent>
<xs:extension base="gen:Address">
<xs:sequence>
<xs:element name="postalCode" type="xs:positiveInteger"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
5 changes: 5 additions & 0 deletions notes/0.6.8.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## bug fixes and minor enhancements
- Fixes handling of cross-namespace extension. [#135][#135] reported by [@psnively][@psnively]

[#135]: https://github.com/eed3si9n/scalaxb/issues/135
[@psnively]: https://github.com/psnively

0 comments on commit 2463dc4

Please sign in to comment.