1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.strutsit.chain.configuration;
25
26 import org.apache.commons.chain.Catalog;
27 import org.apache.commons.chain.config.ConfigParser;
28 import org.apache.commons.chain.config.ConfigRuleSet;
29 import org.apache.commons.chain.impl.CatalogBase;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.strutsit.chain.ChainException;
33
34 /***
35 * Interface for a chain configuration.
36 *
37 * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff </a>
38 * @since JDK 1.4
39 * @version $Revision: 1.5 $
40 */
41 public class ChainXMLConfiguration extends ChainConfigurationBase {
42
43
44
45 /***
46 * The logger for this class (commons-logging).
47 */
48 private static Log log = LogFactory.getLog(ChainXMLConfiguration.class);
49
50 /***
51 * <p>
52 * The <code>ConfigParser</code> instance under test.
53 * </p>
54 */
55 private transient ConfigParser parser = null;
56
57
58
59
60 /***
61 * <p>
62 * The {@link Catalog}to contain our configured commands.
63 * </p>
64 */
65 private Catalog catalog = null;
66
67 /***
68 * @return Returns the {link Catalog} - object of this configuration.
69 */
70 public final Catalog getCatalog() {
71 return catalog;
72 }
73
74
75
76
77 /***
78 * Inits the configuration.
79 *
80 * @throws ChainException
81 * if something goes wrong.
82 */
83 public final void init() throws ChainException {
84
85 if (log.isTraceEnabled()) {
86 log.trace("init -> START");
87 }
88 super.init();
89 catalog = new CatalogBase();
90 parser = new ConfigParser();
91 ConfigRuleSet ruleset = (ConfigRuleSet) parser.getRuleSet();
92 ruleset.setChainClass("org.strutsit.chain.configuration.ChainConfBase");
93 try {
94 parser.parse(catalog, this.getClass().getResource(getConfigFile()));
95 } catch (Exception e) {
96 throw new ChainException(e);
97 }
98 if (log.isTraceEnabled()) {
99 log.trace("init -> END");
100 }
101 }
102
103 /***
104 * Rereads the configuration.
105 */
106 public final void reread() {
107 if (log.isTraceEnabled()) {
108 log.trace("reread -> START");
109 }
110 catalog = new CatalogBase();
111 try {
112 parser.parse(catalog, this.getClass().getResource(getConfigFile()));
113 } catch (Exception e) {
114 e.printStackTrace();
115
116 }
117 if (log.isTraceEnabled()) {
118 log.trace("reread -> END");
119 }
120 }
121 }