| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.config; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.xml.namespace.QName; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
import org.apache.log4j.Logger; |
| 25 | |
import org.kuali.rice.core.config.event.RiceConfigEvent; |
| 26 | |
import org.kuali.rice.core.config.event.RiceConfigEventListener; |
| 27 | |
import org.kuali.rice.core.lifecycle.BaseCompositeLifecycle; |
| 28 | |
import org.kuali.rice.core.lifecycle.Lifecycle; |
| 29 | |
import org.kuali.rice.core.resourceloader.ResourceLoader; |
| 30 | |
import org.kuali.rice.core.resourceloader.SpringResourceLoader; |
| 31 | |
import org.springframework.beans.factory.InitializingBean; |
| 32 | |
|
| 33 | |
public abstract class ModuleConfigurer extends BaseCompositeLifecycle implements Configurer, InitializingBean, RiceConfigEventListener { |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | protected final Logger LOG = Logger.getLogger(getClass()); |
| 38 | |
|
| 39 | |
public static final String LOCAL_RUN_MODE = "local"; |
| 40 | |
public static final String EMBEDDED_RUN_MODE = "embedded"; |
| 41 | |
public static final String REMOTE_RUN_MODE = "remote"; |
| 42 | |
public static final String THIN_RUN_MODE = "thin"; |
| 43 | 0 | protected final List<String> VALID_RUN_MODES = new ArrayList<String>(); |
| 44 | |
|
| 45 | 0 | private String runMode = LOCAL_RUN_MODE; |
| 46 | 0 | private String moduleName = "!!!UNSET!!!"; |
| 47 | 0 | protected String webModuleConfigName = ""; |
| 48 | 0 | protected String webModuleConfigurationFiles = ""; |
| 49 | 0 | protected String webModuleBaseUrl = ""; |
| 50 | 0 | protected boolean webInterface = false; |
| 51 | |
protected boolean testMode; |
| 52 | 0 | protected String springFileLocations = ""; |
| 53 | |
protected String resourceLoaderName; |
| 54 | 0 | protected boolean exposeServicesOnBus = true; |
| 55 | 0 | protected boolean setSOAPServicesAsDefault = false; |
| 56 | 0 | protected boolean includeUserInterfaceComponents = true; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | 0 | public ModuleConfigurer() { |
| 62 | 0 | VALID_RUN_MODES.add( LOCAL_RUN_MODE ); |
| 63 | 0 | VALID_RUN_MODES.add( EMBEDDED_RUN_MODE ); |
| 64 | 0 | VALID_RUN_MODES.add( REMOTE_RUN_MODE ); |
| 65 | 0 | VALID_RUN_MODES.add( THIN_RUN_MODE ); |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
@Override |
| 74 | |
protected List<Lifecycle> loadLifecycles() throws Exception { |
| 75 | 0 | return new ArrayList<Lifecycle>(0); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public void afterPropertiesSet() throws Exception { |
| 81 | 0 | if ( getModuleName().equals( "!!!UNSET!!!" ) ) { |
| 82 | 0 | throw new IllegalArgumentException( "Module Name must be given for each ModuleConfigurer instance" ); |
| 83 | |
} |
| 84 | 0 | if ( hasWebInterface() ) { |
| 85 | 0 | if ( StringUtils.isBlank( webModuleConfigName ) ) { |
| 86 | 0 | setWebModuleConfigName( "config/" + getModuleName().toLowerCase() ); |
| 87 | |
} |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
} |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public String getRunMode() { |
| 97 | 0 | return this.runMode; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void setRunMode(String runMode) { |
| 101 | 0 | runMode = runMode.trim(); |
| 102 | 0 | if ( !VALID_RUN_MODES.contains( runMode ) ) { |
| 103 | 0 | throw new IllegalArgumentException( "Invalid run mode for the " + this.getClass().getSimpleName() + ": " + runMode + " - Valid Values are: " + VALID_RUN_MODES ); |
| 104 | |
} |
| 105 | 0 | this.runMode = runMode; |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
|
| 109 | |
public Config loadConfig(Config parentConfig) throws Exception { |
| 110 | 0 | if ( LOG.isInfoEnabled() ) { |
| 111 | 0 | LOG.info("Starting configuration of " + getModuleName() + " for service namespace " + parentConfig.getServiceNamespace()); |
| 112 | |
} |
| 113 | 0 | Config config = parentConfig; |
| 114 | 0 | if (Boolean.valueOf(config.getProperty("rice." + getModuleName().toLowerCase() + ".testMode"))) { |
| 115 | 0 | testMode = true; |
| 116 | |
} |
| 117 | 0 | configureWebConfiguration(config); |
| 118 | 0 | configureRunMode(config); |
| 119 | 0 | return config; |
| 120 | |
} |
| 121 | |
|
| 122 | |
protected void configureWebConfiguration( Config config ) throws Exception { |
| 123 | 0 | if ( StringUtils.isBlank( getWebModuleConfigurationFiles() ) ) { |
| 124 | 0 | if ( StringUtils.isBlank( config.getProperty( "rice." + getModuleName().toLowerCase() + ".struts.config.files" ) ) ) { |
| 125 | 0 | setWebModuleConfigurationFiles( "/" + getModuleName().toLowerCase() + "/WEB-INF/struts-config.xml" ); |
| 126 | |
} else { |
| 127 | 0 | setWebModuleConfigurationFiles( config.getProperty( "rice." + getModuleName().toLowerCase() + ".struts.config.files" ) ); |
| 128 | |
} |
| 129 | |
} |
| 130 | 0 | config.putProperty( "rice." + getModuleName().toLowerCase() + ".struts.config.files", getWebModuleConfigurationFiles() ); |
| 131 | 0 | if ( StringUtils.isBlank( getWebModuleBaseUrl() ) ) { |
| 132 | 0 | if ( StringUtils.isBlank( config.getProperty( getModuleName().toLowerCase() + ".url" ) ) ) { |
| 133 | 0 | setWebModuleBaseUrl( config.getProperty( "application.url" ) + "/" + getModuleName().toLowerCase() ); |
| 134 | |
} else { |
| 135 | 0 | setWebModuleBaseUrl( config.getProperty( getModuleName().toLowerCase() + ".url" ) ); |
| 136 | |
} |
| 137 | |
} |
| 138 | 0 | config.putProperty( getModuleName().toLowerCase() + ".url", getWebModuleBaseUrl() ); |
| 139 | 0 | if ( StringUtils.isEmpty( getSpringFileLocations() ) ) { |
| 140 | 0 | setSpringFileLocations( getDefaultSpringBeansPath(getDefaultConfigPackagePath() ) ); |
| 141 | |
} |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
protected void configureRunMode(Config config) { |
| 148 | 0 | String propertyName = getModuleName().toLowerCase() + ".mode"; |
| 149 | 0 | config.putProperty(propertyName, getRunMode()); |
| 150 | 0 | } |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
public String getSpringFileLocations() throws Exception { |
| 159 | 0 | return springFileLocations; |
| 160 | |
} |
| 161 | |
|
| 162 | |
|
| 163 | |
protected String getDefaultConfigPackagePath() { |
| 164 | 0 | return "org/kuali/rice/" + getModuleName().toLowerCase() + "/config/"; |
| 165 | |
} |
| 166 | |
protected String getDefaultSpringBeansPath(String configPackagePath) { |
| 167 | 0 | return configPackagePath + getModuleName().toUpperCase() + "SpringBeans.xml"; |
| 168 | |
} |
| 169 | |
public String getDefaultResourceLoaderName() { |
| 170 | 0 | return getModuleName().toUpperCase() + "_SPRING_RESOURCE_LOADER"; |
| 171 | |
} |
| 172 | |
public QName getDefaultResourceLoaderQName() { |
| 173 | 0 | return new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), getDefaultResourceLoaderName()); |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
public ResourceLoader getResourceLoaderToRegister() throws Exception{ |
| 183 | 0 | return null; |
| 184 | |
} |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
protected ResourceLoader createResourceLoader() throws Exception { |
| 199 | 0 | String context = getSpringFileLocations(); |
| 200 | 0 | ResourceLoader resourceLoader = new SpringResourceLoader(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), resourceLoaderName), context); |
| 201 | 0 | return resourceLoader; |
| 202 | |
} |
| 203 | |
|
| 204 | |
|
| 205 | |
public void onEvent(RiceConfigEvent event) throws Exception { |
| 206 | 0 | if ( LOG.isInfoEnabled() ) { |
| 207 | 0 | LOG.info( "ModuleConfigurer.onEvent() called: " + event ); |
| 208 | |
} |
| 209 | 0 | } |
| 210 | |
|
| 211 | |
public String getModuleName() { |
| 212 | 0 | return this.moduleName; |
| 213 | |
} |
| 214 | |
|
| 215 | |
public void setModuleName(String moduleName) { |
| 216 | 0 | this.moduleName = moduleName; |
| 217 | 0 | } |
| 218 | |
|
| 219 | |
public String getWebModuleConfigName() { |
| 220 | 0 | return this.webModuleConfigName; |
| 221 | |
} |
| 222 | |
|
| 223 | |
public void setWebModuleConfigName(String webModuleConfigName) { |
| 224 | 0 | this.webModuleConfigName = webModuleConfigName; |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
public String getWebModuleConfigurationFiles() { |
| 228 | 0 | return this.webModuleConfigurationFiles; |
| 229 | |
} |
| 230 | |
|
| 231 | |
public void setWebModuleConfigurationFiles(String webModuleConfigurationFiles) { |
| 232 | 0 | this.webModuleConfigurationFiles = webModuleConfigurationFiles; |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
public boolean hasWebInterface() { |
| 236 | 0 | return this.webInterface; |
| 237 | |
} |
| 238 | |
|
| 239 | |
protected void setHasWebInterface(boolean webInterface) { |
| 240 | 0 | this.webInterface = webInterface; |
| 241 | 0 | } |
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
public boolean shouldRenderWebInterface() { |
| 251 | 0 | return hasWebInterface() && getRunMode().equals( ModuleConfigurer.LOCAL_RUN_MODE ); |
| 252 | |
} |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
public boolean isTestMode() { |
| 258 | 0 | return this.testMode; |
| 259 | |
} |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public void setTestMode(boolean testMode) { |
| 265 | 0 | this.testMode = testMode; |
| 266 | 0 | } |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
public void setSpringFileLocations(String springFileLocations) { |
| 272 | 0 | this.springFileLocations = springFileLocations; |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
public String getWebModuleBaseUrl() { |
| 279 | 0 | return this.webModuleBaseUrl; |
| 280 | |
} |
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
public void setWebModuleBaseUrl(String webModuleBaseUrl) { |
| 286 | 0 | this.webModuleBaseUrl = webModuleBaseUrl; |
| 287 | 0 | } |
| 288 | |
|
| 289 | |
public boolean isExposeServicesOnBus() { |
| 290 | 0 | return this.exposeServicesOnBus; |
| 291 | |
} |
| 292 | |
|
| 293 | |
public void setExposeServicesOnBus(boolean exposeServicesOnBus) { |
| 294 | 0 | this.exposeServicesOnBus = exposeServicesOnBus; |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
public boolean isIncludeUserInterfaceComponents() { |
| 298 | 0 | return this.includeUserInterfaceComponents; |
| 299 | |
} |
| 300 | |
|
| 301 | |
public void setIncludeUserInterfaceComponents( |
| 302 | |
boolean includeUserInterfaceComponents) { |
| 303 | 0 | this.includeUserInterfaceComponents = includeUserInterfaceComponents; |
| 304 | 0 | } |
| 305 | |
|
| 306 | |
public boolean isSetSOAPServicesAsDefault() { |
| 307 | 0 | return this.setSOAPServicesAsDefault; |
| 308 | |
} |
| 309 | |
|
| 310 | |
public void setSetSOAPServicesAsDefault(boolean setSOAPServicesAsDefault) { |
| 311 | 0 | this.setSOAPServicesAsDefault = setSOAPServicesAsDefault; |
| 312 | 0 | } |
| 313 | |
|
| 314 | |
|
| 315 | |
} |