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.main.spring;
017
018import org.kuali.common.util.execute.Executable;
019import org.kuali.common.util.main.MainContext;
020import org.kuali.common.util.main.MainService;
021import org.kuali.common.util.properties.spring.DefaultPropertySourceConfig;
022import org.kuali.common.util.spring.SpringExecUtils;
023import org.kuali.common.util.spring.config.annotation.Execute;
024import org.kuali.common.util.spring.service.PropertySourceConfig;
025import org.kuali.common.util.spring.service.SpringService;
026import org.kuali.common.util.spring.service.SpringServiceConfig;
027import org.springframework.beans.factory.annotation.Autowired;
028import org.springframework.context.annotation.Configuration;
029import org.springframework.context.annotation.Import;
030import org.springframework.core.env.PropertySource;
031
032@Configuration
033@Import({ SpringServiceConfig.class, MainServiceConfig.class })
034public abstract class AbstractMainRunner implements MainConfig {
035
036        protected Class<? extends PropertySourceConfig> getPropertySourceConfig() {
037                return DefaultPropertySourceConfig.class;
038        }
039
040        protected abstract Class<?> getConfig();
041
042        @Autowired
043        MainContext mainContext;
044
045        @Autowired
046        MainService mainService;
047
048        @Autowired
049        SpringService service;
050
051        @Override
052        @Execute
053        public Executable main() {
054                PropertySource<?> source = mainService.getPropertySource(mainContext, getPropertySourceConfig());
055                return SpringExecUtils.getSpringExecutable(service, source, getConfig());
056        }
057
058}