users@jaxb.java.net

Re: How to register a custom ValidationEventHandler with XmlJavaTypeAdapter

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 8 Feb 2011 10:17:47 +0100

On 7 February 2011 23:02, Mandava, Rajesh <Rajesh.Mandava_at_ca.com> wrote:

> 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?
>

Use the Unmarshaller method:

void *setEventHandler*(ValidationEventHandler
<file:////usr/local/java/jdk1.6.0_03/docs/api/javax/xml/bind/ValidationEventHandler.html>
handler)

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

2. Is there a way to get JAXBContext from within SqlDateAdaptor?
>
Add code to retrieve the object from wherever you create it. Or store it
into a static variable of SqlDateAdaptor.

-W


>
>
> 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.comMarcella.Nunns_at_ca.com
> [image: cid:image002.gif@01CB0303.F65E6E00] <http://www.ca.com/>
>