001 package org.nakedobjects.applib.events;
002
003 import org.nakedobjects.applib.Identifier;
004
005
006 /**
007 * Represents a check as to whether the proposed values of the value type is valid.
008 *
009 * <p>
010 * If {@link #getReason()} is not <tt>null</tt> then provides the reason why the proposed value is invalid,
011 * otherwise the new value is acceptable.
012 */
013 public class ParseValueEvent extends ValidityEvent implements ProposedHolderEvent {
014
015 private static final long serialVersionUID = 1L;
016
017 private static Object coalesce(final Object source, final String proposed) {
018 return source != null?source:proposed;
019 }
020
021 private final String proposed;
022
023 public ParseValueEvent(final Object source, final Identifier classIdentifier, final String proposed) {
024 super(coalesce(source, proposed), classIdentifier);
025 this.proposed = proposed;
026 }
027
028
029 /**
030 * Will be the source provided in the {@link #ParseValueEvent(Object, Identifier, String) constructor}
031 * if not null, otherwise will fallback to the proposed value.
032 */
033 @Override
034 public Object getSource() {
035 return super.getSource();
036 }
037
038 public String getProposed() {
039 return proposed;
040 }
041
042 }