Skip to content

Commit

Permalink
Fixed JavaDocs so that they are compatible with Java8. Added samples …
Browse files Browse the repository at this point in the history
…for JAXB issues. Minor improvements.
  • Loading branch information
dmak committed Jun 7, 2018
1 parent a5305aa commit e82439c
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 83 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ If you provide the code in any way (patch, pull request, post, comment, …) you

### Bug reports

This very open source project is maintained and improved during my free time. That is why I have no ability to test the functionality will all different combinations of Java, JAXB, JAXB plugins and Maven plugins. I leave this to community. Also newly created bug report should mention Java version and have a simple project attached (or one can clone the repository and alter one of the [`samples`](samples/)) that demonstrates the problem.
This very open source project is maintained and improved during my free time. That is why I have no ability to test the functionality will all different combinations of Java, JAXB, JAXB plugins and Maven plugins. I leave this to community. Hence please in newly created bug report:
- mention Java version
- attach a simple project (or one can clone the repository and alter one of the [`samples`](samples/)) that demonstrates the problem

#### Code style

Expand Down Expand Up @@ -642,12 +644,12 @@ The plugin flow consists of the following parts:

There are many pitfalls in JAXB Code Model API which are forcing the developer to use dirty tricks (like accessing private fields) in order to implement the manipulation of code model. Among others:

* [JAXB-784](http://java.net/jira/browse/JAXB-784) is about NPE in `JAnnotationUse#getAnnotationMembers()` method.
* [JAXB-884](https://java.net/jira/browse/JAXB-884) is about ClassCastException in `JAnnotationArrayMember#annotations()` method.
* [JAXB-878](https://java.net/jira/browse/JAXB-878) and [JAXB-879](https://java.net/jira/browse/JAXB-879) describe the lack of public getters for class fields.
* [JAXB-957](https://java.net/jira/browse/JAXB-957) mentions what need to be added to make it possible for the inner class to be moved to another class or package.
* [JAXB-883](http://java.net/jira/browse/JAXB-883) does not allow to learn if "simpleMode" setting is enabled, which in its turn controls plural form for collection property names. There are however some more difficulties to overcome.
* [JAXB-1107](https://java.net/jira/browse/JAXB-1107) – marshalling of text nodes for mixed-mode contents
* [JAXB-784](https://github.com/javaee/jaxb-v2/issues/784) is about NPE in `JAnnotationUse#getAnnotationMembers()` method.
* [JAXB-884](https://github.com/javaee/jaxb-v2/issues/884) is about ClassCastException in `JAnnotationArrayMember#annotations()` method.
* [JAXB-878](https://github.com/javaee/jaxb-v2/issues/878) and [JAXB-879](https://github.com/javaee/jaxb-v2/issues/879) describe the lack of public getters for class fields.
* [JAXB-957](https://github.com/javaee/jaxb-v2/issues/957) mentions what need to be added to make it possible for the inner class to be moved to another class or package.
* [JAXB-883](https://github.com/javaee/jaxb-v2/issues/883) does not allow to learn if "simpleMode" setting is enabled, which in its turn controls plural form for collection property names. There are however some more difficulties to overcome.
* [JAXB-1107](https://github.com/javaee/jaxb-v2/issues/1107) – marshalling of text nodes for mixed-mode contents

## Authors

Expand Down
34 changes: 34 additions & 0 deletions playground/JAXB-1108/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>com.github.jaxb-xew-plugin.sample</groupId>
<artifactId>jaxb-1108</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<verbose>true</verbose>
<schemaDirectory>xsd</schemaDirectory>
<episode>false</episode>
<noFileHeader>true</noFileHeader>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions playground/JAXB-1108/runme.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mvn -X clean install
rem D:\jaxb-ri\bin\xjc.bat -extension xsd\test.xsd
32 changes: 32 additions & 0 deletions playground/JAXB-1108/xsd/test.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="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"
targetNamespace="http://foo.bar"
xmlns="http://foo.bar"
jaxb:version="2.1"
jaxb:extensionBindingPrefixes="xjc"
elementFormDefault="qualified">

<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>

<xsd:element name="comment" type="markup" />

<xsd:complexType name="markup" mixed="true">
<xsd:annotation>
<xsd:appinfo>
<jaxb:class name="Style" />
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element ref="comment" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
34 changes: 34 additions & 0 deletions playground/JAXB-element/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>com.github.jaxb-xew-plugin.sample</groupId>
<artifactId>jaxb-element</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<verbose>true</verbose>
<schemaDirectory>xsd</schemaDirectory>
<episode>false</episode>
<noFileHeader>true</noFileHeader>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
29 changes: 29 additions & 0 deletions playground/JAXB-element/xsd/test.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo.bar"
xmlns="http://foo.bar"
elementFormDefault="qualified">

<xsd:element name="table" type="table-type" />
<xsd:complexType name="table-type">
<xsd:sequence>
<xsd:element ref="table-row" maxOccurs="unbounded" />
<xsd:element ref="caption" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="caption" type="xsd:string" />
<xsd:element name="table-row" type="table-row-type" />
<xsd:complexType name="table-row-type">
<xsd:sequence>
<xsd:element name="table-column" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="table-column" type="table-column-type" />
<xsd:complexType name="table-column-type">
<xsd:sequence>
<xsd:element name="paragraph" type="xsd:string" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="preferred-width" type="xsd:string" />
</xsd:complexType>
</xsd:schema>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-tools</artifactId>
<version>0.6.5</version>
<version>0.12.0</version>
</dependency>

<dependency>
Expand Down
15 changes: 6 additions & 9 deletions samples/jaxb2-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
<version>2.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand All @@ -31,20 +31,17 @@
<configuration>
<outputDirectory>${project.build.testSourceDirectory}</outputDirectory>
<sources>
<source>xsd/BudgetaryCommitment.xsd</source>
<source>xsd/ContractorReference.xsd</source>
<source>xsd/different-namespaces.xsd</source>
<source>xsd/different-namespaces-entries.xsd</source>
<source>xsd</source>
</sources>
<!-- Is not implemented, see https://github.com/mojohaus/jaxb2-maven-plugin/issues/58 -->
<!-- schemaSourceExcludeFilters>
<!-- Since jaxb2-maven-plugin v2.4, see https://github.com/mojohaus/jaxb2-maven-plugin/issues/58 -->
<xjcSourceExcludeFilters>
<filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
<patterns>
<pattern>\.xml</pattern>
</patterns>
</filter>
</schemaSourceExcludeFilters-->
<clearOutputDir>false</clearOutputDir>
</xjcSourceExcludeFilters>
<clearOutputDir>true</clearOutputDir>
<noGeneratedHeaderComments>true</noGeneratedHeaderComments>

<verbose>true</verbose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
<!--
This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0
See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
Any modifications to this file will be lost upon recompilation of the source schema.
Generated on: 2016.12.13 at 08:00:41 PM CET
Generated on: 2018.06.07 at 04:50:09 PM CEST
-->
<bindings scd="x-schema::tns" xmlns:tns="budgetary/reference">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public BudgetaryCommitmentType createBudgetaryCommitmentType() {
}

/**
* Create an instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >}}
* Create an instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >}
*
* @param value
* Java instance representing xml element's value.
* @return
* the new instance of {@link JAXBElement }{@code <}{@link BudgetaryCommitmentType }{@code >}
*/
@XmlElementDecl(namespace = "budgetary/commitment", name = "BudgetaryCommitment")
public JAXBElement<BudgetaryCommitmentType> createBudgetaryCommitment(BudgetaryCommitmentType value) {
Expand Down
5 changes: 1 addition & 4 deletions samples/maven-jaxb2-plugin-basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
<properties>
<xsd.folder>xsd</xsd.folder>
<xjb.folder>xsd</xjb.folder>

<jaxb2-basics.version>0.11.1</jaxb2-basics.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<!-- See https://github.com/dmak/jaxb-xew-plugin/issues/50#issuecomment-248238663 about how to solve the issue with maven-jaxb2-plugin >= v0.12.1 + jaxb-xew-plugin <= v1.7 -->
<version>0.13.1</version>
<version>${maven-jaxb2-plugin.version}</version>
<executions>
<execution>
<id>generate</id>
Expand Down
3 changes: 1 addition & 2 deletions samples/maven-jaxb2-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<!-- See https://github.com/dmak/jaxb-xew-plugin/issues/50#issuecomment-248238663 about how to solve the issue with maven-jaxb2-plugin >= v0.12.1 + jaxb-xew-plugin <= v1.7 -->
<version>0.13.1</version>
<version>${maven-jaxb2-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down
24 changes: 12 additions & 12 deletions samples/maven-jaxb2-plugin/src/main/java/generated/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.jvnet.jaxb2_commons.lang.Equals;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy;
import org.jvnet.jaxb2_commons.lang.HashCode;
import org.jvnet.jaxb2_commons.lang.HashCodeStrategy;
import org.jvnet.jaxb2_commons.lang.Equals2;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy2;
import org.jvnet.jaxb2_commons.lang.HashCode2;
import org.jvnet.jaxb2_commons.lang.HashCodeStrategy2;
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
Expand Down Expand Up @@ -43,7 +43,7 @@
"items"
})
@XmlRootElement(name = "order")
public class Order implements Equals, HashCode
public class Order implements Equals2, HashCode2
{

@XmlElementWrapper(required = true)
Expand All @@ -61,8 +61,8 @@ public void setItems(List<String> items) {
this.items = items;
}

public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy strategy) {
if (!(object instanceof Order)) {
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
if ((object == null)||(this.getClass()!= object.getClass())) {
return false;
}
if (this == object) {
Expand All @@ -74,30 +74,30 @@ public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Obje
lhsItems = ((this.items!= null)?this.getItems():null);
List<String> rhsItems;
rhsItems = ((that.items!= null)?that.getItems():null);
if (!strategy.equals(LocatorUtils.property(thisLocator, "items", lhsItems), LocatorUtils.property(thatLocator, "items", rhsItems), lhsItems, rhsItems)) {
if (!strategy.equals(LocatorUtils.property(thisLocator, "items", lhsItems), LocatorUtils.property(thatLocator, "items", rhsItems), lhsItems, rhsItems, (this.items!= null), (that.items!= null))) {
return false;
}
}
return true;
}

public boolean equals(Object object) {
final EqualsStrategy strategy = JAXBEqualsStrategy.INSTANCE;
final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE2;
return equals(null, null, object, strategy);
}

public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) {
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) {
int currentHashCode = 1;
{
List<String> theItems;
theItems = ((this.items!= null)?this.getItems():null);
currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "items", theItems), currentHashCode, theItems);
currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "items", theItems), currentHashCode, theItems, (this.items!= null));
}
return currentHashCode;
}

public int hashCode() {
final HashCodeStrategy strategy = JAXBHashCodeStrategy.INSTANCE;
final HashCodeStrategy2 strategy = JAXBHashCodeStrategy.INSTANCE2;
return this.hashCode(null, strategy);
}

Expand Down
8 changes: 5 additions & 3 deletions samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<packaging>pom</packaging>

<properties>
<jaxb-xew-plugin.version>1.9</jaxb-xew-plugin.version>
<!-- Versions [0.9.2-0.9.5] of this plugin result the following problem:
<jaxb-xew-plugin.version>1.10-SNAPSHOT</jaxb-xew-plugin.version>
<!-- Versions [0.9.2-0.12.0] of jaxb2-plugin + jaxb-xew-plugin <= v1.9 result the following problem:
Exception in thread "main" java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider org.jvnet.jaxb2_commons.plugin.fixjaxb1058.FixJAXB1058Plugin could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:224)
at java.util.ServiceLoader.access$100(ServiceLoader.java:181)
Expand All @@ -27,7 +27,9 @@
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
... 29 more
-->
<jaxb2-basics.version>0.9.1</jaxb2-basics.version>
<jaxb2-basics.version>0.12.0</jaxb2-basics.version>
<!-- See https://github.com/dmak/jaxb-xew-plugin/issues/50#issuecomment-248238663 about how to solve the issue with maven-jaxb2-plugin >= v0.12.1 + jaxb-xew-plugin <= v1.7 -->
<maven-jaxb2-plugin.version>0.14.0</maven-jaxb2-plugin.version>
</properties>

<modules>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/sun/tools/xjc/addon/xew/Candidate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.sun.codemodel.JAnnotationUse;
Expand Down Expand Up @@ -162,8 +161,8 @@ public String getFieldTargetNamespace() {
}

/**
* The only parametrisation class of the field (collection type). In case of basic parametrisation like {@link List
* <String>} this property is {@code null}.
* The only parametrisation class of the field (collection type). In case of basic parametrisation like
* {@code List<String>} this property is {@code null}.
*/
public JDefinedClass getFieldParametrisationClass() {
return fieldParametrisationClass;
Expand Down
Loading

0 comments on commit e82439c

Please sign in to comment.