View Javadoc

1   /**
2    * $Id: ConfigurationManager.java 17 2006-10-19 15:11:35Z maldito_orco $
3    * $Revision: 17 $
4    * $Date: 2006-10-19 12:11:35 -0300 (Thu, 19 Oct 2006) $
5    *
6    * =========================================================================
7    *
8    * Copyright 2005 Tubo
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  package org.tubo.configuration;
23  
24  //log
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  //tubo
28  import org.tubo.configuration.reader.ConfigurationReader;
29  import org.tubo.configuration.reader.XMLDigesterConfigurationReader;
30  import org.tubo.configuration.def.Configuration;
31  import org.tubo.exception.TuboConfigurationException;
32  
33  /**
34   * Created: Aug 24, 2006, 12:23:43 AM
35   * Last Modification Date: $Date: 2006-10-19 12:11:35 -0300 (Thu, 19 Oct 2006) $
36   *
37   * @author maldito_orco (maldito_orco@users.sourceforge.net)
38   * @version $Revision: 17 $
39   */
40  public class ConfigurationManager {
41      public static final String RCS_ID = "$Id: ConfigurationManager.java 17 2006-10-19 15:11:35Z maldito_orco $";
42      private static Log log = LogFactory.getLog(ConfigurationManager.class);
43  
44      private ConfigurationReader configurationReader = null;
45      private Configuration configuration = null;
46  
47      /**
48       * Default constructor.
49       * Create reader and initialize basic configuration
50       * @throws TuboConfigurationException
51       */
52      public ConfigurationManager() throws TuboConfigurationException {
53          //
54          // create reader
55          configurationReader = new XMLDigesterConfigurationReader();
56      }
57  
58      /**
59       * Create an initial configuration based on meta-rules
60       * @throws TuboConfigurationException
61       */
62      protected void initialize(String resourceLocation) throws TuboConfigurationException {
63          //
64          // load base configuration (based on meta-rules)
65          //configuration = configurationReader.load(FILENAME_META_RULES);
66          configuration = configurationReader.load(resourceLocation);
67      }
68  
69      /**
70       * Get configuration managed by this object
71       * @return configuration managed by this manager
72       */
73      public Configuration getConfiguration() {
74          return configuration;
75      }
76  
77      /**
78       * Append configuration 
79       * @param resourceLocation
80       */
81      public void appendResource(String resourceLocation) throws TuboConfigurationException {
82          if (configuration==null)
83              //
84              // load initial configuration
85              initialize(resourceLocation);
86          else
87              //
88              // append configuration
89              configuration = configurationReader.append(resourceLocation,configuration);
90      }
91  
92  }