001 package org.springframework.richclient.samples.showcase.exceptionhandling;
002
003 import java.util.ArrayList;
004 import java.util.List;
005
006 import org.hibernate.validator.InvalidStateException;
007 import org.hibernate.validator.InvalidValue;
008 import org.springframework.richclient.command.ActionCommand;
009 import org.springframework.richclient.exceptionhandling.HibernateValidatorDialogExceptionHandler;
010
011 /**
012 * Throws an {@link InvalidStateException} with several {@link InvalidValue}s
013 * to show the {@link HibernateValidatorDialogExceptionHandler}.
014 *
015 * @author Jan Hoskens
016 *
017 */
018 public class HibernateExceptionHandlerCommand extends ActionCommand {
019
020 /**
021 * Dummy bean for invalidValues.
022 */
023 public static class MyBean {
024
025 }
026
027 @Override
028 protected void doExecuteCommand() {
029 List<InvalidValue> invalidExceptions = new ArrayList<InvalidValue>(5);
030 MyBean myBean = new MyBean();
031 invalidExceptions.add(new InvalidValue("first invalid message", MyBean.class, "firstProperty",
032 "first invalid value", myBean));
033 invalidExceptions.add(new InvalidValue("second invalid message", MyBean.class, "secondProperty",
034 "second invalid value", myBean));
035 invalidExceptions.add(new InvalidValue("third invalid message", MyBean.class, "thirdProperty",
036 "third invalid value", myBean));
037 invalidExceptions.add(new InvalidValue("fourth invalid message", MyBean.class, "fourthProperty",
038 "fourth invalid value", myBean));
039 invalidExceptions.add(new InvalidValue("fifth invalid message", MyBean.class, "fifthProperty",
040 "fifth invalid value", myBean));
041 throw new InvalidStateException(invalidExceptions.toArray(new InvalidValue[] {}));
042 }
043 }