public static function &getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new __ViewResolver();
     }
     return self::$_instance;
 }
 public function &createEventHandler($view_code)
 {
     $return_value = null;
     $view = __ViewResolver::getInstance()->getView($view_code);
     $event_handler_class = $view->getEventHandlerClass();
     if ($event_handler_class != null) {
         $return_value = new $event_handler_class();
         if ($return_value instanceof __IEventHandler) {
             $return_value->setViewCode($view_code);
         } else {
             throw __ExceptionFactory::getInstance()->createException('Wrong event handler class: ' . $event_handler_class . '. Must implement the __IEventHandler interface.');
         }
     }
     return $return_value;
 }
 /**
  * Dispatch an action. If the action code is not specified, it will be used the default (ACTION_CODE_ON_ACTION_NOT_SPECIFIED).
  * 
  * If the default one does not correspond with any action controller method (remember that the method name is the action code 
  * with the suffix 'Action'), the ACTION_CODE_ON_ACTION_NOT_FOUND will be used instead of.<br>
  * <br>
  * The dispatch method, once has the action controller, performes the following tasks:<br>
  * <p>1. Call to {@link __ActionController::preProcess} method in order to execute a 'pre-logic' before the execution of the action controller logic (i.e. check preconditions, execute another action, ...)<br>
  * <p>2. Call to the action method in order to execute the action logic. The action method should return a {@link __ModelAndView} instance.
  *    In that case, the __ActionDispatcher will resolve a {@link __View} and will execute it (by calling to the {@link __View::execute} method).<br>
  * <p>3. Finally, call to {@link __ActionController::postProcess} method in order to execute a 'post-logic' (i.e. check postconditions, execute another action, ...)<br>
  * <br>
  * The {@link preProcess} and {@link postProcess} methods can be specialized in subclasses in order to define concrete actions and behaviors.<br>
  * 
  *
  * @param string $action_controller The action controller code (aka the module code)
  * @param string $action_code The action to execute.
  * @param __IRequest &$request The request
  * @param __IResponse &$response The response
  * @return mixed The response or the value returned by the controller if it's not a {@link __ModelAndView}
  */
 public function &dispatch(__ActionIdentity $action_identity, __IRequest &$request = null, __IResponse &$response = null)
 {
     $return_value =& $response;
     //by default we'll return the response
     $this->_pushRequest($request);
     $this->_pushResponse($response);
     $this->_pushActionIdentity($action_identity);
     //get the __ActionController class:
     $controller_code = $action_identity->getControllerCode();
     $action_code = $action_identity->getActionCode();
     $action_controller = __ActionControllerResolver::getInstance()->getActionController($controller_code);
     if ($action_controller instanceof __IActionController) {
         $resource_manager = __ApplicationContext::getInstance()->getResourceManager();
         $action_controller_I18n_resources = $resource_manager->loadActionResources($action_identity);
         $front_controller_request = __FrontController::getInstance()->getRequest();
         if ($front_controller_request != null) {
             $valid_request_method = $action_controller->getValidRequestMethod();
             if (($valid_request_method & $front_controller_request->getMethod()) == 0) {
                 throw __ExceptionFactory::getInstance()->createException('ERR_INVALID_REQUEST_METHOD', array($action_identity->getControllerCode()));
             }
         }
         //1. Execute the action's pre-logic:
         $action_controller->preExecute();
         //2. Execute the action logic:
         $controller_result = $action_controller->execute($action_code);
         if ($controller_result instanceof __ModelAndView) {
             $view = $controller_result->getView();
             if ($view == null) {
                 $view_code = $controller_result->getViewCode();
                 if ($view_code == null) {
                     $view_code = $action_code ? $action_code : $controller_code;
                 }
                 $view = __ViewResolver::getInstance()->getView($view_code);
             }
             if ($view instanceof __View) {
                 $model = $controller_result->getModel();
                 //assign the model
                 $view->assign($model->toArray());
                 //assign I18n resources
                 $view->assign($action_controller_I18n_resources);
                 $response = $this->getResponse();
                 $response->appendContent($view->execute());
             }
         } else {
             $return_value =& $controller_result;
         }
         //3. Finally will execute the action's post-logic:
         $action_controller->postExecute();
     }
     $this->_popActionIdentity();
     $this->_popResponse();
     $this->_popRequest();
     return $return_value;
 }