private void populateWithSessionTools()

in src/java/org/apache/turbine/services/pull/TurbinePullService.java [524:594]


    private void populateWithSessionTools(List<ToolData> tools, Context context,
            RunData data, User user)
    {
        // Iterate the tools
        for (ToolData toolData : tools)
        {
            try
            {
                // ensure that tool is created only once for a user
                // by synchronizing against the user object
                synchronized (data.getSession())
                {
                    // first try and fetch the tool from the user's
                    // hashmap
                    Object tool = data.getSession().getAttribute(
                            SESSION_TOOLS_ATTRIBUTE_PREFIX
                            + toolData.toolClassName);

                    if (tool == null)
                    {
                        // if not there, an instance must be fetched from
                        // the pool
                        tool = pool.getInstance(toolData.toolClass);

                        // session tools are init'd with the User object
                        initTool(tool, user);
                    }

                    // *NOT* else
                    if(tool != null)
                    {
                        // store the newly created tool in the session
                        data.getSession().setAttribute(
                                SESSION_TOOLS_ATTRIBUTE_PREFIX
                                + tool.getClass().getName(), tool);

                        // This is a semantics change. In the old
                        // Turbine, Session tools were initialized and
                        // then refreshed every time they were pulled
                        // into the context if "refreshToolsPerRequest"
                        // was wanted.
                        //
                        // RunDataApplicationTools now have a parameter
                        // for refresh. If it is not refreshed immediately
                        // after init(), the parameter value will be undefined
                        // until the 2nd run. So we refresh all the session
                        // tools on every run, even if we just init'ed it.
                        //

                        if (refreshToolsPerRequest)
                        {
                            refreshTool(tool, data);
                        }

                        // put the tool in the context
                        log.debug("Adding {} to ctx as {}", tool, toolData.toolName);
                        context.put(toolData.toolName, tool);
                    }
                    else
                    {
                        log.info("Tool {} was null, skipping it.", toolData.toolName);
                    }
                }
            }
            catch (Exception e)
            {
                log.error("Could not instantiate session tool {} from a {} object",
                        toolData.toolName, toolData.toolClassName, e);
            }
        }
    }