001package org.kuali.common.util.spring.env;
002
003import java.io.File;
004
005import org.kuali.common.util.Assert;
006
007public final class EnvContext<T> {
008
009        public EnvContext(String key, Class<T> type) {
010                this(key, type, null);
011        }
012
013        public EnvContext(String key, Class<T> type, T defaultValue) {
014                Assert.noNulls(type);
015                Assert.noBlanks(key);
016                this.key = key;
017                this.type = type;
018                this.defaultValue = defaultValue;
019        }
020
021        private final String key;
022        private final Class<T> type;
023        private final T defaultValue;
024
025        public String getKey() {
026                return key;
027        }
028
029        public Class<T> getType() {
030                return type;
031        }
032
033        public T getDefaultValue() {
034                return defaultValue;
035        }
036
037        public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) {
038                return new EnvContext<T>(key, type, defaultValue);
039        }
040
041        public static EnvContext<String> newString(String key, String defaultValue) {
042                return newCtx(key, String.class, defaultValue);
043        }
044
045        public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) {
046                return newCtx(key, Boolean.class, defaultValue);
047        }
048
049        public static EnvContext<Integer> newInteger(String key, Integer defaultValue) {
050                return newCtx(key, Integer.class, defaultValue);
051        }
052
053        public static EnvContext<File> newFile(String key, File defaultValue) {
054                return newCtx(key, File.class, defaultValue);
055        }
056
057}