View Javadoc
1   /*
2    * 
3    * $Revision: 1.3 $
4    * $Date: 2004/06/20 12:18:39 $
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.strutsit.chain.interfaces.ChainConfiguration;
27  
28  /***
29   * Factory for instanciating the properbly configuration class.
30   * 
31   * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff </a>
32   * @since JDK 1.4
33   * @version $Revision: 1.3 $
34   */
35  public final class ChainConfigurationFactory {
36  
37      /// Instance of this class
38      private static ChainConfigurationFactory instance;
39  
40      /***
41       * The Factorymethod of this Factory ;-)
42       * 
43       * @return The one and only ChainConfigurationFactory object.
44       */
45      public static synchronized ChainConfigurationFactory getInstance() {
46  
47          if (instance == null) {
48              instance = new ChainConfigurationFactory();
49          }
50          return instance;
51      }
52  
53      /***
54       * Returns the right configuration configured in the chain.properties.
55       * 
56       * @return A [@link ChainConfiguration} object.
57       * 
58       * @TODO Do something if the configuration is missed. Currently returns the
59       *       method null.
60       */
61      public ChainConfiguration createConfiguration() {
62  
63          PropertyReader reader = PropertyReader.getInstance();
64  
65          Object config = null;
66          if (PropertyReader.XML_MODE.equals(reader.getConfigMode())) {
67              try {
68                  config = Class.forName(reader.getXmlClass()).newInstance();
69              } catch (Exception e) {
70                  ; // misconfigured
71              }
72          }
73          return (ChainConfiguration) config;
74      }
75  }
76