1 24 package org.riotfamily.riot.editor.xml; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.riotfamily.common.xml.BeanConfigurationWatcher; 31 import org.riotfamily.common.xml.ConfigurableBean; 32 import org.riotfamily.common.xml.ConfigurationEventListener; 33 import org.riotfamily.common.xml.DocumentReader; 34 import org.riotfamily.common.xml.ValidatingDocumentReader; 35 import org.riotfamily.riot.editor.EditorDefinition; 36 import org.riotfamily.riot.editor.EditorRepository; 37 import org.springframework.beans.factory.InitializingBean; 38 import org.springframework.context.ApplicationContext; 39 import org.springframework.context.ApplicationContextAware; 40 import org.springframework.core.io.Resource; 41 42 45 public class XmlEditorRepository extends EditorRepository 46 implements ApplicationContextAware, InitializingBean, ConfigurableBean, 47 ConfigurationEventListener { 48 49 private ApplicationContext applicationContext; 50 51 private List configLocations; 52 53 private boolean reloadable = true; 54 55 private BeanConfigurationWatcher configWatcher = 56 new BeanConfigurationWatcher(this); 57 58 private XmlEditorRepositoryDigester digester; 59 60 public void setApplicationContext(ApplicationContext applicationContext) { 61 this.applicationContext = applicationContext; 62 } 63 64 public void setConfig(Resource config) { 65 setConfigLocations(new Resource[] { config }); 66 } 67 68 public void setConfigLocations(Resource[] configLocations) { 69 this.configLocations = new ArrayList (); 70 if (configLocations != null) { 71 for (int i = 0; i < configLocations.length; i++) { 72 this.configLocations.add(configLocations[i]); 73 } 74 } 75 configWatcher.setResources(this.configLocations); 76 } 77 78 81 public void addListener(ConfigurationEventListener listener) { 82 configWatcher.addListener(listener); 83 } 84 85 public boolean isReloadable() { 86 return this.reloadable; 87 } 88 89 public void setReloadable(boolean reloadable) { 90 this.reloadable = reloadable; 91 } 92 93 public void afterPropertiesSet() throws Exception { 94 digester = new XmlEditorRepositoryDigester(this, applicationContext); 95 configure(); 96 getFormRepository().addListener(this); 97 getListRepository().addListener(this); 98 } 99 100 public synchronized EditorDefinition getEditorDefinition(String editorId) { 101 configWatcher.checkForModifications(); 102 return super.getEditorDefinition(editorId); 103 } 104 105 106 public void configure() { 107 setRootGroupDefinition(null); 108 getEditorDefinitions().clear(); 109 Iterator it = configLocations.iterator(); 110 while (it.hasNext()) { 111 Resource res = (Resource) it.next(); 112 DocumentReader reader = new ValidatingDocumentReader(res); 113 digester.digest(reader.readDocument(), res); 114 } 115 } 116 117 public void beanReconfigured(ConfigurableBean bean) { 118 configure(); 119 } 120 121 } 122 | Popular Tags |