Skip to content

Commit

Permalink
[highsource#453] : fix simplify plugin to respect globalBindings isSe…
Browse files Browse the repository at this point in the history
…t / indexed properties
  • Loading branch information
laurentschoelens authored and Matt Pavlovich committed Feb 5, 2024
1 parent fef9c54 commit 50adc5c
Show file tree
Hide file tree
Showing 25 changed files with 556 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
final CElementInfo elementInfo) {
final CElementPropertyInfo elementPropertyInfo;
final String propertyName = createPropertyName(model, property, element);
final CElementPropertyInfo originalPropertyInfo = elementInfo
.getProperty();
final CElementPropertyInfo originalPropertyInfo = elementInfo.getProperty();

elementPropertyInfo = new CElementPropertyInfo(propertyName,
property.isCollection() ? CollectionMode.REPEATED_ELEMENT
: CollectionMode.NOT_REPEATED, ID.NONE, null,
Expand All @@ -288,6 +288,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
if (adapter != null) {
elementPropertyInfo.setAdapter(adapter);
}
if (property.realization != null) {
elementPropertyInfo.realization = property.realization;
}

elementPropertyInfo.getTypes().add(
new CTypeRef(elementInfo.getContentType(), element
Expand All @@ -306,6 +309,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
: CollectionMode.NOT_REPEATED, ID.NONE, null,
element.getSchemaComponent(), element.getCustomizations(),
element.getLocator(), false);
if (property.realization != null) {
elementPropertyInfo.realization = property.realization;
}
elementPropertyInfo.getTypes().add(
new CTypeRef(classInfo, element.getElementName(), classInfo
.getTypeName(), false, null));
Expand Down Expand Up @@ -337,6 +343,9 @@ private CReferencePropertyInfo createReferencePropertyInfo(
element.getCustomizations(), element.getLocator(),
property.isDummy(), property.isContent(),
property.isMixedExtendedCust());
if (property.realization != null) {
referencePropertyInfo.realization = property.realization;
}
referencePropertyInfo.getElements().add(element);
return referencePropertyInfo;
}
Expand All @@ -349,6 +358,9 @@ private CReferencePropertyInfo createContentReferencePropertyInfo(
true, property.getSchemaComponent(),
property.getCustomizations(), property.getLocator(), false,
true, property.isMixedExtendedCust());
if (property.realization != null) {
referencePropertyInfo.realization = property.realization;
}
return referencePropertyInfo;
}

Expand All @@ -367,6 +379,9 @@ private CElementPropertyInfo createElementPropertyInfo(final Model model,
if (adapter != null) {
elementPropertyInfo.setAdapter(adapter);
}
if (property.realization != null) {
elementPropertyInfo.realization = property.realization;
}
elementPropertyInfo.getTypes().add(typeRef);
return elementPropertyInfo;
}
Expand Down
1 change: 1 addition & 0 deletions jaxb-plugins-parent/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<module>simple-hashCode-equals-01</module>
<module>simplify-01</module>
<module>simplify-02</module>
<module>simplify-03</module>
<module>superclass</module>
<module>wildcard</module>
<module>zj</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="3.0">

<jaxb:globalBindings choiceContentProperty="true">
<jaxb:globalBindings choiceContentProperty="true" generateIsSetMethod="true">
<xjc:javaType name="java.util.Date" xmlType="xs:dateTime"
adapter="org.jvnet.jaxb.plugin.simplify.tests01.DateAdapter" />
</jaxb:globalBindings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns="urn:test" targetNamespace="urn:test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:version="3.0"
jaxb:extensionBindingPrefixes="simplify">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ public class Gh18Test {
public void compiles() {
final Gh18 item = new Gh18();
item.getA();
item.isSetA();
item.getChildren();
item.isSetChildren();
item.getFeet();
item.isSetFeet();
item.getFoos();
item.isSetFoos();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public void compiles()
{
final Gh1 item = new Gh1();
item.getAs();
item.isSetAs();
item.unsetAs();
item.getBs();
item.isSetBs();
item.unsetBs();
item.getMixedContent();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public void compiles() {
final Gh2 item = new Gh2();
@SuppressWarnings("unused")
final String a = item.getA();
item.isSetA();
@SuppressWarnings("unused")
final Date b = item.getB();
item.isSetB();
@SuppressWarnings("unused")
final Duration c = item.getC();
item.isSetC();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public void setUp() throws Exception {
public void compiles() {
final SimplifyReferencesPropertyAsElementPropertyType item = new SimplifyReferencesPropertyAsElementPropertyType();
item.getBases();
item.isSetBases();
item.getBaseElements();

item.isSetBaseElements();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public void setUp() throws Exception {
public void compiles() {
final SimplifyReferencesPropertyAsReferencePropertyType item = new SimplifyReferencesPropertyAsReferencePropertyType();
item.getBases();
item.isSetBases();
item.getBaseElements();
item.isSetBaseElements();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public void setUp() throws Exception {
public void compiles() {
final SimplifyElementsPropertyAsElementPropertyType item = new SimplifyElementsPropertyAsElementPropertyType();
item.getInts();
item.isSetInts();
item.getStrings();
item.isSetStrings();
}

public void testElementsPropertyAsElementPropertyType() throws Exception {
Expand Down
51 changes: 51 additions & 0 deletions jaxb-plugins-parent/tests/simplify-03/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-tests</artifactId>
<version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>jaxb-plugins-test-simplify-03</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Plugins :: Test [simplify-03]</name>
<description>Test for issue #453 (related to issue in jaxb2-basics #115)</description>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
<arg>-Xsimplify-usePluralForm=true</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jvnet.jaxb.plugin.simplify.tests03;

import jakarta.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

@SuppressWarnings("serial")
public class BaseElementRef extends JAXBElement<BaseType> {

protected final static QName NAME = new QName("urn:test", "baseElement");

@SuppressWarnings({ "unchecked", "rawtypes" })
public BaseElementRef(BaseType value) {
super(NAME, ((Class) BaseType.class), null, value);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public BaseElementRef() {
super(NAME, ((Class) BaseType.class), null, null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jvnet.jaxb.plugin.simplify.tests03;

import java.util.Date;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

/**
*
*
* @author
*/
public class DateAdapter extends XmlAdapter<String, Date> {

private static final DateTimeFormatter PARSER = ISODateTimeFormat
.dateTimeParser().withZoneUTC();
private static final DateTimeFormatter FORMATTER = ISODateTimeFormat
.dateTime().withZoneUTC();

@Override
public String marshal(Date value) throws Exception {
return new DateTime(value).toString(FORMATTER);
}

@Override
public Date unmarshal(String text) throws Exception {
return PARSER.parseDateTime(text).toDate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="urn:jaxb.jvnet.org:plugin:simplify"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="3.0">

<jaxb:globalBindings choiceContentProperty="true" collectionType="indexed">
<xjc:javaType name="java.util.Date" xmlType="xs:dateTime"
adapter="org.jvnet.jaxb.plugin.simplify.tests03.DateAdapter" />
</jaxb:globalBindings>

<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.jvnet.jaxb.plugin.simplify.tests03" />
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[@name='gh2']">
<simplify:property name="bOrC">
<simplify:as-element-property />
</simplify:property>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='gh18']">
<simplify:property name="childOrFootOrFoo">
<simplify:as-element-property />
</simplify:property>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>

0 comments on commit 50adc5c

Please sign in to comment.