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

1   /*
2    * $Id: BasicTilesInitializer.java 831448 2009-10-30 20:39:52Z 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.startup;
22  
23  import org.apache.tiles.Initializable;
24  import org.apache.tiles.TilesApplicationContext;
25  import org.apache.tiles.context.AbstractTilesApplicationContextFactory;
26  import org.apache.tiles.factory.AbstractTilesContainerFactory;
27  
28  /***
29   * Default Tiles initialization delegate implementation under a servlet
30   * environment. It uses init parameters to create the
31   * {@link TilesApplicationContext} and the {@link org.apache.tiles.TilesContainer}.
32   *
33   * @version $Rev: 831448 $ $Date: 2009-10-30 21:39:52 +0100 (ven, 30 ott 2009) $
34   * @since 2.1.2
35   * @deprecated Don't use it, please extend {@link AbstractTilesInitializer}.
36   */
37  public class BasicTilesInitializer extends AbstractTilesInitializer {
38  
39      /***
40       * Init parameter to define the key under which the container will be
41       * stored.
42       *
43       * @since 2.1.2
44       */
45      public static final String CONTAINER_KEY_INIT_PARAMETER =
46          "org.apache.tiles.startup.BasicTilesInitializer.CONTAINER_KEY";
47  
48      /***
49       * Creates the Tiles application context, to be used across all the
50       * Tiles-based application. If you override this class, please override this
51       * method or
52       * {@link #createAndInitializeTilesApplicationContextFactory(TilesApplicationContext)}.
53       *
54       * @param preliminaryContext The preliminary application context to use.
55       * @return The Tiles application context.
56       * @since 2.1.2
57       */
58      protected TilesApplicationContext createTilesApplicationContext(
59              TilesApplicationContext preliminaryContext) {
60          AbstractTilesApplicationContextFactory acFactory =
61              createAndInitializeTilesApplicationContextFactory(preliminaryContext);
62          return acFactory.createApplicationContext(preliminaryContext.getContext());
63      }
64  
65      /***
66       * Creates and initializes the Tiles application context factory, to create
67       * a {@link TilesApplicationContext} to be used across all the Tiles-based
68       * application. If you override this class, please override this method or
69       * {@link #createTilesApplicationContext(TilesApplicationContext)}.
70       *
71       * @param preliminaryContext The preliminary application context to use.
72       * @return The Tiles application context factory.
73       * @since 2.1.2
74       */
75      protected AbstractTilesApplicationContextFactory createAndInitializeTilesApplicationContextFactory(
76              TilesApplicationContext preliminaryContext) {
77          AbstractTilesApplicationContextFactory acFactory = AbstractTilesApplicationContextFactory
78                  .createFactory(preliminaryContext);
79          if (acFactory instanceof Initializable) {
80              ((Initializable) acFactory).init(preliminaryContext.getInitParams());
81          }
82          return acFactory;
83      }
84  
85      /***
86       * Returns the container key under which the container will be stored.
87       *
88       * @param applicationContext The Tiles application context to use.
89       * @return The container key.
90       * @since 2.1.2
91       */
92      protected String getContainerKey(TilesApplicationContext applicationContext) {
93          String key = applicationContext.getInitParams().get(
94                  CONTAINER_KEY_INIT_PARAMETER);
95          return key;
96      }
97  
98      /***
99       * Creates a Tiles container factory. If you override this class, please
100      * override this method or {@link #createContainer(TilesApplicationContext)}.
101      *
102      * @param context The servlet context to use.
103      * @return The created container factory.
104      * @since 2.1.2
105      */
106     protected AbstractTilesContainerFactory createContainerFactory(
107             TilesApplicationContext context) {
108         AbstractTilesContainerFactory factory = AbstractTilesContainerFactory
109                 .getTilesContainerFactory(context);
110         return factory;
111     }
112 }