001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/model/ValidationError.java $
003: * $Id: ValidationError.java 21196 2007-02-09 18:57:43Z john.ellis@rsmart.com $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.model;
021:
022: import java.util.List;
023: import java.util.ArrayList;
024: import java.util.Arrays;
025:
026: /**
027: * Created by IntelliJ IDEA.
028: * User: John Ellis
029: * Date: Aug 18, 2005
030: * Time: 2:51:11 PM
031: * To change this template use File | Settings | File Templates.
032: */
033:
034: /**
035: * This object contains information reguarding an error on an individual field
036: * that occurs during validation
037: *
038: * @see ElementBean
039: */
040: public class ValidationError {
041:
042: private String fieldName;
043: private String errorCode;
044: private Object[] errorInfo;
045: private String defaultMessage;
046: private String label;
047:
048: /**
049: * Construct a ValidationError with all the required parameters
050: *
051: * @param fieldName the name of the field within this element. if the field
052: * is from a nested element, the parent field name will be prepended with a "."
053: * @param errorCode Code that is suitable for dereferencing into a properties file for
054: * i8n purposes. errorCode will contain the proper formatting for use as a default message.
055: * for instance, "Value {1} for field {0} must match pattern {2}". With the error info, this could be
056: * used by a message formater.
057: * @param errorInfo an array of information related to the error.
058: * @param defaultMessage the fields applied to the error code.
059: */
060: public ValidationError(String label, String fieldName,
061: String errorCode, Object[] errorInfo, String defaultMessage) {
062: this .label = label;
063: this .fieldName = fieldName;
064: this .errorCode = errorCode;
065: this .errorInfo = composeErrorInfo(errorInfo);
066: this .defaultMessage = defaultMessage;
067: }
068:
069: protected Object[] composeErrorInfo(Object[] errorInfo) {
070: if (errorInfo == null || errorInfo.length == 0) {
071: return new Object[] { getLabel() };
072: }
073:
074: List info = new ArrayList(Arrays.asList(errorInfo));
075: info.add(0, getLabel());
076: return info.toArray();
077: }
078:
079: public String getFieldName() {
080: return fieldName;
081: }
082:
083: public void setFieldName(String fieldName) {
084: this .fieldName = fieldName;
085: }
086:
087: public String getErrorCode() {
088: return errorCode;
089: }
090:
091: public void setErrorCode(String errorCode) {
092: this .errorCode = errorCode;
093: }
094:
095: public Object[] getErrorInfo() {
096: return errorInfo;
097: }
098:
099: public void setErrorInfo(Object[] errorInfo) {
100: this .errorInfo = errorInfo;
101: }
102:
103: public String getDefaultMessage() {
104: return defaultMessage;
105: }
106:
107: public void setDefaultMessage(String defaultMessage) {
108: this .defaultMessage = defaultMessage;
109: }
110:
111: public String getLabel() {
112: return label;
113: }
114:
115: public void setLabel(String label) {
116: this.label = label;
117: }
118: }
|