Skip to content

Commit c66218c

Browse files
committed
Issue #43, #44.
1 parent e5c8212 commit c66218c

File tree

4 files changed

+313
-5
lines changed

4 files changed

+313
-5
lines changed

compiler/src/main/java/org/hisrc/jsonix/compilation/mapping/CreateTypeInfoDeclarationVisitor.java

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ final class CreateTypeInfoDeclarationVisitor<T, C extends T> implements
113113
XSD_TYPE_MAPPING.put(XmlSchemaConstants.QNAME, "QName");
114114
// XSD_TYPE_MAPPING.put(XmlSchemaConstants.NOTATION, "Notation");
115115
XSD_TYPE_MAPPING.put(XmlSchemaConstants.DURATION, "Duration");
116-
XSD_TYPE_MAPPING.put(XmlSchemaConstants.DURATION, "String");
117116
XSD_TYPE_MAPPING.put(XmlSchemaConstants.DATETIME, "DateTime");
118117
XSD_TYPE_MAPPING.put(XmlSchemaConstants.TIME, "Time");
119118
XSD_TYPE_MAPPING.put(XmlSchemaConstants.DATE, "Date");

compiler/src/test/java/org/hisrc/jsonix/xjc/plugin/tests/JsonixPluginTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void compilesOWS_V_1_1_0() throws Exception {
7474
com.sun.codemodel.CodeWriter cw = options.createCodeWriter();
7575
model.codeModel.build(cw);
7676
}
77-
77+
7878
@Test
7979
public void compilesWFS_V_2_0() throws Exception {
8080

@@ -84,8 +84,7 @@ public void compilesWFS_V_2_0() throws Exception {
8484
URL binding = getClass().getResource("/ogc/wfs-v_2_0.xjb");
8585
final String[] arguments = new String[] { "-xmlschema",
8686
schema.toExternalForm(), "-b", binding.toExternalForm(), "-d",
87-
"target/generated-sources/wfs-v_2_0", "-extension",
88-
"-Xjsonix"
87+
"target/generated-sources/wfs-v_2_0", "-extension", "-Xjsonix"
8988

9089
};
9190

@@ -98,7 +97,6 @@ public void compilesWFS_V_2_0() throws Exception {
9897
model.codeModel.build(cw);
9998
}
10099

101-
102100
@Test
103101
public void compilesContext_V_1_1_0() throws Exception {
104102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.basic;
35+
36+
import java.io.File;
37+
38+
import org.junit.Before;
39+
import org.junit.Test;
40+
41+
import com.sun.codemodel.JCodeModel;
42+
import com.sun.tools.xjc.ConsoleErrorReporter;
43+
import com.sun.tools.xjc.ModelLoader;
44+
import com.sun.tools.xjc.Options;
45+
import com.sun.tools.xjc.model.Model;
46+
47+
public class JsonixPluginZeroTest {
48+
49+
@Before
50+
public void setUp() {
51+
System.setProperty("javax.xml.accessExternalSchema", "all");
52+
}
53+
54+
@Test
55+
public void compilesBasicZero() throws Exception {
56+
57+
new File("target/generated-sources/basic/zero").mkdirs();
58+
59+
final String[] arguments = new String[] {
60+
"-xmlschema",
61+
getClass().getResource("/basic/zero/schema.xsd")
62+
.toExternalForm(), "-d",
63+
"target/generated-sources/basic/zero", "-extension", "-Xjsonix"
64+
65+
};
66+
67+
Options options = new Options();
68+
options.parseArguments(arguments);
69+
ConsoleErrorReporter receiver = new ConsoleErrorReporter();
70+
Model model = ModelLoader.load(options, new JCodeModel(), receiver);
71+
model.generateCode(options, receiver);
72+
com.sun.codemodel.CodeWriter cw = options.createCodeWriter();
73+
model.codeModel.build(cw);
74+
}
75+
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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"
4+
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
5+
jaxb:extensionBindingPrefixes="xjc"
6+
jaxb:version="2.0">
7+
8+
<xs:annotation>
9+
<xs:appinfo>
10+
<jaxb:globalBindings typesafeEnumBase="xs:token"/>
11+
<jaxb:schemaBindings>
12+
<jaxb:package name="org.hisrc.jsonix.tests.zero"/>
13+
</jaxb:schemaBindings>
14+
</xs:appinfo>
15+
</xs:annotation>
16+
17+
<xs:element name="simpleTypes" type="simpleTypesType"/>
18+
<xs:complexType name="simpleTypesType">
19+
<xs:sequence>
20+
<xs:element name="base64Binary" type="xs:base64Binary" minOccurs="0"/>
21+
<xs:element name="hexBinary" type="xs:hexBinary" minOccurs="0"/>
22+
<xs:element name="duration" type="xs:duration" minOccurs="0"/>
23+
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0"/>
24+
<xs:element name="date" type="xs:date" minOccurs="0"/>
25+
<xs:element name="time" type="xs:time" minOccurs="0"/>
26+
<xs:element name="gYearMonth" type="xs:gYearMonth" minOccurs="0"/>
27+
<xs:element name="gYear" type="xs:gYear" minOccurs="0"/>
28+
<xs:element name="gMonthDay" type="xs:gMonthDay" minOccurs="0"/>
29+
<xs:element name="gDay" type="xs:gDay" minOccurs="0"/>
30+
<xs:element name="gMonth" type="xs:gMonth" minOccurs="0"/>
31+
<xs:element name="float" type="xs:float" minOccurs="0"/>
32+
<xs:element name="double" type="xs:double" minOccurs="0"/>
33+
<xs:element name="decimal" type="xs:decimal" minOccurs="0"/>
34+
<xs:element name="integer" type="xs:integer" minOccurs="0"/>
35+
<xs:element name="long" type="xs:long" minOccurs="0"/>
36+
<xs:element name="int" type="xs:int" minOccurs="0"/>
37+
<xs:element name="short" type="xs:short" minOccurs="0"/>
38+
<xs:element name="byte" type="xs:byte" minOccurs="0"/>
39+
<xs:element name="unsignedLong" type="xs:unsignedLong" minOccurs="0"/>
40+
<xs:element name="unsignedInt" type="xs:unsignedInt" minOccurs="0"/>
41+
<xs:element name="unsignedShort" type="xs:unsignedShort" minOccurs="0"/>
42+
<xs:element name="unsignedByte" type="xs:unsignedByte" minOccurs="0"/>
43+
<xs:element name="nonNegativeInteger" type="xs:nonNegativeInteger" minOccurs="0"/>
44+
<xs:element name="nonPositiveInteger" type="xs:nonPositiveInteger" minOccurs="0"/>
45+
<xs:element name="positiveInteger" type="xs:positiveInteger"
46+
minOccurs="0"/>
47+
<xs:element name="negativeInteger" type="xs:negativeInteger"
48+
minOccurs="0"/>
49+
<xs:element name="boolean" type="xs:boolean" minOccurs="0"/>
50+
<xs:element name="anyURI" type="xs:anyURI" minOccurs="0"/>
51+
<xs:element name="QName" type="xs:QName" minOccurs="0"/>
52+
<!--
53+
<xs:element name="NOTATION" type="xs:NOTATION" minOccurs="0"/>
54+
-->
55+
56+
<xs:element name="string" type="xs:string" minOccurs="0"/>
57+
<xs:element name="normalizedString" type="xs:normalizedString"
58+
minOccurs="0"/>
59+
<xs:element name="token" type="xs:token" minOccurs="0"/>
60+
<xs:element name="language" type="xs:language" minOccurs="0"/>
61+
<xs:element name="Name" type="xs:Name" minOccurs="0"/>
62+
<xs:element name="NCName" type="xs:NCName" minOccurs="0"/>
63+
<xs:element name="ID" type="xs:ID" minOccurs="0"/>
64+
<xs:element name="IDREF" type="xs:IDREF" minOccurs="0"/>
65+
<xs:element name="IDREFS" type="xs:IDREFS"/>
66+
<xs:element name="ENTITY" type="xs:ENTITY" minOccurs="0"/>
67+
<xs:element name="ENTITIES" type="xs:ENTITIES" minOccurs="0"/>
68+
<xs:element name="NMTOKEN" type="xs:NMTOKEN" minOccurs="0"/>
69+
<xs:element name="NMTOKENS" type="xs:NMTOKENS" minOccurs="0"/>
70+
</xs:sequence>
71+
</xs:complexType>
72+
73+
<!-- Element with a simple type -->
74+
<xs:element name="string" type="xs:string"/>
75+
76+
<!-- Complex type with simple content -->
77+
<xs:element name="value" type="valueType"/>
78+
<xs:complexType name="valueType">
79+
<xs:simpleContent>
80+
<xs:extension base="xs:string">
81+
<xs:attribute name="attribute" type="xs:string" use="optional"/>
82+
</xs:extension>
83+
</xs:simpleContent>
84+
</xs:complexType>
85+
86+
<!-- Any attribute -->
87+
<xs:element name="anyAttribute" type="anyAttributeType"/>
88+
<xs:complexType name="anyAttributeType">
89+
<xs:simpleContent>
90+
<xs:extension base="xs:string">
91+
<xs:anyAttribute/>
92+
</xs:extension>
93+
</xs:simpleContent>
94+
</xs:complexType>
95+
96+
<!-- attribute -->
97+
<xs:element name="attribute" type="attributeType"/>
98+
<xs:complexType name="attributeType">
99+
<xs:simpleContent>
100+
<xs:extension base="xs:string">
101+
<xs:attribute name="string" type="xs:string" use="optional"/>
102+
<xs:attribute name="integers" use="optional">
103+
<xs:simpleType>
104+
<xs:list itemType="xs:integer"/>
105+
</xs:simpleType>
106+
</xs:attribute>
107+
</xs:extension>
108+
</xs:simpleContent>
109+
</xs:complexType>
110+
111+
<!-- anyElement -->
112+
<xs:element name="anyElementLax" type="anyElementLaxType"/>
113+
<xs:complexType name="anyElementLaxType">
114+
<xs:sequence>
115+
<xs:any processContents="lax"/>
116+
</xs:sequence>
117+
</xs:complexType>
118+
<xs:element name="anyElementStrict" type="anyElementStrictType"/>
119+
<xs:complexType name="anyElementStrictType">
120+
<xs:sequence>
121+
<xs:any processContents="strict"/>
122+
</xs:sequence>
123+
</xs:complexType>
124+
<xs:element name="anyElementSkip" type="anyElementSkipType"/>
125+
<xs:complexType name="anyElementSkipType">
126+
<xs:sequence>
127+
<xs:any processContents="skip"/>
128+
</xs:sequence>
129+
</xs:complexType>
130+
131+
<xs:simpleType name="strings">
132+
<xs:list itemType="xs:string"/>
133+
</xs:simpleType>
134+
135+
<!-- element -->
136+
<xs:element name="element" type="elementType"/>
137+
<xs:complexType name="elementType">
138+
<xs:sequence>
139+
<xs:element name="element" type="xs:string" minOccurs="0"/>
140+
<xs:element name="elements" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
141+
<xs:element name="item" type="strings" minOccurs="0"/>
142+
<xs:element name="items" type="strings" minOccurs="0" maxOccurs="unbounded"/>
143+
</xs:sequence>
144+
</xs:complexType>
145+
146+
<!-- elements -->
147+
<xs:element name="elements" type="elementsType"/>
148+
<xs:complexType name="elementsType">
149+
<xs:sequence>
150+
<xs:choice maxOccurs="unbounded">
151+
<xs:element name="string" type="xs:string"/>
152+
<xs:element name="integer" type="xs:integer"/>
153+
</xs:choice>
154+
</xs:sequence>
155+
</xs:complexType>
156+
157+
<!-- Element reference -->
158+
<xs:element name="elementRef" type="elementRefType"/>
159+
<xs:complexType name="elementRefType">
160+
<xs:sequence>
161+
<xs:element ref="base" maxOccurs="unbounded"/>
162+
</xs:sequence>
163+
</xs:complexType>
164+
165+
<!-- element refs -->
166+
<xs:element name="elementRefs" type="elementRefsType"/>
167+
<xs:complexType name="elementRefsType">
168+
<xs:sequence>
169+
<xs:choice maxOccurs="unbounded">
170+
<xs:element name="alpha" type="valueType"/>
171+
<xs:element name="beta" type="valueType"/>
172+
</xs:choice>
173+
</xs:sequence>
174+
</xs:complexType>
175+
176+
<!-- Mixed -->
177+
<xs:element name="elementRefMixed" type="elementRefMixedType"/>
178+
<xs:complexType name="elementRefMixedType" mixed="true">
179+
<xs:sequence>
180+
<xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
181+
</xs:sequence>
182+
</xs:complexType>
183+
184+
<!-- Derivation by extension -->
185+
<xs:element name="base" type="baseType"/>
186+
<xs:complexType name="baseType">
187+
<xs:sequence>
188+
<xs:element name="alpha" type="xs:string" minOccurs="0"/>
189+
<xs:element name="beta" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
190+
</xs:sequence>
191+
</xs:complexType>
192+
193+
<xs:element name="extended" type="extendedType" substitutionGroup="base"/>
194+
<xs:complexType name="extendedType">
195+
<xs:complexContent>
196+
<xs:extension base="baseType">
197+
<xs:sequence>
198+
<xs:element name="gamma" type="xs:anyURI" minOccurs="0"/>
199+
<xs:element name="delta" type="xs:dateTime" minOccurs="0" maxOccurs="unbounded"/>
200+
</xs:sequence>
201+
</xs:extension>
202+
</xs:complexContent>
203+
</xs:complexType>
204+
205+
<xs:element name="extendedExtended" type="extendedExtendedType" substitutionGroup="base"/>
206+
<xs:complexType name="extendedExtendedType">
207+
<xs:complexContent>
208+
<xs:extension base="extendedType">
209+
<xs:sequence>
210+
<xs:element name="epsilon" type="xs:double" minOccurs="0"/>
211+
<xs:element name="zeta" type="xs:decimal" minOccurs="0" maxOccurs="unbounded"/>
212+
</xs:sequence>
213+
</xs:extension>
214+
</xs:complexContent>
215+
</xs:complexType>
216+
217+
<xs:element name="enum" type="enumType"/>
218+
<xs:simpleType name="enumType">
219+
<xs:restriction base="xs:token">
220+
<xs:enumeration value="Male"/>
221+
<xs:enumeration value="Female"/>
222+
</xs:restriction>
223+
</xs:simpleType>
224+
225+
<xs:complexType name="abstractBaseType" abstract="true"/>
226+
227+
<xs:complexType name="extendedMixedType">
228+
<xs:complexContent mixed="true">
229+
<xs:extension base="abstractBaseType"/>
230+
</xs:complexContent>
231+
</xs:complexType>
232+
233+
<xs:element name="abstractElement" abstract="true"/>
234+
235+
</xs:schema>

0 commit comments

Comments
 (0)