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