Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Please refer to the [wiki](https://github.com/highsource/jaxb-tools/wiki/JAXB2-B

JAXB2 Basics can only be used with JAXB/XJC 2.3.x. JAXB/XJC versions 2.2.x and earlier are no longer supported.

If you're using `jaxb2-basics-runtime` dependency with previous generated code, please be sure to use 0.11 as minimal version or consider upgrading to 2.x.
The new published artifact `org.jvnet.jaxb:jaxb2-basics-runtime` is backward compatible with `org.jvnet.jaxb2_commons:jaxb2-basics-runtime` from version 0.11 and above.

## Using JAXB2 Basics

* [Using JAXB2 Basics Plugins](https://github.com/highsource/jaxb-tools/wiki/Using-JAXB2-Basics-Plugins)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public Object[] copy(ObjectLocator locator, Object[] value, boolean valueSet) {
}

public static final DefaultCopyStrategy INSTANCE2 = new DefaultCopyStrategy();
public static final CopyStrategy INSTANCE = INSTANCE2;
public static final DefaultCopyStrategy INSTANCE = INSTANCE2;

public static DefaultCopyStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public boolean equals(ObjectLocator leftLocator,
}

public static DefaultEqualsStrategy INSTANCE2 = new DefaultEqualsStrategy();
public static EqualsStrategy INSTANCE = INSTANCE2;
public static DefaultEqualsStrategy INSTANCE = INSTANCE2;

public static DefaultEqualsStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public int hashCode(ObjectLocator locator, int hashCode, Object[] value, boolean
}

public static final DefaultHashCodeStrategy INSTANCE2 = new DefaultHashCodeStrategy();
public static final HashCodeStrategy INSTANCE = INSTANCE2;
public static final DefaultHashCodeStrategy INSTANCE = INSTANCE2;

public static DefaultHashCodeStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public Object merge(ObjectLocator leftLocator, ObjectLocator rightLocator,
}

public static final DefaultMergeStrategy INSTANCE2 = new DefaultMergeStrategy();
public static final MergeStrategy INSTANCE = INSTANCE2;
public static final DefaultMergeStrategy INSTANCE = INSTANCE2;

public static DefaultMergeStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ public StringBuilder appendField(ObjectLocator parentLocator,
}

public static final DefaultToStringStrategy INSTANCE2 = new DefaultToStringStrategy();
public static final ToStringStrategy INSTANCE = INSTANCE2;
public static final DefaultToStringStrategy INSTANCE = INSTANCE2;

public static DefaultToStringStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Object copyInternal(ObjectLocator locator, @SuppressWarnings("rawtypes

public static final JAXBCopyStrategy INSTANCE2 = new JAXBCopyStrategy();
@SuppressWarnings("deprecation")
public static final CopyStrategy INSTANCE = INSTANCE2;
public static final JAXBCopyStrategy INSTANCE = INSTANCE2;

public static JAXBCopyStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected boolean equalsInternal(ObjectLocator leftLocator,

public static JAXBEqualsStrategy INSTANCE2 = new JAXBEqualsStrategy();
@SuppressWarnings("deprecation")
public static EqualsStrategy INSTANCE = INSTANCE2;
public static JAXBEqualsStrategy INSTANCE = INSTANCE2;

public static JAXBEqualsStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected int hashCodeInternal(ObjectLocator locator, int hashCode,

public static JAXBHashCodeStrategy INSTANCE2 = new JAXBHashCodeStrategy();
@SuppressWarnings("deprecation")
public static HashCodeStrategy INSTANCE = INSTANCE2;
public static JAXBHashCodeStrategy INSTANCE = INSTANCE2;

public static JAXBHashCodeStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected Object mergeInternal(ObjectLocator leftLocator,

public static final JAXBMergeCollectionsStrategy INSTANCE2 = new JAXBMergeCollectionsStrategy();
@SuppressWarnings("deprecation")
public static final MergeStrategy INSTANCE = INSTANCE2;
public static final JAXBMergeCollectionsStrategy INSTANCE = INSTANCE2;

public static JAXBMergeCollectionsStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected Object mergeInternal(ObjectLocator leftLocator,

public static final JAXBMergeStrategy INSTANCE2 = new JAXBMergeStrategy();
@SuppressWarnings("deprecation")
public static final MergeStrategy INSTANCE = INSTANCE2;
public static final JAXBMergeStrategy INSTANCE = INSTANCE2;

public static JAXBMergeStrategy getInstance() {
return INSTANCE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected StringBuilder appendInternal(ObjectLocator locator,

public static final JAXBToStringStrategy INSTANCE2 = new JAXBToStringStrategy();
@SuppressWarnings("deprecation")
public static final ToStringStrategy INSTANCE = INSTANCE2;
public static final JAXBToStringStrategy INSTANCE = INSTANCE2;

public static JAXBToStringStrategy getInstance() {
return INSTANCE2;
Expand Down
56 changes: 56 additions & 0 deletions basics/tests/po-0.11.0-runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<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-basics-project</artifactId>
<version>2.0.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>jaxb2-basics-test-po-0.11.0-runtime</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Basics :: Test [po-0.11.0-runtime]</name>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.11.0</version>
</dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<generatePackage>generated.v0_11_0</generatePackage>
<args>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-XtoString</arg>
<arg>-XtoString-toStringStrategyClass=internal.v0_11_0.EnumToStringStrategy</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package internal.v0_11_0;

import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;

public class EnumToStringStrategy extends JAXBToStringStrategy {

public boolean isUseIdentityHashCode() {
return false;
}

public StringBuilder appendStart(ObjectLocator parentLocator, Object parent, StringBuilder stringBuilder) {
if (parent instanceof Enum) {
return stringBuilder;
} else {
return super.appendStart(parentLocator, parent, stringBuilder);
}
}

public StringBuilder appendEnd(ObjectLocator parentLocator, Object parent, StringBuilder stringBuilder) {
if (parent instanceof Enum) {
return appendEnum((Enum) parent, stringBuilder);
} else {
return super.appendEnd(parentLocator, parent, stringBuilder);
}
}

protected StringBuilder appendEnum(Enum e, StringBuilder stringBuilder) {
stringBuilder.append(e.name());
return stringBuilder;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jvnet.jaxb2_commons.tests.v0_11_0;

import org.junit.Assert;
import org.junit.Test;

public class EqualsPo_V0_11_0_Test {

@Test
public void testEqualsOld() {
generated.v0_11_0.Items.Item item = new generated.v0_11_0.Items.Item();
item.setComment("a");


generated.v0_11_0.Items.Item anotherItem = new generated.v0_11_0.Items.Item();
anotherItem.setComment("a");

Assert.assertEquals("equals doesnt work with 0.11.0 runtime", item, anotherItem);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jvnet.jaxb2_commons.tests.v0_11_0;

import org.junit.Assert;
import org.junit.Test;

public class ToStringPo_V0_11_0_Test {

@Test
public void testToString() {
generated.v0_11_0.Items.Item item = new generated.v0_11_0.Items.Item();
item.setComment("a");

Assert.assertEquals("toString doesnt work with 0.11.0 runtime",
"generated.v0_11_0.Items$Item[productName=<null>(default), quantity=0, usPrice=<null>(default), comment=a, shipDate=<null>(default), partNum=<null>(default)]",
item.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
log4j.rootCategory=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=system.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb2-basics-tests</artifactId>
<artifactId>jaxb-basics-project</artifactId>
<version>2.0.15-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>jaxb2-basics-test-po-old-runtime</artifactId>
<artifactId>jaxb2-basics-test-po-0.13.1-runtime</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Basics :: Test [po-old-runtime]</name>
<name>JAXB Tools :: JAXB Basics :: Test [po-0.13.1-runtime]</name>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin-testing</artifactId>
Expand All @@ -31,9 +35,12 @@
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<generatePackage>generated.v0_13_1</generatePackage>
<args>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-XtoString</arg>
<arg>-XtoString-toStringStrategyClass=internal.v0_13_1.EnumToStringStrategy</arg>
</args>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package internal.v0_13_1;

import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;

public class EnumToStringStrategy extends JAXBToStringStrategy {

public boolean isUseIdentityHashCode() {
return false;
}

public StringBuilder appendStart(ObjectLocator parentLocator, Object parent, StringBuilder stringBuilder) {
if (parent instanceof Enum) {
return stringBuilder;
} else {
return super.appendStart(parentLocator, parent, stringBuilder);
}
}

public StringBuilder appendEnd(ObjectLocator parentLocator, Object parent, StringBuilder stringBuilder) {
if (parent instanceof Enum) {
return appendEnum((Enum) parent, stringBuilder);
} else {
return super.appendEnd(parentLocator, parent, stringBuilder);
}
}

protected StringBuilder appendEnum(Enum e, StringBuilder stringBuilder) {
stringBuilder.append(e.name());
return stringBuilder;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:annotation>
<xsd:documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

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

<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>

<xsd:complexType name="USAddress">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:NMTOKEN"
fixed="US"/>
</xsd:complexType>

<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
<xsd:element name="quantity">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="USPrice" type="xsd:decimal"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="partNum" type="SKU" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<!-- Stock Keeping Unit, a code for identifying products -->
<xsd:simpleType name="SKU">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}-[A-Z]{2}"/>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>
Loading