class EngineContextManager {


    static IEngineContext prepareEngineContext(
            final IEngineConfiguration configuration,
            final TemplateData templateData, final Map<String, Object> templateResolutionAttributes,
            final IContext context) {

        final IEngineContext engineContext =
                createEngineContextIfNeeded(configuration, templateData, templateResolutionAttributes, context);

        // We will always do this, even if the context is a new object (in which case it would be completely needed)
        // because we want to make sure the 'disposeEngineContext' call that will come afterwards can safely
        // decrease the level
        engineContext.increaseLevel();

        if (context instanceof IEngineContext) {
            // Set the template resolution into the context, but only if we haven't just created it
            engineContext.setTemplateData(templateData);
        }

        return engineContext;

    }


    static void disposeEngineContext(final IEngineContext engineContext) {
        engineContext.decreaseLevel();
    }




    private static IEngineContext createEngineContextIfNeeded(
            final IEngineConfiguration configuration,
            final TemplateData templateData, final Map<String, Object> templateResolutionAttributes,
            final IContext context) {<FILL_FUNCTION_BODY>}



    private EngineContextManager() {
        super();
    }


}


        if (context instanceof IEngineContext) {
            // If this context is already an IEngineContext, we will not clone it
            return (IEngineContext) context;
        }

        // It's the engine context factory the one who has the responsibility of creating the specific
        // implementation of the engine context needed.
        final IEngineContextFactory engineContextFactory = configuration.getEngineContextFactory();
        return engineContextFactory.createEngineContext(
                configuration, templateData, templateResolutionAttributes, context);

    
<no_super_class>