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.service; 017 018import java.util.List; 019 020import org.kuali.common.util.spring.PropertySourceUtils; 021import org.springframework.core.env.PropertySource; 022 023public 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(PropertySourceUtils.asList(source), removeExistingSources); 052 } 053 054 public PropertySourceContext(List<PropertySource<?>> sources, boolean removeExistingSources) { 055 this.sources = sources; 056 this.removeExistingSources = removeExistingSources; 057 } 058 059 public boolean isRemoveExistingSources() { 060 return removeExistingSources; 061 } 062 063 public void setRemoveExistingSources(boolean removeExistingSources) { 064 this.removeExistingSources = removeExistingSources; 065 } 066 067 public boolean isLastOneInWins() { 068 return lastOneInWins; 069 } 070 071 public void setLastOneInWins(boolean lastOneInWins) { 072 this.lastOneInWins = lastOneInWins; 073 } 074 075 public List<PropertySource<?>> getSources() { 076 return sources; 077 } 078 079 public void setSources(List<PropertySource<?>> sources) { 080 this.sources = sources; 081 } 082 083 public PropertySourceAddPriority getPriority() { 084 return priority; 085 } 086 087 public void setPriority(PropertySourceAddPriority priority) { 088 this.priority = priority; 089 } 090 091}