/*
 * Copyright 2011 FatWire Corporation. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fatwire.gst.foundation.groovy.context;

import javax.servlet.ServletContext;

import COM.FutureTense.Interfaces.ICS;

import com.fatwire.gst.foundation.controller.AppContext;
import com.fatwire.gst.foundation.controller.action.Action;
import com.fatwire.gst.foundation.controller.action.ActionLocator;
import com.fatwire.gst.foundation.controller.action.Injector;
import com.fatwire.gst.foundation.controller.action.RenderPage;
import com.fatwire.gst.foundation.controller.action.support.AbstractActionLocator;
import com.fatwire.gst.foundation.controller.action.support.ClassActionLocator;
import com.fatwire.gst.foundation.controller.action.support.DefaultWebAppContext;
import com.fatwire.gst.foundation.controller.support.WebAppContextLoader;
import com.fatwire.gst.foundation.groovy.spring.GroovyActionLocator;
import com.fatwire.gst.foundation.groovy.spring.GroovyLoader;

public class GroovyWebContext extends DefaultWebAppContext {
    /**
     * This constructor is needed for the {@link WebAppContextLoader}. 
     * 
     * @param ctx
     * @param app
     */
    public GroovyWebContext(ServletContext context, AppContext app) {
        super(context,app);
    }

    public ActionLocator createActionLocator() {
        // this method is expected to be called only once during the lifecycle
        // of the web app context, though more often does not need to be a
        // problem per se.

        // set up a chain of action locators
        // at the root level (if everything else fails), return a ActionLocator
        // that returns a RenderPage
        Injector injector = getBean("injector", Injector.class);
        ActionLocator root = getRootActionLocator();

        GroovyLoader loader = new GroovyLoader(getServletContext());
        // next, set the groovy action loader
        GroovyActionLocator l = new GroovyActionLocator(root, injector);
        l.setGroovyLoader(loader);
        // and at last the class:<classname> loader
        final ClassActionLocator cal = new ClassActionLocator(l, injector);
        return cal;

    }

    protected ActionLocator getRootActionLocator() {
        Injector injector = getBean("injector", Injector.class);
        AbstractActionLocator a = new AbstractActionLocator(injector) {

            @Override
            protected Action doFindAction(ICS ics, String name) {
                RenderPage rp = new RenderPage();
                return rp;
            }

        };
        return a;
    }
}

@@ -730,50 +730,8 @@
 %0D%0A%0D%0A
-import COM.FutureTense.Interfaces.ICS;%0D%0A%0D%0A
 impo
@@ -788,69 +788,8 @@
 t;%0D%0A
-import com.fatwire.gst.foundation.controller.action.Action;%0D%0A
 impo
@@ -919,157 +919,8 @@
 r;%0D%0A
-import com.fatwire.gst.foundation.controller.action.RenderPage;%0D%0Aimport com.fatwire.gst.foundation.controller.action.support.AbstractActionLocator;%0D%0A
 impo
@@ -1071,32 +1071,118 @@
 WebAppContext;%0D%0A
+import com.fatwire.gst.foundation.controller.action.support.RenderPageActionLocator;%0D%0A
 import com.fatwi
@@ -1516,17 +1516,16 @@
 Loader%7D.
- 
 %0D%0A     *
@@ -1667,16 +1667,17 @@
 context,
+ 
 app);%0D%0A 
@@ -2201,16 +2201,24 @@
 Locator(
+injector
 );%0D%0A%0D%0A  
@@ -2645,32 +2645,49 @@
 otActionLocator(
+Injector injector
 ) %7B%0D%0A        Inj
@@ -2675,32 +2675,34 @@
 tor) %7B%0D%0A        
+//
 Injector injecto
@@ -2755,289 +2755,52 @@
     
-AbstractActionLocator a = new AbstractActionLocator(injector) %7B%0D%0A%0D%0A            @Override%0D%0A            protected Action doFindAction(ICS ics, String name) %7B%0D%0A                RenderPage rp = new RenderPage();%0D%0A                return rp;%0D%0A            %7D%0D%0A%0D%0A        %7D;%0D%0A        return a
+return new RenderPageActionLocator(injector)
 ;%0D%0A 

Replace anonymous ActionLocator class with RenderPageActionLocator