users@jaxb.java.net

How to register a custom ValidationEventHandler with XmlJavaTypeAdapter

From: Mandava, Rajesh <Rajesh.Mandava_at_ca.com>
Date: Mon, 7 Feb 2011 17:02:33 -0500

    I have a sample EJB Web Service that uses java.sql.Date. So, I used
the

XmlJavaTypeAdapter to overcome the problem with no default constructor

(as suggested in the blog
http://weblogs.java.net/blog/kohsuke/archive/2005/09/using_jaxb_20s.html
).

This application is deployed to JBoss 5.1.0 (JRE build 1.6.0_20-b02).

 

For a date "2011013", my SqlDateAdaptor.unmarshal throws an
UnmarshalException.

But, the UnmarshallerImpl.handleEvent ignores this exception.

 

So, I want to add a custom handler MyCustomValidationEventHandler

overriding the handleEvent as follows:

 

public class MyCustomValidationEventHandler implements
ValidationEventHandler {

    public boolean handleEvent(ValidationEvent event) {

        return event.getSeverity()!=ValidationEvent.ERROR &&

                  event.getSeverity()!=ValidationEvent.FATAL_ERROR;

    }

}

 

How do I register the custom handler MyCustomValidationEventHandler?

1. Should it be done inside the package-info.java?

2. Is there a way to get JAXBContext from within SqlDateAdaptor?

 

Your help will be greatly appreciated.

 

Thanks and Regards,

Rajesh Mandava
CA Technologies
Principal Software Engineer
Tel: +214-473-1334
Fax: +214-473-1323
Rajesh.Mandava_at_ca.com <mailto:Rajesh.Mandava_at_ca.com>
Marcella.Nunns_at_ca.com
<mailto:Marcella.Nunns@ca.com> <http://www.ca.com/>







image001.gif
(image/gif attachment: image001.gif)