View Javadoc

1   /*
2    * 
3    * $Revision: 1.5 $
4    * $Date: 2005/01/11 08:23:59 $
5    *
6    * ====================================================================
7    * struts-it
8    * Copyright (C) 2004 - strutsit community
9    * 
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   * created: 2004-06-05  Manfred Wolff
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      // -- Instance variables---------------------------------------------------
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      //-- Properties
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      //-- Interface Methods
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             // TODO handle exception
116         }
117         if (log.isTraceEnabled()) {
118             log.trace("reread -> END");
119         }
120     }
121 }