    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     * Action 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: ActionLoader.java 1078552 2011-03-06 19:58:46Z tv $
    034     */
    035    public class ActionLoader
    036        extends GenericLoader<Action>
    037        implements Loader<Action>
    038    {
    039        /** The single instance of this class. */
    040        private static ActionLoader instance = new ActionLoader();
    041
    042        /**
    043         * These ctor's are private to force clients to use getInstance()
    044         * to access this class.
    045         */
    046        private ActionLoader()
    047        {
    048            super();
    049        }
    050
    051        /**
    052         * Attempts to load and execute the external action.
    053         * @deprecated Use PipelineData version instead.
    054         * @param data Turbine information.
    055         * @param name Name of object that will execute the action.
    056         * @exception Exception a generic exception.
    057         */
    058        @Deprecated
    059        @Override
    060        public void exec(RunData data, String name)
    061                throws Exception
    062        {
    063            // Execute action
    064            getAssembler(name).perform(data);
    065        }
    066
    067        /**
    068         * Attempts to load and execute the external action.
    069         *
    070         * @param pipelineData Turbine information.
    071         * @param name Name of object that will execute the action.
    072         * @exception Exception a generic exception.
    073         */
    074        @Override
    075        public void exec(PipelineData pipelineData, String name)
    076                    throws Exception
    077        {
    078            getAssembler(name).perform(pipelineData);
    079        }
    080
    081        /**
    082         * Pulls out an instance of the object by name.  Name is just the
    083         * single name of the object. This is equal to getInstance but
    084         * returns an Assembler object and is needed to fulfil the Loader
    085         * interface.
    086         *
    087         * @param name Name of object instance.
    088         * @return An Action with the specified name, or null.
    089         * @exception Exception a generic exception.
    090         */
    091        public Action getAssembler(String name)
    092            throws Exception
    093        {
    094            return getAssembler(Action.NAME, name);
    095        }
    096
    097        /**
    098         * @see org.apache.turbine.modules.Loader#getCacheSize()
    099         */
    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    }