| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.datadictionary; |
| 17 | |
|
| 18 | |
import no.geosoft.cc.io.FileListener; |
| 19 | |
import no.geosoft.cc.io.FileMonitor; |
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.commons.logging.Log; |
| 22 | |
import org.apache.commons.logging.LogFactory; |
| 23 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 24 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 25 | |
import org.kuali.rice.krad.uif.util.UifBeanFactoryPostProcessor; |
| 26 | |
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
| 27 | |
import org.springframework.core.io.FileSystemResource; |
| 28 | |
import org.springframework.core.io.InputStreamResource; |
| 29 | |
import org.springframework.core.io.Resource; |
| 30 | |
|
| 31 | |
import java.io.File; |
| 32 | |
import java.io.InputStream; |
| 33 | |
import java.net.URL; |
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.List; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public class ReloadingDataDictionary extends DataDictionary implements FileListener, URLMonitor.URLContentChangedListener { |
| 56 | 0 | private static final Log LOG = LogFactory.getLog(DataDictionary.class); |
| 57 | |
|
| 58 | |
private static final String CLASS_DIR_CONFIG_PARM = "reload.data.dictionary.classes.dir"; |
| 59 | |
private static final String SOURCE_DIR_CONFIG_PARM = "reload.data.dictionary.source.dir"; |
| 60 | |
private static final String INTERVAL_CONFIG_PARM = "reload.data.dictionary.interval"; |
| 61 | |
|
| 62 | |
private URLMonitor dictionaryUrlMonitor; |
| 63 | |
|
| 64 | |
|
| 65 | |
public ReloadingDataDictionary() { |
| 66 | 0 | super(); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public void parseDataDictionaryConfigurationFiles(boolean allowConcurrentValidation) { |
| 77 | 0 | ConfigurationService configurationService = KRADServiceLocator.getKualiConfigurationService(); |
| 78 | |
|
| 79 | |
|
| 80 | 0 | String classesDir = configurationService.getPropertyValueAsString(CLASS_DIR_CONFIG_PARM); |
| 81 | |
|
| 82 | |
|
| 83 | 0 | String sourceDir = configurationService.getPropertyValueAsString(SOURCE_DIR_CONFIG_PARM); |
| 84 | |
|
| 85 | |
|
| 86 | 0 | int reloadInterval = Integer.parseInt(configurationService.getPropertyValueAsString(INTERVAL_CONFIG_PARM)); |
| 87 | |
|
| 88 | 0 | FileMonitor dictionaryFileMonitor = new FileMonitor(reloadInterval); |
| 89 | |
|
| 90 | 0 | dictionaryUrlMonitor = new URLMonitor(reloadInterval); |
| 91 | 0 | dictionaryUrlMonitor.addListener(this); |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | 0 | List<String> configLocations = new ArrayList<String>(configFileLocations); |
| 96 | |
|
| 97 | 0 | super.parseDataDictionaryConfigurationFiles(allowConcurrentValidation); |
| 98 | 0 | for (String configLocation : configLocations) { |
| 99 | 0 | Resource classFileResource = getFileResource(configLocation); |
| 100 | |
try { |
| 101 | 0 | if (classFileResource.getURI().toString().startsWith("jar:")) { |
| 102 | 0 | LOG.debug("Monitoring dictionary file at URI: " + classFileResource.getURI().toString()); |
| 103 | 0 | dictionaryUrlMonitor.addURI(classFileResource.getURL()); |
| 104 | |
} else { |
| 105 | 0 | String filePathClassesDir = classFileResource.getFile().getAbsolutePath(); |
| 106 | 0 | String sourceFilePath = StringUtils.replace(filePathClassesDir, classesDir, sourceDir); |
| 107 | 0 | File dictionaryFile = new File(filePathClassesDir); |
| 108 | 0 | if (dictionaryFile.exists()) { |
| 109 | 0 | LOG.debug("Monitoring dictionary file: " + dictionaryFile.getName()); |
| 110 | 0 | dictionaryFileMonitor.addFile(dictionaryFile); |
| 111 | |
} |
| 112 | |
} |
| 113 | |
} |
| 114 | 0 | catch (Exception e) { |
| 115 | 0 | LOG.info("Exception in picking up dictionary file for monitoring: " + e.getMessage(), e); |
| 116 | 0 | } |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
|
| 120 | 0 | dictionaryFileMonitor.addListener(this); |
| 121 | 0 | } |
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
@Override |
| 131 | |
public void fileChanged(File file) { |
| 132 | 0 | LOG.info("reloading dictionary configuration for " + file.getName()); |
| 133 | |
try { |
| 134 | 0 | Resource resource = new FileSystemResource(file); |
| 135 | 0 | xmlReader.loadBeanDefinitions(resource); |
| 136 | |
|
| 137 | 0 | UifBeanFactoryPostProcessor factoryPostProcessor = new UifBeanFactoryPostProcessor(); |
| 138 | 0 | factoryPostProcessor.postProcessBeanFactory(ddBeans); |
| 139 | |
|
| 140 | |
|
| 141 | 0 | ddIndex.run(); |
| 142 | |
} |
| 143 | 0 | catch (Exception e) { |
| 144 | 0 | LOG.info("Exception in dictionary hot deploy: " + e.getMessage(), e); |
| 145 | 0 | } |
| 146 | 0 | } |
| 147 | |
|
| 148 | |
public void urlContentChanged(final URL url) { |
| 149 | 0 | LOG.info("reloading dictionary configuration for " + url.toString()); |
| 150 | |
try { |
| 151 | 0 | InputStream urlStream = url.openStream(); |
| 152 | 0 | InputStreamResource resource = new InputStreamResource(urlStream); |
| 153 | |
|
| 154 | 0 | int originalValidationMode = xmlReader.getValidationMode(); |
| 155 | 0 | xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); |
| 156 | 0 | xmlReader.loadBeanDefinitions(resource); |
| 157 | 0 | xmlReader.setValidationMode(originalValidationMode); |
| 158 | |
|
| 159 | 0 | UifBeanFactoryPostProcessor factoryPostProcessor = new UifBeanFactoryPostProcessor(); |
| 160 | 0 | factoryPostProcessor.postProcessBeanFactory(ddBeans); |
| 161 | |
|
| 162 | |
|
| 163 | 0 | ddIndex.run(); |
| 164 | |
} |
| 165 | 0 | catch (Exception e) { |
| 166 | 0 | LOG.info("Exception in dictionary hot deploy: " + e.getMessage(), e); |
| 167 | 0 | } |
| 168 | 0 | } |
| 169 | |
} |