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 1199089 2011-11-08 03:14:28Z 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.
084         *
085         * @param name Name of object instance.
086         * @return An Action with the specified name, or null.
087         * @exception Exception a generic exception.
088         */
089        public Action getAssembler(String name)
090            throws Exception
091        {
092            return getAssembler(Action.class, name);
093        }
094    
095        /**
096         * @see org.apache.turbine.modules.Loader#getCacheSize()
097         */
098        public int getCacheSize()
099        {
100            return ActionLoader.getConfiguredCacheSize();
101        }
102    
103        /**
104         * The method through which this class is accessed.
105         *
106         * @return The single instance of this class.
107         */
108        public static ActionLoader getInstance()
109        {
110            return instance;
111        }
112    
113        /**
114         * Helper method to get the configured cache size for this module
115         *
116         * @return the configure cache size
117         */
118        private static int getConfiguredCacheSize()
119        {
120            return Turbine.getConfiguration().getInt(Action.CACHE_SIZE_KEY,
121                    Action.CACHE_SIZE_DEFAULT);
122        }
123    }