private void checkActionOutputs()

in ti/phase2/jars/core/src/java/org/apache/ti/pageflow/xwork/PageFlowResult.java [418:485]


    private void checkActionOutputs(Forward fwd, PageFlowActionContext actionContext) {
        if (_actionOutputDeclarations == null) {
            return;
        }

        boolean isInProductionMode = AdapterManager.getContainerAdapter().isInProductionMode();
        Map fwdActionOutputs = fwd.getActionOutputs();

        for (Iterator i = _actionOutputDeclarations.values().iterator(); i.hasNext();) {
            ActionOutput actionOutput = (ActionOutput) i.next();

            if (!actionOutput.getNullable() &&
                    ((fwdActionOutputs == null) || (fwdActionOutputs.get(actionOutput.getName()) == null))) {
                FlowController flowController = actionContext.getFlowController();
                FlowControllerException ex = new MissingActionOutputException(flowController, actionOutput.getName(), getName());
                InternalUtils.throwPageFlowException(ex);
            }

            //
            // If we're *not* in production mode, do some (expensive) checks to ensure that the types for the
            // action outputs match their declared types.
            //
            if (!isInProductionMode && (fwdActionOutputs != null)) {
                Object actualActionOutput = fwdActionOutputs.get(actionOutput.getName());

                if (actualActionOutput != null) {
                    String expectedTypeName = actionOutput.getType();
                    int expectedArrayDims = 0;

                    while (expectedTypeName.endsWith("[]")) {
                        ++expectedArrayDims;
                        expectedTypeName = expectedTypeName.substring(0, expectedTypeName.length() - 2);
                    }

                    Class expectedType = (Class) PRIMITIVE_TYPES.get(expectedTypeName);

                    if (expectedType == null) {
                        try {
                            expectedType = Class.forName(expectedTypeName);
                        } catch (ClassNotFoundException e) {
                            _log.error("Could not load expected action output type " + expectedTypeName + " for action output '" +
                                       actionOutput.getName() + "' on forward '" + getName() + "'; skipping type check.");

                            continue;
                        }
                    }

                    Class actualType = actualActionOutput.getClass();
                    int actualArrayDims = 0;
                    InternalStringBuilder arraySuffix = new InternalStringBuilder();

                    while (actualType.isArray() && (actualArrayDims <= expectedArrayDims)) {
                        ++actualArrayDims;
                        arraySuffix.append("[]");
                        actualType = actualType.getComponentType();
                    }

                    if ((actualArrayDims != expectedArrayDims) || !expectedType.isAssignableFrom(actualType)) {
                        FlowController fc = actionContext.getFlowController();
                        FlowControllerException ex = new MismatchedActionOutputException(fc, actionOutput.getName(), getName(),
                                                                                         expectedTypeName,
                                                                                         actualType.getName() + arraySuffix);
                        InternalUtils.throwPageFlowException(ex);
                    }
                }
            }
        }
    }