1/*2 * $Id: AbstractTilesApplicationContextFactory.java 734996 2009-01-16 13:27:28Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.context;
2223import java.util.Map;
2425import org.apache.commons.logging.Log;
26import org.apache.commons.logging.LogFactory;
27import org.apache.tiles.Initializable;
28import org.apache.tiles.TilesApplicationContext;
29import org.apache.tiles.reflect.ClassUtil;
3031/***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.136 */37publicabstractclassAbstractTilesApplicationContextFactory {
3839/***40 * Initialization parameter that represents the context factory class name.41 *42 * @since 2.1.143 */44publicstaticfinal String APPLICATION_CONTEXT_FACTORY_INIT_PARAM =
45"org.apache.tiles.context.AbstractTilesApplicationContextFactory";
4647/***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.153 */54publicabstract TilesApplicationContext createApplicationContext(
55 Object context);
5657/***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.164 */65publicstaticAbstractTilesApplicationContextFactory createFactory(
66 TilesApplicationContext preliminaryContext) {
67 Log log = LogFactory
68 .getLog(AbstractTilesApplicationContextFactory.class);
69AbstractTilesApplicationContextFactory retValue;
7071if (log.isInfoEnabled()) {
72 log.info("Initializing Tiles2 application context. . .");
73 }
7475 Map<String, String> params = preliminaryContext.getInitParams();
7677 String className = params.get(APPLICATION_CONTEXT_FACTORY_INIT_PARAM);
7879if (className != null) {
80 retValue = (AbstractTilesApplicationContextFactory) ClassUtil
81 .instantiate(className);
82 } else {
83 retValue = newChainedTilesApplicationContextFactory();
84 }
8586if (retValue instanceof Initializable) {
87 ((Initializable) retValue).init(params);
88 }
8990if (log.isInfoEnabled()) {
91 log.info("Finished initializing Tiles2 application context.");
92 }
9394return retValue;
95 }
96 }