-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
254abb2
commit 5e4641b
Showing
14 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
compiler/src/main/java/org/hisrc/jsonix/xml/xsom/MultiplicityCounterNG.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,71 @@ | ||
package org.hisrc.jsonix.xml.xsom; | ||
|
||
import static com.sun.tools.xjc.model.Multiplicity.ONE; | ||
import static com.sun.tools.xjc.model.Multiplicity.ZERO; | ||
|
||
import java.math.BigInteger; | ||
|
||
import com.sun.tools.xjc.model.Multiplicity; | ||
import com.sun.xml.xsom.XSElementDecl; | ||
import com.sun.xml.xsom.XSModelGroup; | ||
import com.sun.xml.xsom.XSModelGroupDecl; | ||
import com.sun.xml.xsom.XSParticle; | ||
import com.sun.xml.xsom.XSWildcard; | ||
import com.sun.xml.xsom.visitor.XSTermFunction; | ||
|
||
public class MultiplicityCounterNG implements XSTermFunction<Multiplicity> { | ||
|
||
public static final XSTermFunction<Multiplicity> INSTANCE = new MultiplicityCounterNG(); | ||
|
||
private MultiplicityCounterNG() { | ||
} | ||
|
||
public Multiplicity particle(XSParticle p) { | ||
Multiplicity m = p.getTerm().apply(this); | ||
|
||
BigInteger max; | ||
if (m.max == null | ||
|| (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p | ||
.getMaxOccurs()))) | ||
max = null; | ||
else | ||
max = p.getMaxOccurs(); | ||
|
||
return Multiplicity.multiply(m, | ||
Multiplicity.create(p.getMinOccurs(), max)); | ||
} | ||
|
||
public Multiplicity wildcard(XSWildcard wc) { | ||
return ONE; | ||
} | ||
|
||
public Multiplicity modelGroupDecl(XSModelGroupDecl decl) { | ||
return modelGroup(decl.getModelGroup()); | ||
} | ||
|
||
public Multiplicity modelGroup(XSModelGroup group) { | ||
boolean isChoice = group.getCompositor() == XSModelGroup.CHOICE; | ||
|
||
Multiplicity r = null; | ||
|
||
for (XSParticle p : group.getChildren()) { | ||
Multiplicity m = particle(p); | ||
|
||
if (r == null) { | ||
r = m; | ||
continue; | ||
} | ||
if (isChoice) { | ||
r = Multiplicity.choice(r, m); | ||
} else { | ||
r = Multiplicity.group(r, m); | ||
} | ||
} | ||
return r; | ||
} | ||
|
||
public Multiplicity elementDecl(XSElementDecl decl) { | ||
return ONE; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
compiler/src/main/java/org/hisrc/jsonix/xml/xsom/ParticleMultiplicityCounter.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,45 @@ | ||
package org.hisrc.jsonix.xml.xsom; | ||
|
||
import java.math.BigInteger; | ||
|
||
import org.hisrc.xml.xsom.DefaultFunctionImpl; | ||
|
||
import com.sun.tools.xjc.model.Multiplicity; | ||
import com.sun.xml.xsom.XSAttributeUse; | ||
import com.sun.xml.xsom.XSParticle; | ||
import com.sun.xml.xsom.visitor.XSTermFunction; | ||
|
||
public class ParticleMultiplicityCounter extends | ||
DefaultFunctionImpl<Multiplicity> { | ||
|
||
public static final ParticleMultiplicityCounter INSTANCE = new ParticleMultiplicityCounter(); | ||
|
||
private final XSTermFunction<Multiplicity> counter = MultiplicityCounterNG.INSTANCE; | ||
|
||
protected ParticleMultiplicityCounter() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public Multiplicity particle(XSParticle p) { | ||
|
||
Multiplicity m = p.getTerm().apply(this.counter); | ||
|
||
BigInteger max; | ||
if (m.max == null | ||
|| (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p | ||
.getMaxOccurs()))) | ||
max = null; | ||
else | ||
max = p.getMaxOccurs(); | ||
|
||
return Multiplicity.multiply(m, | ||
Multiplicity.create(p.getMinOccurs(), max)); | ||
} | ||
|
||
@Override | ||
public Multiplicity attributeUse(XSAttributeUse use) { | ||
return use.isRequired() ? Multiplicity.ONE : Multiplicity.OPTIONAL; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...java/org/hisrc/jsonix/xjc/plugin/tests/jsonschemas/JsonixPluginJsonSchemasChoiceTest.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,50 @@ | ||
/** | ||
* Jsonix is a JavaScript library which allows you to convert between XML | ||
* and JavaScript object structures. | ||
* | ||
* Copyright (c) 2010 - 2014, Alexey Valikov, Highsource.org | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* * Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package org.hisrc.jsonix.xjc.plugin.tests.jsonschemas; | ||
|
||
import org.hisrc.xml.bind.model.util.MModelInfoLoader; | ||
import org.junit.Test; | ||
|
||
public class JsonixPluginJsonSchemasChoiceTest { | ||
|
||
@Test | ||
public void elements01() throws Exception { | ||
MModelInfoLoader.INSTANCE.loadModel("jsonschema/choice/elements01.xsd"); | ||
} | ||
|
||
@Test | ||
public void elements02() throws Exception { | ||
MModelInfoLoader.INSTANCE.loadModel("jsonschema/choice/elements02.xsd"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
compiler/src/test/resources/jsonschema/choice/elements01.xsd
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,23 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:element name="choice" type="choiceType" /> | ||
<xs:complexType name="choiceType"> | ||
<xs:choice> | ||
<xs:element name="a" type="xs:string" minOccurs="0" /> | ||
<xs:element name="b" type="xs:integer" minOccurs="0" /> | ||
</xs:choice> | ||
</xs:complexType> | ||
|
||
</xs:schema> |
23 changes: 23 additions & 0 deletions
23
compiler/src/test/resources/jsonschema/choice/elements02.xsd
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,23 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:element name="choice" type="choiceType" /> | ||
<xs:complexType name="choiceType"> | ||
<xs:choice maxOccurs="50"> | ||
<xs:element name="a" type="xs:string" minOccurs="0" /> | ||
<xs:element name="b" type="xs:integer" minOccurs="0" /> | ||
</xs:choice> | ||
</xs:complexType> | ||
|
||
</xs:schema> |
18 changes: 18 additions & 0 deletions
18
compiler/src/test/resources/jsonschema/minmaxoccurs/anyAttribute01.xsd
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,18 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="aa01"> | ||
<xs:anyAttribute /> | ||
</xs:complexType> | ||
</xs:schema> |
20 changes: 20 additions & 0 deletions
20
compiler/src/test/resources/jsonschema/minmaxoccurs/anyElement01.xsd
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,20 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="ae01"> | ||
<xs:sequence> | ||
<xs:any minOccurs="2" maxOccurs="20" /> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |
18 changes: 18 additions & 0 deletions
18
compiler/src/test/resources/jsonschema/minmaxoccurs/attribute01.xsd
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,18 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="a01"> | ||
<xs:attribute name="a" type="xs:string" use="required" /> | ||
</xs:complexType> | ||
</xs:schema> |
21 changes: 21 additions & 0 deletions
21
compiler/src/test/resources/jsonschema/minmaxoccurs/element01.xsd
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 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="e01"> | ||
<xs:sequence> | ||
<xs:element name="a" type="xs:string" minOccurs="10" | ||
maxOccurs="20" /> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |
22 changes: 22 additions & 0 deletions
22
compiler/src/test/resources/jsonschema/minmaxoccurs/elementRef01.xsd
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,22 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="er01"> | ||
<xs:sequence> | ||
<xs:element name="a" type="xs:int" minOccurs="0" | ||
maxOccurs="1" nillable="true" /> | ||
</xs:sequence> | ||
</xs:complexType> | ||
|
||
</xs:schema> |
26 changes: 26 additions & 0 deletions
26
compiler/src/test/resources/jsonschema/minmaxoccurs/elementRefs01.xsd
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,26 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="ers01"> | ||
<xs:sequence> | ||
<xs:choice minOccurs="3" maxOccurs="5"> | ||
<xs:element name="a" type="xs:string" minOccurs="10" | ||
maxOccurs="20" /> | ||
<xs:element name="b" type="xs:string" minOccurs="30" | ||
maxOccurs="40" /> | ||
</xs:choice> | ||
</xs:sequence> | ||
</xs:complexType> | ||
|
||
</xs:schema> |
33 changes: 33 additions & 0 deletions
33
compiler/src/test/resources/jsonschema/minmaxoccurs/elements01.xsd
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,33 @@ | ||
<?xml version="1.0"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> | ||
|
||
<xs:annotation> | ||
<xs:appinfo> | ||
<jaxb:globalBindings typesafeEnumBase="xs:token" /> | ||
<jaxb:schemaBindings> | ||
<jaxb:package name="test" /> | ||
</jaxb:schemaBindings> | ||
</xs:appinfo> | ||
</xs:annotation> | ||
|
||
<xs:complexType name="es01"> | ||
<xs:sequence> | ||
<xs:choice minOccurs="5" maxOccurs="10"> | ||
<xs:element name="a" type="xs:string" minOccurs="10" | ||
maxOccurs="20" /> | ||
<xs:element name="b" type="xs:int" minOccurs="30" | ||
maxOccurs="40" /> | ||
</xs:choice> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="es02"> | ||
<xs:choice minOccurs="5" maxOccurs="10"> | ||
<xs:element name="a" type="xs:string" minOccurs="10" | ||
maxOccurs="20" /> | ||
<xs:element name="b" type="xs:int" minOccurs="30" | ||
maxOccurs="40" /> | ||
</xs:choice> | ||
</xs:complexType> | ||
</xs:schema> |
Oops, something went wrong.