1 package org.kuali.common.util.spring.env; 2 3 import java.io.File; 4 5 import org.kuali.common.util.Assert; 6 7 public final class EnvContext<T> { 8 9 public EnvContext(String key, Class<T> type) { 10 this(key, type, null); 11 } 12 13 public EnvContext(String key, Class<T> type, T defaultValue) { 14 Assert.noNulls(type); 15 Assert.noBlanks(key); 16 this.key = key; 17 this.type = type; 18 this.defaultValue = defaultValue; 19 } 20 21 private final String key; 22 private final Class<T> type; 23 private final T defaultValue; 24 25 public String getKey() { 26 return key; 27 } 28 29 public Class<T> getType() { 30 return type; 31 } 32 33 public T getDefaultValue() { 34 return defaultValue; 35 } 36 37 public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) { 38 return new EnvContext<T>(key, type, defaultValue); 39 } 40 41 public static EnvContext<String> newString(String key, String defaultValue) { 42 return newCtx(key, String.class, defaultValue); 43 } 44 45 public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) { 46 return newCtx(key, Boolean.class, defaultValue); 47 } 48 49 public static EnvContext<Integer> newInteger(String key, Integer defaultValue) { 50 return newCtx(key, Integer.class, defaultValue); 51 } 52 53 public static EnvContext<File> newFile(String key, File defaultValue) { 54 return newCtx(key, File.class, defaultValue); 55 } 56 57 }