FieldError.java
上传用户:jiancairen
上传日期:2007-08-27
资源大小:26458k
文件大小:3k
源码类别:

Java编程

开发平台:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.validation;
  17. /**
  18.  * Class that encapsulates a field error, i.e. a reason for rejecting
  19.  * a specific field value.
  20.  *
  21.  * <p>See DefaultMessageCodesResolver javadoc for details on how a message
  22.  * code list is built for a FieldError.
  23.  *
  24.  * @author Rod Johnson
  25.  * @author Juergen Hoeller
  26.  * @since 10.03.2003
  27.  * @see DefaultMessageCodesResolver
  28.  */
  29. public class FieldError extends ObjectError {
  30. private final String field;
  31. private final Object rejectedValue;
  32. private final boolean bindingFailure;
  33. /**
  34.  * Create a new FieldError instance.
  35.  * @param objectName the name of the affected object
  36.  * @param field the affected field of the object
  37.  * @param rejectedValue the rejected field value
  38.  * @param bindingFailure whether this error represents a binding failure
  39.  * (like a type mismatch); else, it is a validation failure
  40.  * @param codes the codes to be used to resolve this message
  41.  * @param arguments the array of arguments to be used to resolve this message
  42.  * @param defaultMessage the default message to be used to resolve this message
  43.  */
  44. public FieldError(String objectName, String field, Object rejectedValue, boolean bindingFailure,
  45. String[] codes, Object[] arguments, String defaultMessage) {
  46. super(objectName, codes, arguments, defaultMessage);
  47. this.field = field;
  48. this.rejectedValue = rejectedValue;
  49. this.bindingFailure = bindingFailure;
  50. }
  51. /**
  52.  * Return the affected field of the object.
  53.  */
  54. public String getField() {
  55. return field;
  56. }
  57. /**
  58.  * Return the rejected field value.
  59.  */
  60. public Object getRejectedValue() {
  61. return rejectedValue;
  62. }
  63. /**
  64.  * Return whether this error represents a binding failure
  65.  * (like a type mismatch); else, it is a validation failure.
  66.  */
  67. public boolean isBindingFailure() {
  68. return bindingFailure;
  69. }
  70. public String toString() {
  71. return "Field error in object '" + getObjectName() + "' on field '" + this.field +
  72. "': rejectedValue=[" + this.rejectedValue + "]; " + resolvableToString();
  73. }
  74. }