1/*2 * $Id: BasicPreparerFactory.java 791161 2009-07-04 18:53:36Z 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.preparer;
2223import java.util.HashMap;
24import java.util.Map;
2526import org.apache.tiles.context.TilesRequestContext;
27import org.apache.tiles.reflect.ClassUtil;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
3031/***32 * Default implementation of the {@link PreparerFactory}.33 * This factory provides no contextual configuration. It34 * simply instantiates the named preparerInstance and returns it.35 *36 * @since Tiles 2.037 * @version $Rev: 791161 $ $Date: 2009-07-04 20:53:36 +0200 (sab, 04 lug 2009) $38 */39publicclassBasicPreparerFactory implements PreparerFactory {
4041/***42 * The logging object.43 */44privatefinal Logger log = LoggerFactory
45 .getLogger(BasicPreparerFactory.class);
4647/***48 * Maps a preparer name to the instantiated preparer.49 */50protected Map<String, ViewPreparer> preparers;
5152/***53 * Constructor.54 */55publicBasicPreparerFactory() {
56this.preparers = new HashMap<String, ViewPreparer>();
57 }
585960/***61 * Create a new instance of the named preparerInstance. This factory62 * expects all names to be qualified class names.63 *64 * @param name the named preparerInstance65 * @param context current context66 * @return ViewPreparer instance67 */68publicViewPreparer getPreparer(String name, TilesRequestContext context) {
6970if (!preparers.containsKey(name)) {
71 preparers.put(name, createPreparer(name));
72 }
7374return preparers.get(name);
75 }
7677/***78 * Creates a view preparer for the given name.79 *80 * @param name The name of the preparer.81 * @return The created preparer.82 */83protectedViewPreparer createPreparer(String name) {
8485if (log.isDebugEnabled()) {
86 log.debug("Creating ViewPreparer '" + name + "' . . .");
87 }
8889 Object instance = ClassUtil.instantiate(name, true);
90 log.debug("ViewPreparer created successfully");
91return (ViewPreparer) instance;
9293 }
94 }