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