1 24 package org.riotfamily.riot.list.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.list.ListConfig; 36 import org.riotfamily.riot.list.ListRepository; 37 import org.springframework.beans.factory.InitializingBean; 38 import org.springframework.core.io.Resource; 39 40 43 public class XmlListRepository extends ListRepository implements 44 InitializingBean, ConfigurableBean { 45 46 private List configLocations; 47 48 private boolean reloadable = true; 49 50 private BeanConfigurationWatcher configWatcher; 51 52 private XmlListRepositoryDigester digester; 53 54 public XmlListRepository() { 55 configWatcher = new BeanConfigurationWatcher(this); 56 } 57 58 public void setConfig(Resource config) { 59 setConfigLocations(new Resource[] { config }); 60 } 61 62 public void setConfigLocations(Resource[] configLocations) { 63 this.configLocations = new ArrayList (); 64 if (configLocations != null) { 65 for (int i = 0; i < configLocations.length; i++) { 66 this.configLocations.add(configLocations[i]); 67 } 68 } 69 configWatcher.setResources(this.configLocations); 70 } 71 72 public boolean isReloadable() { 73 return this.reloadable; 74 } 75 76 public void setReloadable(boolean reloadable) { 77 this.reloadable = reloadable; 78 } 79 80 public void addListener(ConfigurationEventListener listener) { 81 configWatcher.addListener(listener); 82 } 83 84 public void afterPropertiesSet() throws Exception { 85 digester = new XmlListRepositoryDigester(this, getApplicationContext()); 86 configure(); 87 } 88 89 public ListConfig getListConfig(String listId) { 90 configWatcher.checkForModifications(); 91 return super.getListConfig(listId); 92 } 93 94 public void configure() { 95 getListConfigs().clear(); 96 getListConfigsByClass().clear(); 97 Iterator it = configLocations.iterator(); 98 while (it.hasNext()) { 99 Resource res = (Resource) it.next(); 100 DocumentReader reader = new ValidatingDocumentReader(res); 101 digester.digest(reader.readDocument(), res); 102 } 103 } 104 105 } 106 | Popular Tags |