001/** 002 * Copyright 2010-2014 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.common.util.spring.env; 017 018import java.io.File; 019 020import org.kuali.common.util.Assert; 021 022public final class EnvContext<T> { 023 024 public EnvContext(String key, Class<T> type) { 025 this(key, type, null); 026 } 027 028 public EnvContext(String key, Class<T> type, T defaultValue) { 029 Assert.noNulls(type); 030 Assert.noBlanks(key); 031 this.key = key; 032 this.type = type; 033 this.defaultValue = defaultValue; 034 } 035 036 private final String key; 037 private final Class<T> type; 038 private final T defaultValue; 039 040 public String getKey() { 041 return key; 042 } 043 044 public Class<T> getType() { 045 return type; 046 } 047 048 public T getDefaultValue() { 049 return defaultValue; 050 } 051 052 public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) { 053 return new EnvContext<T>(key, type, defaultValue); 054 } 055 056 public static EnvContext<String> newString(String key, String defaultValue) { 057 return newCtx(key, String.class, defaultValue); 058 } 059 060 public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) { 061 return newCtx(key, Boolean.class, defaultValue); 062 } 063 064 public static EnvContext<Integer> newInteger(String key, Integer defaultValue) { 065 return newCtx(key, Integer.class, defaultValue); 066 } 067 068 public static EnvContext<File> newFile(String key, File defaultValue) { 069 return newCtx(key, File.class, defaultValue); 070 } 071 072}