KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > xml > XmlListRepository


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.list.xml;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
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 /**
41  *
42  */

43 public class XmlListRepository extends ListRepository implements
44         InitializingBean, ConfigurableBean {
45
46     private List JavaDoc 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 JavaDoc();
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 JavaDoc {
85         digester = new XmlListRepositoryDigester(this, getApplicationContext());
86         configure();
87     }
88     
89     public ListConfig getListConfig(String JavaDoc listId) {
90         configWatcher.checkForModifications();
91         return super.getListConfig(listId);
92     }
93     
94     public void configure() {
95         getListConfigs().clear();
96         getListConfigsByClass().clear();
97         Iterator JavaDoc 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