-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#457] add multiple namespaces prefix bindings
- Loading branch information
1 parent
4e7a716
commit 4b10ef6
Showing
7 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<xsd:schema | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="c" | ||
xmlns:a="a" | ||
xmlns:c="c" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:import namespace="a" schemaLocation="a.xsd"/> | ||
|
||
<xsd:element name="c" type="c:CType"/> | ||
|
||
<xsd:complexType name="CType"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:AType"> | ||
<xsd:sequence> | ||
<xsd:element name="c" type="c:C1Type"/> | ||
<xsd:element name="ca" type="a:AType" minOccurs="0" maxOccurs="unbounded"/> | ||
</xsd:sequence> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="C1Type"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:A1Type"> | ||
<xsd:sequence> | ||
<xsd:element name="c1" type="xsd:string"/> | ||
</xsd:sequence> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="issueHJIII24Mammal"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:issueHJIII24Animal"> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="issueHJIII24Dog"> | ||
<xsd:complexContent> | ||
<xsd:extension base="c:issueHJIII24Mammal"> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
21 changes: 21 additions & 0 deletions
21
basics/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/ATest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import javax.xml.bind.annotation.XmlNs; | ||
import javax.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb2_commons.test.namespace.a.AType; | ||
|
||
public class ATest { | ||
|
||
@Test | ||
public void testA() { | ||
AType a = new AType(); | ||
XmlSchema schema = a.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertNotNull(namespaces); | ||
Assert.assertEquals(1, namespaces.length); | ||
Assert.assertEquals("a", namespaces[0].namespaceURI()); | ||
Assert.assertEquals("a", namespaces[0].prefix()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
basics/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/BTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import javax.xml.bind.annotation.XmlNs; | ||
import javax.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb2_commons.test.namespace.b.BType; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BTest { | ||
|
||
@Test | ||
public void testB() { | ||
BType b = new BType(); | ||
XmlSchema schema = b.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertNotNull(namespaces); | ||
Assert.assertEquals(2, namespaces.length); | ||
XmlNs aNs = Arrays.stream(namespaces).filter(ns -> "aprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(aNs); | ||
Assert.assertEquals("a", aNs.namespaceURI()); | ||
Assert.assertEquals("aprefix", aNs.prefix()); | ||
XmlNs bNs = Arrays.stream(namespaces).filter(ns -> "b".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(bNs); | ||
Assert.assertEquals("b", bNs.namespaceURI()); | ||
Assert.assertEquals("b", bNs.prefix()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
basics/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/CTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBElement; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.annotation.XmlNs; | ||
import javax.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb2_commons.test.namespace.a.A1Type; | ||
import org.jvnet.jaxb.test.namespace.c.C1Type; | ||
import org.jvnet.jaxb.test.namespace.c.CType; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.io.StringWriter; | ||
import java.util.Arrays; | ||
|
||
public class CTest { | ||
|
||
@Test | ||
public void testC() throws JAXBException { | ||
CType c = new CType(); | ||
XmlSchema schema = c.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertEquals(3, namespaces.length); | ||
XmlNs aNs = Arrays.stream(namespaces).filter(ns -> "aprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(aNs); | ||
Assert.assertEquals("a", aNs.namespaceURI()); | ||
Assert.assertEquals("aprefix", aNs.prefix()); | ||
XmlNs bNs = Arrays.stream(namespaces).filter(ns -> "bprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(bNs); | ||
Assert.assertEquals("b", bNs.namespaceURI()); | ||
Assert.assertEquals("bprefix", bNs.prefix()); | ||
XmlNs cNs = Arrays.stream(namespaces).filter(ns -> "creal".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(cNs); | ||
Assert.assertEquals("c", cNs.namespaceURI()); | ||
Assert.assertEquals("creal", cNs.prefix()); | ||
|
||
c.setA(new A1Type()); | ||
c.setC(new C1Type()); | ||
|
||
JAXBElement<CType> jaxbElement | ||
= new JAXBElement<>( new QName("c", "cPart"), CType.class, c); | ||
JAXBContext context = JAXBContext.newInstance(CType.class.getPackage().getName()); | ||
StringWriter writer = new StringWriter(); | ||
context.createMarshaller().marshal(jaxbElement, writer); | ||
String marshalled = writer.toString(); | ||
|
||
Assert.assertNotNull(marshalled); | ||
String expectedA = "xmlns:aprefix=\"a\""; | ||
Assert.assertTrue(marshalled.contains(expectedA)); | ||
String expectedB = "xmlns:bprefix=\"b\""; | ||
Assert.assertTrue(marshalled.contains(expectedB)); | ||
String expectedC = "xmlns:creal=\"c\""; | ||
Assert.assertTrue(marshalled.contains(expectedC)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/tests/namespace/RunNamespacePlugin.java → ...b/tests/namespace/RunNamespacePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters