1/*2 * $Id: ChainedDelegateAttributeRenderer.java 821299 2009-10-03 12:15:05Z 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.renderer.impl;
2223import java.io.IOException;
24import java.util.ArrayList;
25import java.util.List;
2627import org.apache.tiles.Attribute;
28import org.apache.tiles.context.TilesRequestContext;
29import org.apache.tiles.renderer.RendererException;
30import org.apache.tiles.renderer.TypeDetectingAttributeRenderer;
3132/***33 * Renders an attribute that has no associated renderer using delegation to34 * other renderers.35 *36 * @version $Rev: 821299 $ $Date: 2009-10-03 14:15:05 +0200 (sab, 03 ott 2009) $37 * @since 2.2.138 */39publicclassChainedDelegateAttributeRendererextendsAbstractBaseAttributeRenderer {
4041/***42 * The list of chained renderers.43 */44private List<TypeDetectingAttributeRenderer> renderers;
4546/***47 * Constructor.48 *49 * @since 2.2.150 */51publicChainedDelegateAttributeRenderer() {
52 renderers = new ArrayList<TypeDetectingAttributeRenderer>();
53 }
5455/***56 * Adds an attribute renderer to the list. The first inserted this way, the57 * first is checked when rendering.58 *59 * @param renderer The renderer to add.60 */61publicvoid addAttributeRenderer(TypeDetectingAttributeRenderer renderer) {
62 renderers.add(renderer);
63 }
6465/*** {@inheritDoc} */66 @Override
67publicvoid write(Object value, Attribute attribute,
68TilesRequestContext request)
69 throws IOException {
70if (value == null) {
71thrownew NullPointerException("The attribute value is null");
72 }
7374for (TypeDetectingAttributeRenderer renderer : renderers) {
75if (renderer.isRenderable(value, attribute, request)) {
76 renderer.render(attribute, request);
77return;
78 }
79 }
8081thrownewRendererException("Type of the attribute not found, class '"82 + value.getClass() + "' value '" + value.toString() + "'");
83 }
84 }