001    /**
002     * Copyright 2010-2013 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     */
016    package org.kuali.common.util.service;
017    
018    import java.util.List;
019    
020    import org.kuali.common.util.spring.SpringUtils;
021    import org.springframework.core.env.PropertySource;
022    
023    public class PropertySourceContext {
024    
025            public static final boolean DEFAULT_REMOVE_EXISTING_SOURCES = false;
026            public static final boolean DEFAULT_LAST_ONE_IN_WINS = true;
027            public static final PropertySourceAddPriority DEFAULT_PRIORITY = PropertySourceAddPriority.LAST;
028    
029            // If true, any existing property sources are removed and replaced by the list from this context
030            boolean removeExistingSources = DEFAULT_REMOVE_EXISTING_SOURCES;
031    
032            // If true, the last PropertySource in the list has the highest priority
033            // 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
034            boolean lastOneInWins = DEFAULT_LAST_ONE_IN_WINS;
035    
036            // Can add property sources before or after existing property sources
037            PropertySourceAddPriority priority = DEFAULT_PRIORITY;
038    
039            // The list of property source objects to add to the environment
040            List<PropertySource<?>> sources;
041    
042            public PropertySourceContext() {
043                    this(null);
044            }
045    
046            public PropertySourceContext(List<PropertySource<?>> sources) {
047                    this(sources, DEFAULT_REMOVE_EXISTING_SOURCES);
048            }
049    
050            public PropertySourceContext(PropertySource<?> source, boolean removeExistingSources) {
051                    this(SpringUtils.asList(source), removeExistingSources);
052            }
053    
054            public PropertySourceContext(List<PropertySource<?>> sources, boolean removeExistingSources) {
055                    super();
056                    this.sources = sources;
057                    this.removeExistingSources = removeExistingSources;
058            }
059    
060            public boolean isRemoveExistingSources() {
061                    return removeExistingSources;
062            }
063    
064            public void setRemoveExistingSources(boolean removeExistingSources) {
065                    this.removeExistingSources = removeExistingSources;
066            }
067    
068            public boolean isLastOneInWins() {
069                    return lastOneInWins;
070            }
071    
072            public void setLastOneInWins(boolean lastOneInWins) {
073                    this.lastOneInWins = lastOneInWins;
074            }
075    
076            public List<PropertySource<?>> getSources() {
077                    return sources;
078            }
079    
080            public void setSources(List<PropertySource<?>> sources) {
081                    this.sources = sources;
082            }
083    
084            public PropertySourceAddPriority getPriority() {
085                    return priority;
086            }
087    
088            public void setPriority(PropertySourceAddPriority priority) {
089                    this.priority = priority;
090            }
091    
092    }