File tree Expand file tree Collapse file tree 4 files changed +50
-35
lines changed
java/org/jvnet/jaxb2_commons/plugin/simplify/tests01 Expand file tree Collapse file tree 4 files changed +50
-35
lines changed Original file line number Diff line number Diff line change 167167 <artifactId >junit</artifactId >
168168 <version >4.11</version >
169169 </dependency >
170+ <!-- Joda-Time -->
171+ <dependency >
172+ <groupId >joda-time</groupId >
173+ <artifactId >joda-time</artifactId >
174+ <version >2.5</version >
175+ </dependency >
170176 <!-- Commons -->
171177 <dependency >
172178 <groupId >org.apache.commons</groupId >
Original file line number Diff line number Diff line change 2121 <groupId >org.jvnet.jaxb2_commons</groupId >
2222 <artifactId >jaxb2-basics</artifactId >
2323 </dependency >
24+ <dependency >
25+ <groupId >joda-time</groupId >
26+ <artifactId >joda-time</artifactId >
27+ </dependency >
2428 </dependencies >
2529 <build >
2630 <defaultGoal >test</defaultGoal >
Original file line number Diff line number Diff line change 22
33import java .util .Date ;
44
5+ import javax .xml .bind .annotation .adapters .XmlAdapter ;
6+
57import org .joda .time .DateTime ;
68import org .joda .time .format .DateTimeFormatter ;
79import org .joda .time .format .ISODateTimeFormat ;
1113 *
1214 * @author
1315 */
14- public class DateAdapter {
15-
16- private static final DateTimeFormatter s_parser = ISODateTimeFormat .dateTimeParser ().withZoneUTC ();
17- private static final DateTimeFormatter s_formatter = ISODateTimeFormat .dateTime ().withZoneUTC ();
18-
19- public static Date parseDateTime (String v ) {
20-
21- try {
22- return s_parser .parseDateTime (v ).toDate ();
23- }
24- catch (Exception e ) {
25- return null ;
26- }
27-
28- }
29-
30- /** {@inheritDoc} */
31-
32- public static String printDateTime (Date v ) {
33- return new DateTime (v ).toString (s_formatter );
34- }
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+ }
3532
3633}
Original file line number Diff line number Diff line change 1- <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify" jaxb:extensionBindingPrefixes="simplify" jaxb:version="2.1">
2- <jaxb:globalBindings choiceContentProperty="true">
3- <jaxb:javaType name="java.util.Date" xmlType="xs:dateTime" parseMethod="com.amadeus.apt.fom.presentation.model.flights.Adapter.DateAdapter.parseDateTime" printMethod="com.amadeus.apt.fom.presentation.model.flights.Adapter.DateAdapter.printDateTime"/>
4- </jaxb:globalBindings>
5- <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
6- <jaxb:schemaBindings>
7- <jaxb:package name="org.jvnet.jaxb2_commons.plugin.simplify.tests01"/>
8- </jaxb:schemaBindings>
9- <jaxb:bindings node="xs:complexType[@name='gh2']">
10- <simplify:property name="bOrC">
11- <simplify:as-element-property/>
12- </simplify:property>
13- </jaxb:bindings>
14- </jaxb:bindings>
1+ <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
2+ xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
3+ xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
4+ jaxb:extensionBindingPrefixes="xjc simplify" jaxb:version="2.1">
5+
6+ <jaxb:globalBindings choiceContentProperty="true">
7+ <!--jaxb:javaType name="java.util.Date" xmlType="xs:dateTime" parseMethod="com.amadeus.apt.fom.presentation.model.flights.Adapter.DateAdapter.parseDateTime"
8+ printMethod="com.amadeus.apt.fom.presentation.model.flights.Adapter.DateAdapter.printDateTime"/ -->
9+ <xjc:javaType name="java.util.Date" xmlType="xs:dateTime"
10+ adapter="org.jvnet.jaxb2_commons.plugin.simplify.tests01.DateAdapter" />
11+ </jaxb:globalBindings>
12+
13+ <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
14+ <jaxb:schemaBindings>
15+ <jaxb:package name="org.jvnet.jaxb2_commons.plugin.simplify.tests01" />
16+ </jaxb:schemaBindings>
17+ <jaxb:bindings node="xs:complexType[@name='gh2']">
18+ <simplify:property name="bOrC">
19+ <simplify:as-element-property />
20+ </simplify:property>
21+ </jaxb:bindings>
22+ </jaxb:bindings>
1523</jaxb:bindings>
1624
You can’t perform that action at this time.
0 commit comments