View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.spring.env;
17  
18  import java.io.File;
19  
20  import org.kuali.common.util.Assert;
21  
22  public final class EnvContext<T> {
23  
24  	public EnvContext(String key, Class<T> type) {
25  		this(key, type, null);
26  	}
27  
28  	public EnvContext(String key, Class<T> type, T defaultValue) {
29  		Assert.noNulls(type);
30  		Assert.noBlanks(key);
31  		this.key = key;
32  		this.type = type;
33  		this.defaultValue = defaultValue;
34  	}
35  
36  	private final String key;
37  	private final Class<T> type;
38  	private final T defaultValue;
39  
40  	public String getKey() {
41  		return key;
42  	}
43  
44  	public Class<T> getType() {
45  		return type;
46  	}
47  
48  	public T getDefaultValue() {
49  		return defaultValue;
50  	}
51  
52  	public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) {
53  		return new EnvContext<T>(key, type, defaultValue);
54  	}
55  
56  	public static EnvContext<String> newString(String key, String defaultValue) {
57  		return newCtx(key, String.class, defaultValue);
58  	}
59  
60  	public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) {
61  		return newCtx(key, Boolean.class, defaultValue);
62  	}
63  
64  	public static EnvContext<Integer> newInteger(String key, Integer defaultValue) {
65  		return newCtx(key, Integer.class, defaultValue);
66  	}
67  
68  	public static EnvContext<File> newFile(String key, File defaultValue) {
69  		return newCtx(key, File.class, defaultValue);
70  	}
71  
72  }