KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > validation > ObjectError


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc objectName;
37
38
39     /**
40      * Creates a new instance of the {@link ObjectError} class.
41      * @param objectName the name of the affected object
42      * @param codes the codes to be used to resolve this message
43      * @param arguments the array of arguments to be used to resolve this message
44      * @param defaultMessage the default message to be used to resolve this message
45      * @throws IllegalArgumentException if the supplied <code>objectName</code> is <code>null</code>
46      */

47     public ObjectError(String JavaDoc objectName, String JavaDoc[] codes, Object JavaDoc[] arguments, String JavaDoc 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 JavaDoc getObjectName() {
57         return objectName;
58     }
59
60
61     public String JavaDoc toString() {
62         return "Error in object '" + this.objectName + "': " + resolvableToString();
63     }
64
65     public boolean equals(Object JavaDoc other) {
66         if (this == other) {
67             return true;
68         }
69         if (!(getClass().equals(other.getClass())) || !super.equals(other)) {
70             return false;
71         }
72         ObjectError otherError = (ObjectError) other;
73         return getObjectName().equals(otherError.getObjectName());
74     }
75
76     public int hashCode() {
77         return super.hashCode() * 29 + getObjectName().hashCode();
78     }
79
80 }
81
Popular Tags