users@jaxb.java.net

Re: Does not throw an validation exception

From: Sriram Thyagarajan <Sriram_Thyagarajan_at_KEANE-NNE.com>
Date: Fri, 02 May 2003 09:13:18 -0400

any help on the below error ? The restriction does not work (both length
and pattern are not imposed during validtion)

-----Original Message-----
From: Sriram Thyagarajan
Sent: Wednesday, April 30, 2003 4:08 PM
To: 'JAXB-INTEREST_at_JAVA.SUN.COM'
Subject: Does not throw an validation exception


Here is definition...

  <xsd:simpleType name="StringTime_HHmmss">
    <xsd:restriction base="xsd:string">
      <xsd:length value="6" fixed="true"/>
      <xsd:pattern value="[0-2][0-3][0-5][0-9][0-5][0-9]"/>
    </xsd:restriction>
  </xsd:simpleType>

...
      <xsd:element name="AccidentTime" type="StringTime_HHmmss"
        minOccurs="1" maxOccurs="1"/>
...



All I am trying to do here is trying to validate the input field is a valid
hour/min/sec combination...

For the following input date, no validation exception is thrown during
unmarshalling

    <AccidentTime>595959</AccidentTime>

What am I doing wrong here... Any help appreciated.

I have my own even Handler and it catches other validation events related to
date conversion

      _jaxbContext = JAXBContext.newInstance(packageName);
      _unMarshaller = _jaxbContext.createUnmarshaller();

      //Set the event handler
      _xmlValidationEventsHandler = new XmlValidationEventsHandler();
      _unMarshaller.setEventHandler(_xmlValidationEventsHandler);

      //Set the validation to true
      _unMarshaller.setValidating(true);

All that the event Handler does is create an list (I did this, so that I can
process or ignore as needed)

  public boolean handleEvent(ValidationEvent event) {
    boolean returnFlag = true;
    if (event.getSeverity() == ValidationEvent.FATAL_ERROR) {
      //Stop when there is a fatal error
      returnFlag = false;
    } else {
      boolean ignorableEvent = checkIfIgnorable(event);
      if (!ignorableEvent) {
        if (_validationsEvents == null) {
          _validationsEvents = new ArrayList();
        }
        _validationsEvents.add(event);
      }
    }
    return returnFlag;
  }


Thanks