001/**
002 * Copyright 2005-2016 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.rice.kew.engine;
017
018import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
019import org.kuali.rice.coreservice.framework.parameter.ParameterService;
020import org.kuali.rice.kew.engine.node.service.RouteNodeService;
021import org.kuali.rice.kew.engine.simulation.SimulationEngine;
022import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
023import org.springframework.beans.factory.InitializingBean;
024
025/**
026 * An implementation of the {@link WorkflowEngineFactory}. 
027 * 
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030public class WorkflowEngineFactoryImpl implements WorkflowEngineFactory, InitializingBean {
031
032    private RouteNodeService routeNodeService;
033    private RouteHeaderService routeHeaderService;
034    private ParameterService parameterService;
035    
036    
037    /**
038     * Ensures that all dependencies were injected into this factory.
039     * 
040     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
041     * @throws IllegalStateException if any of the required services are null
042     */
043    @Override
044    public void afterPropertiesSet() {
045        if (routeNodeService == null) {
046            throw new IllegalStateException("routeNodeService not properly injected, was null.");
047        }
048        if (routeHeaderService == null) {
049            throw new IllegalStateException("routeHeaderService not properly injected, was null.");
050        }
051        //if (parameterService == null) {
052        //    throw new IllegalStateException("parameterService not properly injected, was null.");
053        //}
054    }
055    
056    /**
057     * @see org.kuali.rice.kew.engine.WorkflowEngineFactory#newEngine(org.kuali.rice.kew.engine.OrchestrationConfig)
058     */
059    @SuppressWarnings("unchecked")
060    @Override
061    public <E extends WorkflowEngine> E newEngine(OrchestrationConfig config) {
062        switch (config.getCapability()) {
063            case STANDARD:
064                return (E) new StandardWorkflowEngine(routeNodeService, routeHeaderService, parameterService, config);
065            case BLANKET_APPROVAL:
066                return (E) new BlanketApproveEngine(routeNodeService, routeHeaderService, parameterService, config);
067            case SIMULATION:
068                return (E) new SimulationEngine(routeNodeService, routeHeaderService, parameterService, config);
069        }
070        
071        return null;
072    }
073    
074    /**
075     * @return the routeNodeService
076     */
077    public RouteNodeService getRouteNodeService() {
078        return this.routeNodeService;
079    }
080
081
082    /**
083     * @param routeNodeService the routeNodeService to set
084     */
085    public void setRouteNodeService(RouteNodeService routeNodeService) {
086        this.routeNodeService = routeNodeService;
087    }
088
089
090    /**
091     * @return the routeHeaderService
092     */
093    public RouteHeaderService getRouteHeaderService() {
094        return this.routeHeaderService;
095    }
096
097
098    /**
099     * @param routeHeaderService the routeHeaderService to set
100     */
101    public void setRouteHeaderService(RouteHeaderService routeHeaderService) {
102        this.routeHeaderService = routeHeaderService;
103    }
104
105
106    /**
107     * @return the parameterService
108     */
109    public ParameterService getParameterService() {
110        if (this.parameterService == null) {
111            this.parameterService = CoreFrameworkServiceLocator.getParameterService();
112        }
113        return this.parameterService;
114    }
115
116
117    /**
118     * @param parameterService the parameterService to set
119     */
120    public void setParameterService(ParameterService parameterService) {
121        this.parameterService = parameterService;
122    }
123
124}