001    /*
002     * Copyright 2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the
005     * "License"); you may not use this file except in compliance with the
006     * License.  You may obtain a copy of the License at
007     *
008     *      http://www.osedu.org/licenses/ECL-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
013     * implied.  See the License for the specific language governing
014     * permissions and limitations under the License.
015     */
016    package org.kuali.student.r2.common.infc;
017    
018    import javax.xml.bind.annotation.XmlEnum;
019    
020    public interface ValidationResult {
021    
022        @XmlEnum
023        public enum ErrorLevel {
024    
025            OK(0), WARN(1), ERROR(2);
026            int level;
027    
028            private ErrorLevel(int level) {
029                this.level = level;
030            }
031    
032            public int getLevel() {
033                return level;
034            }
035    
036            public static ErrorLevel fromInt(int level) {
037                switch (level) {
038                    case 0:
039                        return OK;
040                    case 1:
041                        return WARN;
042                    case 2:
043                        return ERROR;
044                    default:
045                        throw new IllegalArgumentException(level + "");
046                }
047            }
048    
049            public static ErrorLevel min(ErrorLevel e1, ErrorLevel e2) {
050                return e1.ordinal() < e2.ordinal() ? e1 : e2;
051            }
052    
053            public static ErrorLevel max(ErrorLevel e1, ErrorLevel e2) {
054                return e1.ordinal() > e2.ordinal() ? e1 : e2;
055            }
056        }
057    
058        /**
059         * Message explaining this validation result
060         *
061         * If an error it is an an error message.
062         *
063         * TODO: decide if this is a key that then gets resolved into a
064         * real localized message using the message service or the final
065         * localized message itself
066         *
067         * @name Message
068         * @readOnly
069         */
070        public String getMessage();
071    
072        /**
073         * Identifies the element (field) that is the focus of the
074         * validation.  Uses xpath (dot) notation to navigate to the
075         * field, for example: officialIdentifier.code
076         *
077         * TODO: find out how repeating substructures are handled in this
078         * notation, with [n] occurrence brackets?
079         *
080         * @name Element
081         * @readOnly
082         * @required
083         */
084        public String getElement();
085    
086        /**
087         * Indicates the severity of the validation result.
088         *
089         * 0=OK
090         * 1=WARN
091         * 2=ERROR
092         *
093         * @name Level
094         * @readOnly
095         * @required
096         */
097        public ErrorLevel getLevel();
098    }