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 import org.apache.turbine.util.RunData; 25 26 /** 27 * The purpose of this class is to allow one to load and execute 28 * Layout modules. 29 * 30 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 31 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 32 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 33 * @version $Id: LayoutLoader.java 1078552 2011-03-06 19:58:46Z tv $ 34 */ 35 public class LayoutLoader 36 extends GenericLoader<Layout> 37 implements Loader<Layout> 38 { 39 /** The single instance of this class. */ 40 private static LayoutLoader instance = new LayoutLoader(); 41 42 /** 43 * These ctor's are private to force clients to use getInstance() 44 * to access this class. 45 */ 46 private LayoutLoader() 47 { 48 super(); 49 } 50 51 /** 52 * Attempts to load and execute the external layout. 53 * 54 * @deprecated Use PipelineData version instead. 55 * @param data Turbine information. 56 * @param name Name of object that will execute the layout. 57 * @exception Exception a generic exception. 58 */ 59 @Deprecated 60 @Override 61 public void exec(RunData data, String name) 62 throws Exception 63 { 64 // Execute layout 65 getAssembler(name).build(data); 66 } 67 68 /** 69 * Attempts to load and execute the external layout. 70 * 71 * @param pipelineData Turbine information. 72 * @param name Name of object that will execute the layout. 73 * @exception Exception a generic exception. 74 */ 75 @Override 76 public void exec(PipelineData pipelineData, String name) 77 throws Exception 78 { 79 getAssembler(name).build(pipelineData); 80 } 81 82 /** 83 * Pulls out an instance of the object by name. Name is just the 84 * single name of the object. This is equal to getInstance but 85 * returns an Assembler object and is needed to fulfil the Loader 86 * interface. 87 * 88 * @param name Name of object instance. 89 * @return A Layout with the specified name, or null. 90 * @exception Exception a generic exception. 91 */ 92 public Layout getAssembler(String name) 93 throws Exception 94 { 95 return getAssembler(Layout.NAME, name); 96 } 97 98 /** 99 * @see org.apache.turbine.modules.Loader#getCacheSize() 100 */ 101 public int getCacheSize() 102 { 103 return LayoutLoader.getConfiguredCacheSize(); 104 } 105 106 /** 107 * The method through which this class is accessed. 108 * 109 * @return The single instance of this class. 110 */ 111 public static LayoutLoader getInstance() 112 { 113 return instance; 114 } 115 116 /** 117 * Helper method to get the configured cache size for this module 118 * 119 * @return the configure cache size 120 */ 121 private static int getConfiguredCacheSize() 122 { 123 return Turbine.getConfiguration().getInt(Layout.CACHE_SIZE_KEY, 124 Layout.CACHE_SIZE_DEFAULT); 125 } 126 }