Hi,

I've read Kohsuke's blog in order to map xs:date to java.util.Date[1]

Its solution is working well but one thing is annoying.
When launching the code generation from cxf-codegen-plugin, one class is created : org.w3._2001.xmlschema.Adapter1.

Its content is :

package org.w3._2001.xmlschema;

import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class Adapter1
    extends XmlAdapter<String, Date>
{
    public Date unmarshal(String value) {
        return (be.ucm.career.converter.jaxb.DateAdapter.parseDate(value));
    }

    public String marshal(Date value) {
        return (be.ucm.career.converter.jaxb.DateAdapter.printDate(value));
    }

}

Note the ugly class and package names.
I don't understand the use of this class since I've created my own adapter, just like Kohsuke did :

package be.ucm.career.converter.jaxb;

import javax.xml.bind.DatatypeConverter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateAdapter {

  public static Date parseDate(String s) {
    return DatatypeConverter.parseDate(s).getTime();
  }

  public static String printDate(Date dt) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(dt);
    return DatatypeConverter.printDate(cal);
  }

}

and added the corresponding binding option :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc";
               xmlns:xs="http://www.w3.org/2001/XMLSchema";
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";>
    <jaxb:globalBindings localScoping="nested"
                         collectionType="java.util.ArrayList"
                         generateValueClass="true">
        <jaxb:javaType name="java.util.Date"
                       xmlType="xs:date"
parseMethod="be.ucm.career.converter.jaxb.DateAdapter.parseDate"

printMethod="be.ucm.career.converter.jaxb.DateAdapter.printDate"
                       hasNsContext="false" />
        <xjc:serializable uid="2"/>
    </jaxb:globalBindings>
</jaxb:bindings>

So normally it should only use my class and not creating one.
Moreover the generated code uses the new class, like this :

@XmlElement(name = "CreationDate", required = true, type = String.class)
    @XmlJavaTypeAdapter(Adapter1 .class)
    @XmlSchemaType(name = "date")
    protected Date creationDate;

Is there something I missed ?

Regards.

[1] http://weblogs.java.net/blog/kohsuke/archive/2006/03/how_do_i_map_xs.html
--
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Reply via email to