KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > xml > XmlEditorRepository


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.editor.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.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 /**
43  *
44  */

45 public class XmlEditorRepository extends EditorRepository
46         implements ApplicationContextAware, InitializingBean, ConfigurableBean,
47         ConfigurationEventListener {
48
49     private ApplicationContext applicationContext;
50
51     private List JavaDoc 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 JavaDoc();
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     /**
79      * @since 6.5
80      */

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 JavaDoc {
94         digester = new XmlEditorRepositoryDigester(this, applicationContext);
95         configure();
96         getFormRepository().addListener(this);
97         getListRepository().addListener(this);
98     }
99
100     public synchronized EditorDefinition getEditorDefinition(String JavaDoc editorId) {
101         configWatcher.checkForModifications();
102         return super.getEditorDefinition(editorId);
103     }
104
105
106     public void configure() {
107         setRootGroupDefinition(null);
108         getEditorDefinitions().clear();
109         Iterator JavaDoc 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