001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.describe;
016    
017    import org.apache.tapestry.IMarkupWriter;
018    import org.apache.tapestry.IRequestCycle;
019    
020    /**
021     * Renders an object array as an unordered list; each element is recursively rendered.
022     * 
023     * @author Howard M. Lewis Ship
024     * @since 4.0
025     */
026    public class ObjectArrayRenderStrategy implements RenderStrategy
027    {
028        private RenderStrategy _renderStrategy;
029    
030        public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle)
031        {
032            Object[] array = (Object[]) object;
033    
034            if (array.length == 0)
035            {
036                writer.begin("em");
037                writer.print("empty list");
038                writer.end();
039                return;
040            }
041    
042            writer.begin("ul");
043    
044            for (int i = 0; i < array.length; i++)
045            {
046                writer.begin("li");
047                _renderStrategy.renderObject(array[i], writer, cycle);
048                writer.end();
049    
050            }
051    
052            writer.end();
053        }
054    
055        public void setRenderStrategy(RenderStrategy renderStrategy)
056        {
057            _renderStrategy = renderStrategy;
058        }
059    
060    }