/** * Registers an action result handler and returns created {@link jodd.madvoc.result.ActionResult} if * result with same type doesn't exist. Otherwise, returns existing result and created one will be ignored. */ public ActionResult register(final Class<? extends ActionResult> resultClass) { return register(createResult(resultClass)); }
/** * Collects all action results. */ protected void collectActionResults() { final Collection<ActionResult> resultsValues = resultsManager.getAllActionResults(); results = new ArrayList<>(); results.addAll(resultsValues); results.sort(Comparator.comparing(a -> a.getClass().getSimpleName())); }
/** * Registers an action result handler and returns created {@link jodd.madvoc.result.ActionResult} if * result with same type doesn't exist. Otherwise, returns existing result and created one will be ignored. */ public ActionResult register(Class<? extends ActionResult> resultClass) { ActionResult result = createResult(resultClass); ActionResult existing = lookup(result.getType()); if (existing != null) { if (existing.getClass().equals(resultClass) == false) { throw new MadvocException("Madvoc result with the same result type '" + result.getType() + "' already registered: '" + resultClass.getSimpleName() + "'."); } result = existing; } else { results.put(result.getType(), result); } return result; }
/** * Lookups for action result and {@link #register(Class) registers} it if missing. */ private ActionResult lookupAndRegisterIfMissing(final Class<? extends ActionResult> actionResultClass) { ActionResult actionResult = allResults.get(actionResultClass); if (actionResult == null) { actionResult = register(actionResultClass); } return actionResult; }
/** * Invokes a result after the action invocation. * <p> * Results may be objects that specify which action result will be used * to render the result. * <p> * Result value may consist of two parts: type and value. Result type is optional and, if exists, it is separated * by semi-colon from the value. If type is not specified * then the default result type if still not defined. Result type defines which * {@link ActionResult} should be used for rendering the value. * <p> * Result value is first checked against aliased values. Then, it is resolved and then passed * to the founded {@link ActionResult}. * * @see ActionResult#render(jodd.madvoc.ActionRequest, Object) */ @SuppressWarnings("unchecked") public void render(final ActionRequest actionRequest, final Object resultObject) throws Exception { final ActionResult actionResult = resultsManager.lookup(actionRequest, resultObject); if (actionResult == null) { throw new MadvocException("Action result not found"); } if (preventCaching) { ServletUtil.preventCaching(actionRequest.getHttpServletResponse()); } log.debug(() -> "Result type: " + actionResult.getClass().getSimpleName()); actionResult.render(actionRequest, actionRequest.getActionResult()); }
actionResultHandler = lookupAndRegisterIfMissing(actionResultClass); actionResultHandler = lookupAndRegisterIfMissing(renderWith.value()); actionResultHandler = lookupAndRegisterIfMissing(actionResultClass);
/** * Registers new action result instance. If action result of the same class is already * registered, registration will be skipped. If result for the same result type or * same target class exist, it will be replaced! However, default Jodd results will * <i>never</i> replace other results. After the registration, results are initialized. */ protected ActionResult register(final 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; } allResults.put(actionResultClass, result); // + init initializeResult(result); return result; }
/** * Loads madvoc result from founded {@link jodd.madvoc.result.ActionResult} instance. */ @SuppressWarnings({"unchecked"}) protected void onResultClass(String className) throws ClassNotFoundException { Class resultClass = ClassLoaderUtil.loadClass(className); if (resultClass.equals(ActionResult.class)) { return; } if (ReflectUtil.isSubclass(resultClass, ActionResult.class) == true) { resultsManager.register(resultClass); } }
ActionResult result = resultsManager.lookup(resultType); if (result == null) { throw new MadvocException("Unable to find action result type: " + resultType);
protected void collectActionResults() { Collection<ActionResult> resultsValues = resultsManager.getAllActionResults().values(); results = new ArrayList<ActionResult>(); results.addAll(resultsValues); Collections.sort(results, new Comparator<ActionResult>() { public int compare(ActionResult a1, ActionResult a2) { return a1.getType().compareTo(a2.getType()); } }); }