Skip to content

Commit d2aebf3

Browse files
[#453] : fix simplify plugin to respect globalBindings isSet / indexed properties
1 parent 4c85fe7 commit d2aebf3

File tree

25 files changed

+556
-6
lines changed

25 files changed

+556
-6
lines changed

jaxb-plugins-parent/jaxb-plugins/src/main/java/org/jvnet/jaxb/plugin/simplify/SimplifyPlugin.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
276276
final CElementInfo elementInfo) {
277277
final CElementPropertyInfo elementPropertyInfo;
278278
final String propertyName = createPropertyName(model, property, element);
279-
final CElementPropertyInfo originalPropertyInfo = elementInfo
280-
.getProperty();
279+
final CElementPropertyInfo originalPropertyInfo = elementInfo.getProperty();
280+
281281
elementPropertyInfo = new CElementPropertyInfo(propertyName,
282282
property.isCollection() ? CollectionMode.REPEATED_ELEMENT
283283
: CollectionMode.NOT_REPEATED, ID.NONE, null,
@@ -288,6 +288,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
288288
if (adapter != null) {
289289
elementPropertyInfo.setAdapter(adapter);
290290
}
291+
if (property.realization != null) {
292+
elementPropertyInfo.realization = property.realization;
293+
}
291294

292295
elementPropertyInfo.getTypes().add(
293296
new CTypeRef(elementInfo.getContentType(), element
@@ -306,6 +309,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
306309
: CollectionMode.NOT_REPEATED, ID.NONE, null,
307310
element.getSchemaComponent(), element.getCustomizations(),
308311
element.getLocator(), false);
312+
if (property.realization != null) {
313+
elementPropertyInfo.realization = property.realization;
314+
}
309315
elementPropertyInfo.getTypes().add(
310316
new CTypeRef(classInfo, element.getElementName(), classInfo
311317
.getTypeName(), false, null));
@@ -337,6 +343,9 @@ private CReferencePropertyInfo createReferencePropertyInfo(
337343
element.getCustomizations(), element.getLocator(),
338344
property.isDummy(), property.isContent(),
339345
property.isMixedExtendedCust());
346+
if (property.realization != null) {
347+
referencePropertyInfo.realization = property.realization;
348+
}
340349
referencePropertyInfo.getElements().add(element);
341350
return referencePropertyInfo;
342351
}
@@ -349,6 +358,9 @@ private CReferencePropertyInfo createContentReferencePropertyInfo(
349358
true, property.getSchemaComponent(),
350359
property.getCustomizations(), property.getLocator(), false,
351360
true, property.isMixedExtendedCust());
361+
if (property.realization != null) {
362+
referencePropertyInfo.realization = property.realization;
363+
}
352364
return referencePropertyInfo;
353365
}
354366

@@ -367,6 +379,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
367379
if (adapter != null) {
368380
elementPropertyInfo.setAdapter(adapter);
369381
}
382+
if (property.realization != null) {
383+
elementPropertyInfo.realization = property.realization;
384+
}
370385
elementPropertyInfo.getTypes().add(typeRef);
371386
return elementPropertyInfo;
372387
}

jaxb-plugins-parent/tests/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<module>simple-hashCode-equals-01</module>
3030
<module>simplify-01</module>
3131
<module>simplify-02</module>
32+
<module>simplify-03</module>
3233
<module>superclass</module>
3334
<module>wildcard</module>
3435
<module>zj</module>

jaxb-plugins-parent/tests/simplify-01/src/main/resources/binding.xjb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
2-
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
2+
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
33
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
44
jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="3.0">
55

6-
<jaxb:globalBindings choiceContentProperty="true">
6+
<jaxb:globalBindings choiceContentProperty="true" generateIsSetMethod="true">
77
<xjc:javaType name="java.util.Date" xmlType="xs:dateTime"
88
adapter="org.jvnet.jaxb.plugin.simplify.tests01.DateAdapter" />
99
</jaxb:globalBindings>

jaxb-plugins-parent/tests/simplify-01/src/main/resources/schema.xsd

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns="urn:test" targetNamespace="urn:test"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
7-
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
7+
xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
88
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:version="3.0"
99
jaxb:extensionBindingPrefixes="simplify">
1010

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh18Test.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ public class Gh18Test {
88
public void compiles() {
99
final Gh18 item = new Gh18();
1010
item.getA();
11+
item.isSetA();
1112
item.getChildren();
13+
item.isSetChildren();
1214
item.getFeet();
15+
item.isSetFeet();
1316
item.getFoos();
17+
item.isSetFoos();
1418
}
1519
}

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh1Test.java

+4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public void compiles()
1717
{
1818
final Gh1 item = new Gh1();
1919
item.getAs();
20+
item.isSetAs();
21+
item.unsetAs();
2022
item.getBs();
23+
item.isSetBs();
24+
item.unsetBs();
2125
item.getMixedContent();
2226

2327
}

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh2Test.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ public void compiles() {
1313
final Gh2 item = new Gh2();
1414
@SuppressWarnings("unused")
1515
final String a = item.getA();
16+
item.isSetA();
1617
@SuppressWarnings("unused")
1718
final Date b = item.getB();
19+
item.isSetB();
1820
@SuppressWarnings("unused")
1921
final Duration c = item.getC();
22+
item.isSetC();
2023
}
2124
}

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh4Test.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public void setUp() throws Exception {
2020
public void compiles() {
2121
final SimplifyReferencesPropertyAsElementPropertyType item = new SimplifyReferencesPropertyAsElementPropertyType();
2222
item.getBases();
23+
item.isSetBases();
2324
item.getBaseElements();
24-
25+
item.isSetBaseElements();
2526
}
2627

2728
@Test

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh5Test.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public void setUp() throws Exception {
2020
public void compiles() {
2121
final SimplifyReferencesPropertyAsReferencePropertyType item = new SimplifyReferencesPropertyAsReferencePropertyType();
2222
item.getBases();
23+
item.isSetBases();
2324
item.getBaseElements();
25+
item.isSetBaseElements();
2426
}
2527

2628
@Test

jaxb-plugins-parent/tests/simplify-01/src/test/java/org/jvnet/jaxb/plugin/simplify/tests01/Gh6Test.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public void setUp() throws Exception {
2020
public void compiles() {
2121
final SimplifyElementsPropertyAsElementPropertyType item = new SimplifyElementsPropertyAsElementPropertyType();
2222
item.getInts();
23+
item.isSetInts();
2324
item.getStrings();
25+
item.isSetStrings();
2426
}
2527

2628
public void testElementsPropertyAsElementPropertyType() throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.jvnet.jaxb</groupId>
7+
<artifactId>jaxb-plugins-tests</artifactId>
8+
<version>3.0.2-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>jaxb-plugins-test-simplify-03</artifactId>
11+
<packaging>jar</packaging>
12+
<name>JAXB Tools :: JAXB Plugins :: Test [simplify-03]</name>
13+
<description>Test for issue #453 (related to issue in jaxb2-basics #115)</description>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.jvnet.jaxb</groupId>
17+
<artifactId>jaxb-maven-plugin-testing</artifactId>
18+
<scope>test</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.jvnet.jaxb</groupId>
22+
<artifactId>jaxb-plugins</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>joda-time</groupId>
26+
<artifactId>joda-time</artifactId>
27+
</dependency>
28+
</dependencies>
29+
<build>
30+
<defaultGoal>test</defaultGoal>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.jvnet.jaxb</groupId>
34+
<artifactId>jaxb-maven-plugin</artifactId>
35+
<configuration>
36+
<extension>true</extension>
37+
<args>
38+
<arg>-Xsimplify</arg>
39+
<arg>-Xsimplify-usePluralForm=true</arg>
40+
</args>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.jvnet.jaxb</groupId>
44+
<artifactId>jaxb-plugins</artifactId>
45+
</plugin>
46+
</plugins>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.jvnet.jaxb.plugin.simplify.tests03;
2+
3+
import jakarta.xml.bind.JAXBElement;
4+
import javax.xml.namespace.QName;
5+
6+
@SuppressWarnings("serial")
7+
public class BaseElementRef extends JAXBElement<BaseType> {
8+
9+
protected final static QName NAME = new QName("urn:test", "baseElement");
10+
11+
@SuppressWarnings({ "unchecked", "rawtypes" })
12+
public BaseElementRef(BaseType value) {
13+
super(NAME, ((Class) BaseType.class), null, value);
14+
}
15+
16+
@SuppressWarnings({ "unchecked", "rawtypes" })
17+
public BaseElementRef() {
18+
super(NAME, ((Class) BaseType.class), null, null);
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jvnet.jaxb.plugin.simplify.tests03;
2+
3+
import java.util.Date;
4+
5+
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
6+
7+
import org.joda.time.DateTime;
8+
import org.joda.time.format.DateTimeFormatter;
9+
import org.joda.time.format.ISODateTimeFormat;
10+
11+
/**
12+
*
13+
*
14+
* @author
15+
*/
16+
public class DateAdapter extends XmlAdapter<String, Date> {
17+
18+
private static final DateTimeFormatter PARSER = ISODateTimeFormat
19+
.dateTimeParser().withZoneUTC();
20+
private static final DateTimeFormatter FORMATTER = ISODateTimeFormat
21+
.dateTime().withZoneUTC();
22+
23+
@Override
24+
public String marshal(Date value) throws Exception {
25+
return new DateTime(value).toString(FORMATTER);
26+
}
27+
28+
@Override
29+
public Date unmarshal(String text) throws Exception {
30+
return PARSER.parseDateTime(text).toDate();
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
2+
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
3+
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+
jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="3.0">
5+
6+
<jaxb:globalBindings choiceContentProperty="true" collectionType="indexed">
7+
<xjc:javaType name="java.util.Date" xmlType="xs:dateTime"
8+
adapter="org.jvnet.jaxb.plugin.simplify.tests03.DateAdapter" />
9+
</jaxb:globalBindings>
10+
11+
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
12+
<jaxb:schemaBindings>
13+
<jaxb:package name="org.jvnet.jaxb.plugin.simplify.tests03" />
14+
</jaxb:schemaBindings>
15+
<jaxb:bindings node="xs:complexType[@name='gh2']">
16+
<simplify:property name="bOrC">
17+
<simplify:as-element-property />
18+
</simplify:property>
19+
</jaxb:bindings>
20+
<jaxb:bindings node="xs:complexType[@name='gh18']">
21+
<simplify:property name="childOrFootOrFoo">
22+
<simplify:as-element-property />
23+
</simplify:property>
24+
</jaxb:bindings>
25+
</jaxb:bindings>
26+
</jaxb:bindings>
27+

0 commit comments

Comments
 (0)