View Javadoc
1   /**
2    * Copyright 2010-2013 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.service;
17  
18  import java.util.List;
19  
20  import org.kuali.common.util.spring.PropertySourceUtils;
21  import org.springframework.core.env.PropertySource;
22  
23  public class PropertySourceContext {
24  
25  	public static final boolean DEFAULT_REMOVE_EXISTING_SOURCES = false;
26  	public static final boolean DEFAULT_LAST_ONE_IN_WINS = true;
27  	public static final PropertySourceAddPriority DEFAULT_PRIORITY = PropertySourceAddPriority.LAST;
28  
29  	// If true, any existing property sources are removed and replaced by the list from this context
30  	boolean removeExistingSources = DEFAULT_REMOVE_EXISTING_SOURCES;
31  
32  	// If true, the last PropertySource in the list has the highest priority
33  	// That is to say, Spring will search for property values starting at the bottom of the list and work its way upwards, stopping as soon as it has a match
34  	boolean lastOneInWins = DEFAULT_LAST_ONE_IN_WINS;
35  
36  	// Can add property sources before or after existing property sources
37  	PropertySourceAddPriority priority = DEFAULT_PRIORITY;
38  
39  	// The list of property source objects to add to the environment
40  	List<PropertySource<?>> sources;
41  
42  	public PropertySourceContext() {
43  		this(null);
44  	}
45  
46  	public PropertySourceContext(List<PropertySource<?>> sources) {
47  		this(sources, DEFAULT_REMOVE_EXISTING_SOURCES);
48  	}
49  
50  	public PropertySourceContext(PropertySource<?> source, boolean removeExistingSources) {
51  		this(PropertySourceUtils.asList(source), removeExistingSources);
52  	}
53  
54  	public PropertySourceContext(List<PropertySource<?>> sources, boolean removeExistingSources) {
55  		this.sources = sources;
56  		this.removeExistingSources = removeExistingSources;
57  	}
58  
59  	public boolean isRemoveExistingSources() {
60  		return removeExistingSources;
61  	}
62  
63  	public void setRemoveExistingSources(boolean removeExistingSources) {
64  		this.removeExistingSources = removeExistingSources;
65  	}
66  
67  	public boolean isLastOneInWins() {
68  		return lastOneInWins;
69  	}
70  
71  	public void setLastOneInWins(boolean lastOneInWins) {
72  		this.lastOneInWins = lastOneInWins;
73  	}
74  
75  	public List<PropertySource<?>> getSources() {
76  		return sources;
77  	}
78  
79  	public void setSources(List<PropertySource<?>> sources) {
80  		this.sources = sources;
81  	}
82  
83  	public PropertySourceAddPriority getPriority() {
84  		return priority;
85  	}
86  
87  	public void setPriority(PropertySourceAddPriority priority) {
88  		this.priority = priority;
89  	}
90  
91  }