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.tiles.TilesRequestProcessor;
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.  Use this class if
021     * you are using the Tiles library.  If not, you can use the {@link org.nanocontainer.nanowar.sample.struts.PicoRequestProcessor}
022     * instead.
023     *
024     * @author Stephen Molitor
025     * @see ActionFactory
026     * @see org.nanocontainer.nanowar.sample.struts.PicoRequestProcessor
027     */
028    public class PicoTilesRequestProcessor extends TilesRequestProcessor {
029    
030        private final ActionFactory actionFactory = new ActionFactory();
031    
032        /**
033         * Creates or retrieves the action instance.  The action is retrieved from the actions
034         * Pico container, using the mapping path as the component key.  If no such action exists,
035         * a new one will be instantiated and placed in the actions container, thus injecting
036         * its dependencies.
037         *
038         * @param request  the HTTP request object.
039         * @param response the HTTP response object.
040         * @param mapping  the action mapping.
041         * @return the action instance.
042         */
043        protected Action processActionCreate(HttpServletRequest request,
044                                             HttpServletResponse response,
045                                             ActionMapping mapping) throws IOException {
046            return actionFactory.getAction(request, mapping, servlet);
047        }
048    
049    }