001package 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 022import org.apache.turbine.Turbine; 023import org.apache.turbine.pipeline.PipelineData; 024 025/** 026 * The purpose of this class is to allow one to load and execute 027 * Action modules. 028 * 029 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 030 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 031 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 032 * @version $Id: ActionLoader.java 1773378 2016-12-09 13:19:59Z tv $ 033 */ 034public class ActionLoader 035 extends GenericLoader<Action> 036 implements Loader<Action> 037{ 038 /** The single instance of this class. */ 039 private static ActionLoader instance = new ActionLoader(); 040 041 /** 042 * These ctor's are private to force clients to use getInstance() 043 * to access this class. 044 */ 045 private ActionLoader() 046 { 047 super(); 048 } 049 050 /** 051 * Attempts to load and execute the external action. 052 * 053 * @param pipelineData Turbine information. 054 * @param name Name of object that will execute the action. 055 * @throws Exception a generic exception. 056 */ 057 @Override 058 public void exec(PipelineData pipelineData, String name) 059 throws Exception 060 { 061 getAssembler(name).perform(pipelineData); 062 } 063 064 /** 065 * Pulls out an instance of the object by name. Name is just the 066 * single name of the object. 067 * 068 * @param name Name of object instance. 069 * @return An Action with the specified name, or null. 070 * @throws Exception a generic exception. 071 */ 072 @Override 073 public Action getAssembler(String name) 074 throws Exception 075 { 076 return getAssembler(Action.class, name); 077 } 078 079 /** 080 * @see org.apache.turbine.modules.Loader#getCacheSize() 081 */ 082 @Override 083 public int getCacheSize() 084 { 085 return ActionLoader.getConfiguredCacheSize(); 086 } 087 088 /** 089 * The method through which this class is accessed. 090 * 091 * @return The single instance of this class. 092 */ 093 public static ActionLoader getInstance() 094 { 095 return instance; 096 } 097 098 /** 099 * 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(Action.CACHE_SIZE_KEY, 106 Action.CACHE_SIZE_DEFAULT); 107 } 108}