1/*2 * $Id: CachingTilesContainer.java 537196 2007-05-11 14:07:35Z 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.impl.mgmt;
2223import org.apache.tiles.Definition;
24import org.apache.tiles.TilesException;
25import org.apache.tiles.context.TilesRequestContext;
26import org.apache.tiles.definition.DefinitionsFactoryException;
27import org.apache.tiles.definition.DefinitionsFactory;
28import org.apache.tiles.impl.BasicTilesContainer;
29import org.apache.tiles.mgmt.MutableTilesContainer;
3031/***32 * Mutable container which caches (in memory) the definitions33 * registered to it. If a definition is not found in cache, it34 * will revert back to it's definitions factory.35 *36 * @since Tiles 2.037 * @version $Rev: 537196 $ $Date: 2007-05-11 16:07:35 +0200 (Fri, 11 May 2007) $38 */39publicclassCachingTilesContainerextendsBasicTilesContainer40 implements MutableTilesContainer {
4142/***43 * The definition manager to store custom and main definitions.44 */45privateDefinitionManager mgr = newDefinitionManager();
4647/*** {@inheritDoc} */48publicvoid register(Definition definition, Object... requestItems) throws TilesException {
49TilesRequestContext requestContext = getContextFactory().createRequestContext(
50 getApplicationContext(),
51 requestItems
52 );
53 register(definition, requestContext);
54 }
5556/*** {@inheritDoc} */57 @Override
58protected Definition getDefinition(String definition,
59TilesRequestContext context)
60 throws DefinitionsFactoryException {
61return mgr.getDefinition(definition, context);
62 }
636465/*** {@inheritDoc} */66 @Override
67publicDefinitionsFactory getDefinitionsFactory() {
68return mgr.getFactory();
69 }
7071/*** {@inheritDoc} */72 @Override
73publicvoid setDefinitionsFactory(DefinitionsFactory definitionsFactory) {
74super.setDefinitionsFactory(definitionsFactory);
75 mgr.setFactory(definitionsFactory);
76 }
7778/***79 * Registers a custom definition.80 *81 * @param definition The definition to register.82 * @param request The request inside which the definition should be83 * registered.84 * @throws DefinitionsFactoryException If something goes wrong during adding85 * a definition, such as missing parent definitions.86 */87protectedvoid register(Definition definition,
88TilesRequestContext request) throws DefinitionsFactoryException {
89 Definition def = new Definition(definition);
90 mgr.addDefinition(def, request);
91 }
92 }