Package jodd.madvoc.result

Examples of jodd.madvoc.result.ActionResult


   *
   * @see ActionResult#render(jodd.madvoc.ActionRequest, Object)
   */
  @SuppressWarnings("unchecked")
  public void render(ActionRequest actionRequest, Object resultObject) throws Exception {
    ActionResult actionResult;

    // [1] try to lookup the result class

    Class<? extends ActionResult> actionResultClass = null;

    if (resultObject != null && resultObject.getClass() != String.class) {
      // try annotation
      RenderWith renderWith = resultObject.getClass().getAnnotation(RenderWith.class);
      if (renderWith != null) {
        actionResultClass = renderWith.value();
      }
    } else if (resultObject == null) {
      Result result = actionRequest.getResult();
      if (result != null) {
        actionResultClass = result.getActionResult();
        resultObject = result.getResultValue();
        if (resultObject == null) {
          resultObject = result.value();
        }
      }
    }

    if (actionResultClass != null) {
      // result class is known, lookup the action result type
      actionResult = resultsManager.lookup(actionResultClass);

      if (actionResult == null) {
        // register action result if by any chance it wasn't registered yet
        actionResult = resultsManager.register(actionResultClass);
      }

    } else {
      // result class is not known, lookup it from returned string
      String resultValue = resultObject != null ? resultObject.toString() : null;
      String resultType = null;

      // first check result value
      if (resultValue != null) {
        int columnIndex = resultValue.indexOf(':');

        if (columnIndex != -1) {
          resultType = resultValue.substring(0, columnIndex);

          resultValue = resultValue.substring(columnIndex + 1);
        }
      }

      // result type still not defined, use default
      if (resultType == null) {
        resultType = madvocConfig.getDefaultResultType();
      }

      actionResult = resultsManager.lookup(resultType);
      if (actionResult == null) {
        throw new MadvocException("Action result not found: " + resultType);
      }

      // convert remaining of the string to result object
      try {
        Class targetClass = actionResult.getResultValueType();
        if (targetClass == String.class) {
          resultObject = resultValue;
        } else {
          resultObject = TypeConverterManager.convertType(resultValue, targetClass);
        }
      } catch (Exception ex) {
        resultObject = resultValue;
      }
    }

    // finally, invoke result
    if (madvocConfig.isPreventCaching()) {
      ServletUtil.preventCaching(actionRequest.getHttpServletResponse());
    }

    actionResult.render(actionRequest, resultObject);
  }
View Full Code Here


    String resultType = result.getResultType();

    boolean existingResult = false;

    if (resultType != null) {
      ActionResult existing = lookup(resultType);
      if (existing != null) {
        Class<? extends ActionResult> resultClass = result.getClass();
        Class<? extends ActionResult> existingClass = existing.getClass();
        if (existingClass.equals(resultClass) == false) {
          // existing class is different from current class
          if (resultClass.getPackage().equals(ActionResult.class.getPackage())) {
            Class<? extends ActionResult> temp = existingClass;
            existingClass = resultClass;
View Full Code Here

   *
   * @see ActionResult#render(jodd.madvoc.ActionRequest, Object)
   */
  @SuppressWarnings("unchecked")
  public void render(ActionRequest actionRequest, Object resultObject) throws Exception {
    ActionResult actionResult = resultsManager.lookup(actionRequest, resultObject);

    if (actionResult == null) {
      throw new MadvocException("Action result not found");
    }

    if (madvocConfig.isPreventCaching()) {
      ServletUtil.preventCaching(actionRequest.getHttpServletResponse());
    }

    actionResult.render(actionRequest, actionRequest.getActionResult());
  }
View Full Code Here

  protected ActionResult register(ActionResult result) {
    Class<? extends ActionResult> actionResultClass = result.getClass();

    // check existing

    ActionResult existingResult = allResults.get(actionResultClass);

    if (existingResult != null) {
      if (log.isDebugEnabled()) {
        log.debug("ActionResult already registered: " + actionResultClass);
      }
      return existingResult;
    }

    // + string hook

    String resultName = result.getResultName();

    if (resultName != null) {
      existingResult = stringResults.get(resultName);

      if (existingResult != null) {
        // the same result name exist
        if (!resultMayReplaceExistingOne(actionResultClass)) {
          if (log.isDebugEnabled()) {
            log.debug("ActionResult already registered: " + actionResultClass);
          }
          return existingResult;
        }

        // allow only one action result per result type
        allResults.remove(existingResult.getClass());
      }

      if (log.isInfoEnabled()) {
        log.debug("ActionResult registered: " + resultName + " -> " + actionResultClass);
      }

      stringResults.put(resultName, result);
    }

    // + type result

    Class resultValueType = result.getResultValueType();

    if (resultValueType != null && resultValueType != String.class) {
      existingResult = typeResults.get(resultValueType);

      if (existingResult != null) {
        if (!resultMayReplaceExistingOne(actionResultClass)) {
          if (log.isDebugEnabled()) {
            log.debug("ActionResult already registered: " + actionResultClass);
          }
          return existingResult;
        }

        // allow only one action result per result type
        allResults.remove(existingResult.getClass());
      }

      if (log.isInfoEnabled()) {
        log.debug("ActionResult registered: " + resultValueType + " -> " + actionResultClass);
      }
View Full Code Here

  /**
   * Lookups for action result and {@link #register(Class) registers} it if missing.
   */
  private ActionResult lookupAndRegisterIfMissing(Class<? extends ActionResult> actionResultClass) {
    ActionResult actionResult = allResults.get(actionResultClass);

    if (actionResult == null) {
      actionResult = register(actionResultClass);
    }

View Full Code Here

   *     <li>if result is not a <code>String</code>, find ActionResult for matching result object type</li>
   *     <li>if action result still not found, call <code>toString</code> on result object and parse it</li>
   * </ul>
   */
  public ActionResult lookup(ActionRequest actionRequest, Object resultObject) {
    ActionResult actionResult = null;

    // + special class: result
    if (resultObject == null) {
      Result result = actionRequest.getResult();

      if (result != null) {
        // read Result, if used; if not, values will be null
        Class<? extends ActionResult> actionResultClass = result.getActionResult();

        resultObject = result.getResultValue();
        if (resultObject == null) {
          resultObject = result.value();
        }

        if (actionResultClass != null) {
          actionResult = lookupAndRegisterIfMissing(actionResultClass);
        }
      }
    }

    if (actionResult == null) {
      // + still not found, read @Action value
      ActionConfig actionConfig = actionRequest.getActionConfig();

      Class<? extends ActionResult> actionResultClass = actionConfig.getActionResult();
      if (actionResultClass != null) {
        actionResult = lookupAndRegisterIfMissing(actionResultClass);
      }
    }

    if (actionResult == null && resultObject != null) {
      Class resultType = resultObject.getClass();

      if (resultType != String.class) {
        // + still not found, read @RenderWith value if exist
        RenderWith renderWith = resultObject.getClass().getAnnotation(RenderWith.class);

        if (renderWith != null) {
          actionResult = lookupAndRegisterIfMissing(renderWith.value());
        }

        if (actionResult == null) {
          // + still not found, lookup for type
          actionResult = typeResults.get(resultObject.getClass());
        }
      }
    }

    if (actionResult == null) {
      // + still not found, toString()

      ActionResult defaultActionResult = lookupAndRegisterIfMissing(madvocConfig.getDefaultActionResult());

      if (stringResults.isEmpty()) {
        // no string results registered, carry on with the defaults.
        actionResult = defaultActionResult;
      }
View Full Code Here

TOP

Related Classes of jodd.madvoc.result.ActionResult

Copyright © 2018 www.massapicom. 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.