001    /*******************************************************************************
002     * Copyright (C) PicoContainer Organization. All rights reserved. 
003     * ---------------------------------------------------------------------------
004     * The software in this package is published under the terms of the BSD style
005     * license a copy of which has been included with this distribution in the
006     * LICENSE.txt file.
007     ******************************************************************************/
008    package org.picocontainer.web.struts;
009    
010    import javax.servlet.http.HttpServletRequest;
011    import javax.servlet.http.HttpServletResponse;
012    
013    import org.apache.struts.action.Action;
014    import org.apache.struts.action.ActionMapping;
015    import org.apache.struts.action.RequestProcessor;
016    
017    /**
018     * Uses Pico to produce Actions and inject dependencies into them. If you are
019     * using the Tiles library, use {@link PicoTilesRequestProcessor} instead.
020     * 
021     * @author Stephen Molitor
022     * @see PicoActionFactory
023     * @see PicoTilesRequestProcessor
024     */
025    public class PicoRequestProcessor extends RequestProcessor {
026    
027        private final PicoActionFactory actionFactory = new PicoActionFactory();
028    
029        /**
030         * Creates or retrieves the action instance. The action is retrieved from
031         * the actions Pico container, using the mapping path as the component key.
032         * If no such action exists, a new one will be instantiated and placed in
033         * the actions container, thus injecting its dependencies.
034         * 
035         * @param request the HTTP request object.
036         * @param response the HTTP response object.
037         * @param mapping the action mapping.
038         * @return the action instance.
039         */
040        protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {
041            return actionFactory.getAction(request, mapping, this.servlet);
042        }
043    
044    }