View Javadoc

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