001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 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 implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.framework.type; 017 018import org.kuali.rice.core.api.mo.common.Coded; 019 020import java.util.HashSet; 021import java.util.Set; 022 023/** 024 * enum used to specify the validationRule type to be specified in the vended {@link ValidationRule}s. INVALID VALID 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 * 027 */ 028 029public enum ValidationRuleType implements Coded { 030 /** 031 * use this flag with the static factory to get a ValidationRuleTypeService} that creates 032 * warning validationRules. 033 */ 034 INVALID("I"), 035 036 /** 037 * use this flag with the static factory to get a ValidationRuleTypeService} that creates 038 * error validationRules. 039 */ 040 VALID("V"); 041 042 private final String code; 043 044 /** 045 * Create a ValdationRuleTye of the given code 046 * @param code 047 */ 048 private ValidationRuleType(String code) { 049 this.code = code; 050 } 051 052 @Override 053 public String toString() { 054 return this.name().toLowerCase(); 055 } 056 057 /** 058 * for each type, check the input with the lowercase version of the type name, and returns any match. 059 * @param s the type to retrieve 060 * @return the type, or null if a match is not found. 061 */ 062 public static ValidationRuleType fromString(String s) { 063 for (ValidationRuleType type : ValidationRuleType.values()) { 064 if (type.toString().equals(s.toLowerCase())) { 065 return type; 066 } 067 } 068 return null; 069 } 070 071 /** 072 * for each type, check the input with the uppercase version of the type code, and returns any match. 073 * @param code the type to retrieve 074 * @return the type, or null if a match is not found. 075 */ 076 public static ValidationRuleType fromCode(String code) { 077 if (code == null) { 078 return null; 079 } 080 for (ValidationRuleType type : values()) { 081 if (type.code.equals(code)) { 082 return type; 083 } 084 } 085 throw new IllegalArgumentException("Failed to locate the ValidationRuleType with the given code: " + code); 086 } 087 088 089 /** 090 * Set of valid type codes 091 */ 092 public static final Set<String> VALID_TYPE_CODES = new HashSet<String>(); 093 static { 094 for (ValidationRuleType type : values()) { 095 VALID_TYPE_CODES.add(type.getCode()); 096 } 097 } 098 099 /** 100 * The code value for this object. In general a code value cannot be null or a blank string. 101 * 102 * @return the code value for this object. 103 */ 104 @Override 105 public String getCode() { 106 return code; 107 } 108}