View Javadoc

    1   package org.apache.turbine.modules;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import org.apache.turbine.Turbine;
    25  import org.apache.turbine.pipeline.PipelineData;
    26
    27  /**
    28   * The purpose of this class is to allow one to load and execute
    29   * Screen modules.
    30   *
    31   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    32   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    33   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    34   * @version $Id: ScreenLoader.java 1709648 2015-10-20 17:08:10Z tv $
    35   */
    36  public class ScreenLoader
    37      extends GenericLoader<Screen>
    38      implements Loader<Screen>
    39  {
    40      /** The single instance of this class. */
    41      private static ScreenLoader instance = new ScreenLoader();
    42
    43      /**
    44       * These ctor's are private to force clients to use getInstance()
    45       * to access this class.
    46       */
    47      private ScreenLoader()
    48      {
    49          super();
    50      }
    51
    52      /**
    53       * Attempts to load and execute the external Screen. This is used
    54       * when you want to execute a Screen which returns its output via
    55       * a String instead of out the data.getResponse() value.
    56       * This allows you to easily chain the execution of Screen modules
    57       * together.
    58       *
    59       * @param pipelineData Turbine information.
    60       * @param name Name of object that will execute the screen.
    61       * @return the output of the screen module
    62       * @exception Exception a generic exception.
    63       */
    64      public String eval(PipelineData pipelineData, String name)
    65              throws Exception
    66      {
    67          // Execute screen
    68          return getAssembler(name).build(pipelineData);
    69      }
    70
    71      /**
    72       * Attempts to load and execute the Screen. This is used when you
    73       * want to execute a Screen which returns its output via the
    74       * data.getResponse() object.
    75       *
    76       * @param pipelineData Turbine information.
    77       * @param name Name of object that will execute the screen.
    78       * @exception Exception a generic exception.
    79       */
    80      @Override
    81      public void exec(PipelineData pipelineData, String name)
    82  	throws Exception
    83  	{
    84          this.eval(pipelineData, name);
    85  	}
    86
    87      /**
    88       * Pulls out an instance of the object by name.  Name is just the
    89       * single name of the object.
    90       *
    91       * @param name Name of object instance.
    92       * @return A Screen with the specified name, or null.
    93       * @exception Exception a generic exception.
    94       */
    95      @Override
    96      public Screen getAssembler(String name)
    97          throws Exception
    98      {
    99          return getAssembler(Screen.class, name);
    100     }
    101
    102     /**
    103      * @see org.apache.turbine.modules.Loader#getCacheSize()
    104      */
    105     @Override
    106     public int getCacheSize()
    107     {
    108         return ScreenLoader.getConfiguredCacheSize();
    109     }
    110
    111     /**
    112      * The method through which this class is accessed.
    113      *
    114      * @return The single instance of this class.
    115      */
    116     public static ScreenLoader getInstance()
    117     {
    118         return instance;
    119     }
    120
    121     /**
    122      * Helper method to get the configured cache size for this module
    123      *
    124      * @return the configure cache size
    125      */
    126     private static int getConfiguredCacheSize()
    127     {
    128         return Turbine.getConfiguration().getInt(Screen.CACHE_SIZE_KEY,
    129                 Screen.CACHE_SIZE_DEFAULT);
    130     }
    131 }