001 package org.apache.turbine.modules; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.turbine.Turbine; 023 import org.apache.turbine.pipeline.PipelineData; 024 import org.apache.turbine.util.RunData; 025 026 /** 027 * The purpose of this class is to allow one to load and execute 028 * Layout modules. 029 * 030 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 031 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 032 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 033 * @version $Id: LayoutLoader.java 1078552 2011-03-06 19:58:46Z tv $ 034 */ 035 public class LayoutLoader 036 extends GenericLoader<Layout> 037 implements Loader<Layout> 038 { 039 /** The single instance of this class. */ 040 private static LayoutLoader instance = new LayoutLoader(); 041 042 /** 043 * These ctor's are private to force clients to use getInstance() 044 * to access this class. 045 */ 046 private LayoutLoader() 047 { 048 super(); 049 } 050 051 /** 052 * Attempts to load and execute the external layout. 053 * 054 * @deprecated Use PipelineData version instead. 055 * @param data Turbine information. 056 * @param name Name of object that will execute the layout. 057 * @exception Exception a generic exception. 058 */ 059 @Deprecated 060 @Override 061 public void exec(RunData data, String name) 062 throws Exception 063 { 064 // Execute layout 065 getAssembler(name).build(data); 066 } 067 068 /** 069 * Attempts to load and execute the external layout. 070 * 071 * @param pipelineData Turbine information. 072 * @param name Name of object that will execute the layout. 073 * @exception Exception a generic exception. 074 */ 075 @Override 076 public void exec(PipelineData pipelineData, String name) 077 throws Exception 078 { 079 getAssembler(name).build(pipelineData); 080 } 081 082 /** 083 * Pulls out an instance of the object by name. Name is just the 084 * single name of the object. This is equal to getInstance but 085 * returns an Assembler object and is needed to fulfil the Loader 086 * interface. 087 * 088 * @param name Name of object instance. 089 * @return A Layout with the specified name, or null. 090 * @exception Exception a generic exception. 091 */ 092 public Layout getAssembler(String name) 093 throws Exception 094 { 095 return getAssembler(Layout.NAME, name); 096 } 097 098 /** 099 * @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 }