Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.pageload » [javadoc | source]
    1   // Copyright 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.internal.pageload;
   16   
   17   import org.apache.tapestry5.ComponentResources;
   18   import org.apache.tapestry5.MarkupWriter;
   19   import org.apache.tapestry5.runtime.RenderCommand;
   20   import org.apache.tapestry5.runtime.RenderQueue;
   21   
   22   /**
   23    * A RenderCommand wrapper that renders internally a series of render commands. This is intended for static content
   24    * (commands that may write content, but won't affect the render queue itself.
   25    */
   26   public class CompositeRenderCommand implements RenderCommand
   27   {
   28       /**
   29        * Composite commands are intended for static elements; elements that won't invoke methods on the RenderQueue. To
   30        * enforce this, we have a NO-OP version of RenderQueue that is passed ot the composed render commands.
   31        */
   32       private static final RenderQueue NOOP = new RenderQueue()
   33       {
   34           public void push(RenderCommand command)
   35           {
   36               nyi("push");
   37           }
   38   
   39           public void startComponent(ComponentResources resources)
   40           {
   41               nyi("startComponent");
   42           }
   43   
   44           public void endComponent()
   45           {
   46               nyi("endComponent");
   47           }
   48   
   49           private void nyi(String methodName)
   50           {
   51               throw new IllegalStateException(
   52                       String.format("RenderQueue method %s() is not implemented for composited render commands.",
   53                                     methodName));
   54           }
   55       };
   56   
   57       private final RenderCommand[] commands;
   58   
   59       public CompositeRenderCommand(RenderCommand[] commands)
   60       {
   61           this.commands = commands;
   62       }
   63   
   64       public void render(MarkupWriter writer, RenderQueue queue)
   65       {
   66           for (RenderCommand c : commands)
   67           {
   68               c.render(writer, NOOP);
   69           }
   70       }
   71   
   72       @Override
   73       public String toString()
   74       {
   75           StringBuilder builder = new StringBuilder("CompositeRenderCommand[");
   76   
   77           boolean comma = false;
   78   
   79           for (RenderCommand c : commands)
   80           {
   81               if (comma) builder.append(", ");
   82   
   83               builder.append(c);
   84   
   85               comma = true;
   86           }
   87   
   88           return builder.append("]").toString();
   89       }
   90   }

Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.pageload » [javadoc | source]