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