001 /*
002 * Copyright 2002-2005 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.binding.validation.support;
017
018 import org.springframework.binding.validation.ValidationMessage;
019 import org.springframework.core.style.ToStringCreator;
020 import org.springframework.richclient.core.DefaultMessage;
021 import org.springframework.richclient.core.Severity;
022 import org.springframework.util.ObjectUtils;
023
024 /**
025 * Default implementation of ValidationMessage
026 *
027 * @author Oliver Hutchison
028 */
029 public class DefaultValidationMessage extends DefaultMessage implements ValidationMessage {
030 private final String property;
031
032 public DefaultValidationMessage(String property, Severity severity, String message) {
033 super(message, severity);
034 this.property = property;
035 }
036
037 public String getProperty() {
038 return property;
039 }
040
041 public int hashCode() {
042 return (getProperty() != null ? (getProperty().hashCode() * 27) : 0) + (getSeverity().getShortCode() * 9)
043 + getMessage().hashCode();
044 }
045
046 public boolean equals(Object o) {
047 if (o == null || o.getClass() != this.getClass()) {
048 return false;
049 }
050 DefaultValidationMessage m2 = (DefaultValidationMessage)o;
051 return ObjectUtils.nullSafeEquals(getProperty(), m2.getProperty()) && getSeverity().equals(m2.getSeverity())
052 && getMessage().equals(m2.getMessage());
053 }
054
055 public String toString() {
056 return new ToStringCreator(this).append("property", getProperty())
057 .append("severity", getSeverity().getLabel())
058 .append("message", getMessage())
059 .toString();
060 }
061 }