View Javadoc

1   /*
2    * Copyright 2005-2009 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.messaging;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.core.config.ConfigContext;
24  import org.kuali.rice.core.config.ConfigurationException;
25  import org.kuali.rice.core.config.ModuleConfigurer;
26  
27  /**
28   * A KSBExporter which will exports the service in the case where the specified
29   * run mode is set.  The run mode order proceeds as follows:
30   * 
31   * <p>remote -> embedded -> local
32   * 
33   * <p>If any of the earlier run modes in the list is set, then the ones after it
34   * will be applied.  So, if remote is set, then it will automatically be exported
35   * for embedded and local run modes.
36   * 
37   * @author Kuali Rice Team (kuali-rice@googlegroups.com)
38   */
39  public class RunModeServiceExporter extends PropertyConditionalKSBExporter {
40  	
41      private String runModePropertyName;
42      private String validRunMode;
43      private static final List<String> runModeHierarchy = new ArrayList<String>();
44      static {
45      	runModeHierarchy.add(ModuleConfigurer.THIN_RUN_MODE);
46      	runModeHierarchy.add(ModuleConfigurer.REMOTE_RUN_MODE);
47      	runModeHierarchy.add(ModuleConfigurer.EMBEDDED_RUN_MODE);
48      	runModeHierarchy.add(ModuleConfigurer.LOCAL_RUN_MODE);
49      }
50  
51      @Override
52  	protected boolean shouldRemoteThisService() throws Exception {
53      	if (StringUtils.isBlank(validRunMode)) {
54      		throw new ConfigurationException("The validRunMode property was not set.");
55      	}
56      	if (!runModeHierarchy.contains(getValidRunMode())) {
57      		throw new ConfigurationException("Given validRunMode is not a valid run mode.  Value was: " + getValidRunMode());
58      	}
59  		String runModePropertyValue = ConfigContext.getCurrentContextConfig().getProperty(getRunModePropertyName());
60      	if (StringUtils.isBlank(runModePropertyValue)) {
61      		throw new ConfigurationException("Given runModePropertyName does not have a value.  The runModePropertyName was " + getRunModePropertyName());
62      	}
63      	if (!runModeHierarchy.contains(runModePropertyValue)) {
64      		throw new ConfigurationException("Run mode value set on runModePropertyName of '" + getRunModePropertyName() + "' is not a valid run mode.  Value was: " + runModePropertyValue);
65      	}
66      	List<String> validRunModeSubList = runModeHierarchy.subList(runModeHierarchy.indexOf(getValidRunMode()), runModeHierarchy.size());
67      	return validRunModeSubList.contains(runModePropertyValue) && super.shouldRemoteThisService();
68  	}
69  
70  	public String getRunModePropertyName() {
71          return this.runModePropertyName;
72      }
73  
74      public void setRunModePropertyName(String runModePropertyName) {
75          this.runModePropertyName = runModePropertyName;
76      }
77  
78      public String getValidRunMode() {
79          return this.validRunMode;
80      }
81  
82      public void setValidRunMode(String validRunMode) {
83          this.validRunMode = validRunMode;
84      }
85      
86  }