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.main;
17  
18  import java.util.Arrays;
19  import java.util.Collections;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.common.util.Assert;
24  import org.kuali.common.util.spring.service.PropertySourceConfig;
25  import org.kuali.common.util.spring.service.PropertySourceService;
26  import org.springframework.core.env.PropertySource;
27  
28  public class DefaultMainService implements MainService {
29  
30  	private final PropertySourceService service;
31  
32  	public DefaultMainService(PropertySourceService service) {
33  		Assert.noNulls(service);
34  		this.service = service;
35  	}
36  
37  	@Override
38  	public PropertySource<?> getPropertySource(MainContext context, Class<? extends PropertySourceConfig> config) {
39  		Assert.noNulls(context, config);
40  		Map<String, Object> beans = Collections.singletonMap(MainUtils.MAIN_CONTEXT_BEAN_NAME, (Object) context);
41  		List<String> activeProfiles = Arrays.asList(MainUtils.MAIN_PROFILE_NAME);
42  		return service.getPropertySource(beans, null, activeProfiles, config);
43  	}
44  
45  	public PropertySourceService getService() {
46  		return service;
47  	}
48  
49  }