Package org.strecks.action.navigable

Source Code of org.strecks.action.navigable.NavigableLookupDispatchController

/*
* Copyright 2005-2006 the original author or authors.
*
* 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 org.strecks.action.navigable;

import java.lang.reflect.Method;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.strecks.action.NavigableSubmitAction;
import org.strecks.action.basic.BasicLookupDispatchController;
import org.strecks.context.ActionContext;
import org.strecks.controller.NavigableControllerAction;
import org.strecks.controller.annotation.ActionInterface;
import org.strecks.dispatch.annotation.ReadDispatchLookups;
import org.strecks.form.controller.BindingForm;
import org.strecks.navigate.NavigateUtils;
import org.strecks.navigate.NavigationHolder;
import org.strecks.navigate.annotation.ReadNavigation;
import org.strecks.util.ReflectHelper;
import org.strecks.view.ViewAdapter;

/**
* Form-submit action controller which mimics the behaviour of <code>LookupDispatchAction</code>. Internally,
* actually uses an instance of <code>LookupDispatchAction</code> to do the complex stuff of finding the method name
* to execute for a possibly locale variant key. Action beans which use this controller must implement the
* <code>NavigableSubmitAction</code> interface
* @see org.strecks.action.NavigableSubmitAction
* @author Phil Zoio
*/
@ActionInterface(name = NavigableSubmitAction.class)
@ReadDispatchLookups
@ReadNavigation
public class NavigableLookupDispatchController extends BasicLookupDispatchController
    implements
      NavigableControllerAction
{

  private NavigationHolder navigationHolder;

  /* *********************** NavigableControllerAction methods ************************ */

  public NavigableLookupDispatchController()
  {
    super();
  }

  public void setNavigationHolder(NavigationHolder holder)
  {
    this.navigationHolder = holder;
  }

  public NavigationHolder getNavigationHolder()
  {
    return navigationHolder;
  }

  @Override
  protected ViewAdapter executeAction(Object actionBean, ActionContext context)
  {

    NavigableSubmitAction action = (NavigableSubmitAction) actionBean;

    ActionForm form = context.getForm();

    HttpServletRequest request = context.getRequest();

    boolean cancelled = false;
    if (request.getAttribute(Globals.CANCEL_KEY) != null)
    {
      cancelled = true;
    }

    if (form instanceof BindingForm && !cancelled)
    {

      action.preBind();
      BindingForm validBindingForm = (BindingForm) form;
      validBindingForm.bindInwards(actionBean);

    }

    ActionMapping mapping = context.getMapping();

    if (cancelled)
    {
      action.cancel();
    }
    else
    {

      // now figure out what method to execute and do so

      String parameterName = mapping.getParameter();

      getHelper().checkParameterName(mapping, parameterName);

      String methodName = getMethodName(context, parameterName);

      if (methodName == null)
      {
        action.execute();
      }
      else
      {
        Method method = getHelper().getMethod(actionBean, methodName);
        ReflectHelper.invokeMethod(actionBean, method, String.class);
      }

    }

    return NavigateUtils.findActionForward(navigationHolder, actionBean, context);

  }

  @Override
  protected Map<String, String> internalGetKeyMethodMap()
  {
    return super.internalGetKeyMethodMap();
  }

}
TOP

Related Classes of org.strecks.action.navigable.NavigableLookupDispatchController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.