Skip to content

Commit 5e4641b

Browse files
committed
Issues #40, #50.
1 parent 254abb2 commit 5e4641b

File tree

14 files changed

+417
-0
lines changed

14 files changed

+417
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.hisrc.jsonix.xml.xsom;
2+
3+
import static com.sun.tools.xjc.model.Multiplicity.ONE;
4+
import static com.sun.tools.xjc.model.Multiplicity.ZERO;
5+
6+
import java.math.BigInteger;
7+
8+
import com.sun.tools.xjc.model.Multiplicity;
9+
import com.sun.xml.xsom.XSElementDecl;
10+
import com.sun.xml.xsom.XSModelGroup;
11+
import com.sun.xml.xsom.XSModelGroupDecl;
12+
import com.sun.xml.xsom.XSParticle;
13+
import com.sun.xml.xsom.XSWildcard;
14+
import com.sun.xml.xsom.visitor.XSTermFunction;
15+
16+
public class MultiplicityCounterNG implements XSTermFunction<Multiplicity> {
17+
18+
public static final XSTermFunction<Multiplicity> INSTANCE = new MultiplicityCounterNG();
19+
20+
private MultiplicityCounterNG() {
21+
}
22+
23+
public Multiplicity particle(XSParticle p) {
24+
Multiplicity m = p.getTerm().apply(this);
25+
26+
BigInteger max;
27+
if (m.max == null
28+
|| (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p
29+
.getMaxOccurs())))
30+
max = null;
31+
else
32+
max = p.getMaxOccurs();
33+
34+
return Multiplicity.multiply(m,
35+
Multiplicity.create(p.getMinOccurs(), max));
36+
}
37+
38+
public Multiplicity wildcard(XSWildcard wc) {
39+
return ONE;
40+
}
41+
42+
public Multiplicity modelGroupDecl(XSModelGroupDecl decl) {
43+
return modelGroup(decl.getModelGroup());
44+
}
45+
46+
public Multiplicity modelGroup(XSModelGroup group) {
47+
boolean isChoice = group.getCompositor() == XSModelGroup.CHOICE;
48+
49+
Multiplicity r = null;
50+
51+
for (XSParticle p : group.getChildren()) {
52+
Multiplicity m = particle(p);
53+
54+
if (r == null) {
55+
r = m;
56+
continue;
57+
}
58+
if (isChoice) {
59+
r = Multiplicity.choice(r, m);
60+
} else {
61+
r = Multiplicity.group(r, m);
62+
}
63+
}
64+
return r;
65+
}
66+
67+
public Multiplicity elementDecl(XSElementDecl decl) {
68+
return ONE;
69+
}
70+
71+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.hisrc.jsonix.xml.xsom;
2+
3+
import java.math.BigInteger;
4+
5+
import org.hisrc.xml.xsom.DefaultFunctionImpl;
6+
7+
import com.sun.tools.xjc.model.Multiplicity;
8+
import com.sun.xml.xsom.XSAttributeUse;
9+
import com.sun.xml.xsom.XSParticle;
10+
import com.sun.xml.xsom.visitor.XSTermFunction;
11+
12+
public class ParticleMultiplicityCounter extends
13+
DefaultFunctionImpl<Multiplicity> {
14+
15+
public static final ParticleMultiplicityCounter INSTANCE = new ParticleMultiplicityCounter();
16+
17+
private final XSTermFunction<Multiplicity> counter = MultiplicityCounterNG.INSTANCE;
18+
19+
protected ParticleMultiplicityCounter() {
20+
super();
21+
}
22+
23+
@Override
24+
public Multiplicity particle(XSParticle p) {
25+
26+
Multiplicity m = p.getTerm().apply(this.counter);
27+
28+
BigInteger max;
29+
if (m.max == null
30+
|| (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p
31+
.getMaxOccurs())))
32+
max = null;
33+
else
34+
max = p.getMaxOccurs();
35+
36+
return Multiplicity.multiply(m,
37+
Multiplicity.create(p.getMinOccurs(), max));
38+
}
39+
40+
@Override
41+
public Multiplicity attributeUse(XSAttributeUse use) {
42+
return use.isRequired() ? Multiplicity.ONE : Multiplicity.OPTIONAL;
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Jsonix is a JavaScript library which allows you to convert between XML
3+
* and JavaScript object structures.
4+
*
5+
* Copyright (c) 2010 - 2014, Alexey Valikov, Highsource.org
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without modification,
9+
* are permitted provided that the following conditions are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* * Redistributions in binary form must reproduce the above copyright notice, this
15+
* list of conditions and the following disclaimer in the documentation and/or
16+
* other materials provided with the distribution.
17+
*
18+
* * Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
package org.hisrc.jsonix.xjc.plugin.tests.jsonschemas;
35+
36+
import org.hisrc.xml.bind.model.util.MModelInfoLoader;
37+
import org.junit.Test;
38+
39+
public class JsonixPluginJsonSchemasChoiceTest {
40+
41+
@Test
42+
public void elements01() throws Exception {
43+
MModelInfoLoader.INSTANCE.loadModel("jsonschema/choice/elements01.xsd");
44+
}
45+
46+
@Test
47+
public void elements02() throws Exception {
48+
MModelInfoLoader.INSTANCE.loadModel("jsonschema/choice/elements02.xsd");
49+
}
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:element name="choice" type="choiceType" />
16+
<xs:complexType name="choiceType">
17+
<xs:choice>
18+
<xs:element name="a" type="xs:string" minOccurs="0" />
19+
<xs:element name="b" type="xs:integer" minOccurs="0" />
20+
</xs:choice>
21+
</xs:complexType>
22+
23+
</xs:schema>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:element name="choice" type="choiceType" />
16+
<xs:complexType name="choiceType">
17+
<xs:choice maxOccurs="50">
18+
<xs:element name="a" type="xs:string" minOccurs="0" />
19+
<xs:element name="b" type="xs:integer" minOccurs="0" />
20+
</xs:choice>
21+
</xs:complexType>
22+
23+
</xs:schema>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:complexType name="aa01">
16+
<xs:anyAttribute />
17+
</xs:complexType>
18+
</xs:schema>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:complexType name="ae01">
16+
<xs:sequence>
17+
<xs:any minOccurs="2" maxOccurs="20" />
18+
</xs:sequence>
19+
</xs:complexType>
20+
</xs:schema>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:complexType name="a01">
16+
<xs:attribute name="a" type="xs:string" use="required" />
17+
</xs:complexType>
18+
</xs:schema>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:complexType name="e01">
16+
<xs:sequence>
17+
<xs:element name="a" type="xs:string" minOccurs="10"
18+
maxOccurs="20" />
19+
</xs:sequence>
20+
</xs:complexType>
21+
</xs:schema>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
5+
6+
<xs:annotation>
7+
<xs:appinfo>
8+
<jaxb:globalBindings typesafeEnumBase="xs:token" />
9+
<jaxb:schemaBindings>
10+
<jaxb:package name="test" />
11+
</jaxb:schemaBindings>
12+
</xs:appinfo>
13+
</xs:annotation>
14+
15+
<xs:complexType name="er01">
16+
<xs:sequence>
17+
<xs:element name="a" type="xs:int" minOccurs="0"
18+
maxOccurs="1" nillable="true" />
19+
</xs:sequence>
20+
</xs:complexType>
21+
22+
</xs:schema>

0 commit comments

Comments
 (0)