1 5 package javax.xml.bind.util; 6 7 import javax.xml.bind.ValidationEvent; 8 import javax.xml.bind.ValidationEventHandler; 9 import java.util.ArrayList ; 10 import java.util.List ; 11 12 30 public class ValidationEventCollector implements ValidationEventHandler 31 { 32 private final List <ValidationEvent> events = new ArrayList <ValidationEvent>(); 33 34 42 public ValidationEvent[] getEvents() { 43 return events.toArray(new ValidationEvent[events.size()]); 44 } 45 46 49 public void reset() { 50 events.clear(); 51 } 52 53 60 public boolean hasEvents() { 61 return !events.isEmpty(); 62 } 63 64 public boolean handleEvent( ValidationEvent event ) { 65 events.add(event); 66 67 boolean retVal = true; 68 switch( event.getSeverity() ) { 69 case ValidationEvent.WARNING: 70 retVal = true; break; 72 case ValidationEvent.ERROR: 73 retVal = true; break; 75 case ValidationEvent.FATAL_ERROR: 76 retVal = false; break; 78 default: 79 _assert( false, 80 Messages.format( Messages.UNRECOGNIZED_SEVERITY, 81 event.getSeverity() ) ); 82 break; 83 } 84 85 return retVal; 86 } 87 88 private static void _assert( boolean b, String msg ) { 89 if( !b ) { 90 throw new InternalError ( msg ); 91 } 92 } 93 } 94 | Popular Tags |