KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > validator > event > ValidatePreUpdateEventListener


1 //$Id: ValidatePreUpdateEventListener.java,v 1.1 2005/05/27 08:58:53 epbernard Exp $
2
package org.hibernate.validator.event;
3
4 import org.hibernate.event.PreUpdateEvent;
5 import org.hibernate.event.def.DefaultPreUpdateEventListener;
6 import org.hibernate.validator.ClassValidator;
7 import org.hibernate.validator.InvalidStateException;
8 import org.hibernate.validator.InvalidValue;
9
10 /**
11  * Before update, execute the validator framework
12  * @author Gavin King
13  */

14 public class ValidatePreUpdateEventListener extends DefaultPreUpdateEventListener {
15
16     public boolean onPreUpdate(PreUpdateEvent event) {
17         //TODO: cache the validator
18
InvalidValue[] invalidValues = new ClassValidator( event.getEntity().getClass() )
19                 .getInvalidValues( event.getEntity() );
20         if (invalidValues.length>0) {
21             throw new InvalidStateException(invalidValues);
22         }
23         return super.onPreUpdate( event );
24     }
25
26 }
27
Popular Tags