01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.validation;
18:
19: import org.springframework.context.support.DefaultMessageSourceResolvable;
20: import org.springframework.util.Assert;
21:
22: /**
23: * Encapsulates an object error, that is, a global reason for rejecting
24: * an object.
25: *
26: * <p>See the {@link DefaultMessageCodesResolver} javadoc for details on
27: * how a message code list is built for an <code>ObjectError</code>.
28: *
29: * @author Juergen Hoeller
30: * @see FieldError
31: * @see DefaultMessageCodesResolver
32: * @since 10.03.2003
33: */
34: public class ObjectError extends DefaultMessageSourceResolvable {
35:
36: private final String objectName;
37:
38: /**
39: * Creates a new instance of the {@link ObjectError} class.
40: * @param objectName the name of the affected object
41: * @param codes the codes to be used to resolve this message
42: * @param arguments the array of arguments to be used to resolve this message
43: * @param defaultMessage the default message to be used to resolve this message
44: * @throws IllegalArgumentException if the supplied <code>objectName</code> is <code>null</code>
45: */
46: public ObjectError(String objectName, String[] codes,
47: Object[] arguments, String defaultMessage) {
48: super (codes, arguments, defaultMessage);
49: Assert.notNull(objectName, "Object name must not be null");
50: this .objectName = objectName;
51: }
52:
53: /**
54: * Return the name of the affected object.
55: */
56: public String getObjectName() {
57: return objectName;
58: }
59:
60: public String toString() {
61: return "Error in object '" + this .objectName + "': "
62: + resolvableToString();
63: }
64:
65: public boolean equals(Object other) {
66: if (this == other) {
67: return true;
68: }
69: if (!(getClass().equals(other.getClass()))
70: || !super .equals(other)) {
71: return false;
72: }
73: ObjectError otherError = (ObjectError) other;
74: return getObjectName().equals(otherError.getObjectName());
75: }
76:
77: public int hashCode() {
78: return super .hashCode() * 29 + getObjectName().hashCode();
79: }
80:
81: }
|