This project has retired. For details please refer to its Attic page.
AbstractTilesApplicationContextFactory xref
View Javadoc

1   /*
2    * $Id: AbstractTilesApplicationContextFactory.java 734996 2009-01-16 13:27:28Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.context;
22  
23  import java.util.Map;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.tiles.Initializable;
28  import org.apache.tiles.TilesApplicationContext;
29  import org.apache.tiles.reflect.ClassUtil;
30  
31  /***
32   * Abstract factory to create factories for {@link TilesApplicationContext}.
33   *
34   * @version $Rev: 734996 $ $Date: 2009-01-16 14:27:28 +0100 (ven, 16 gen 2009) $
35   * @since 2.1.1
36   */
37  public abstract class AbstractTilesApplicationContextFactory  {
38  
39      /***
40       * Initialization parameter that represents the context factory class name.
41       *
42       * @since 2.1.1
43       */
44      public static final String APPLICATION_CONTEXT_FACTORY_INIT_PARAM =
45          "org.apache.tiles.context.AbstractTilesApplicationContextFactory";
46  
47      /***
48       * Create a TilesApplicationContext for the given context.
49       *
50       * @param context The (application) context to use.
51       * @return TilesApplicationContext The Tiles application context.
52       * @since 2.1.1
53       */
54      public abstract TilesApplicationContext createApplicationContext(
55              Object context);
56  
57      /***
58       * Creates the Tiles application context factory.
59       *
60       * @param preliminaryContext The preliminary {@link TilesApplicationContext}
61       * that allows access to the initialization parameters.
62       * @return The factory.
63       * @since 2.1.1
64       */
65      public static AbstractTilesApplicationContextFactory createFactory(
66              TilesApplicationContext preliminaryContext) {
67          Log log = LogFactory
68                  .getLog(AbstractTilesApplicationContextFactory.class);
69          AbstractTilesApplicationContextFactory retValue;
70  
71          if (log.isInfoEnabled()) {
72              log.info("Initializing Tiles2 application context. . .");
73          }
74  
75          Map<String, String> params = preliminaryContext.getInitParams();
76  
77          String className = params.get(APPLICATION_CONTEXT_FACTORY_INIT_PARAM);
78  
79          if (className != null) {
80              retValue = (AbstractTilesApplicationContextFactory) ClassUtil
81                      .instantiate(className);
82          } else {
83              retValue = new ChainedTilesApplicationContextFactory();
84          }
85  
86          if (retValue instanceof Initializable) {
87              ((Initializable) retValue).init(params);
88          }
89  
90          if (log.isInfoEnabled()) {
91              log.info("Finished initializing Tiles2 application context.");
92          }
93  
94          return retValue;
95      }
96  }