View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
    10   *   http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19
    20  package org.apache.myfaces.orchestra.viewController;
    21
    22  import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
    23
    24  /**
    25   * A partial implementation of the ViewControllerManager interface which
    26   * allows subclasses to just implement two simple abstract methods in order
    27   * to provide a fully functional ViewControllerManager implementation.
    28   * <p>
    29   * This implementation splits responsibility for invoking view lifecycle
    30   * events into three parts:
    31   * <ul>
    32   * <li>A "name mapper" that maps a view identifier to a bean name
    33   * <li>An "executor" that decides which methods on a bean to invoke, and
    34   * <li>A controller that invokes the mapper and executor.
    35   * </ul>
    36   * This class implements the "controller" bit itself, and leaves subclasses
    37   * to just choose the "name mapper" and "executor" to use by overriding
    38   * the abstract methods defined here.
    39   */
    40  public abstract class AbstractViewControllerManager implements ViewControllerManager
    41  {
    42      protected abstract ViewControllerNameMapper getViewControllerNameMapper();
    43      protected abstract ViewControllerExecutor getViewControllerExecutor();
    44
    45      public String getViewControllerName(String viewId)
    46      {
    47          ViewControllerNameMapper nameMapper = getViewControllerNameMapper();
    48          return nameMapper.mapViewId(viewId);
    49      }
    50
    51      public Object getViewController(String viewId)
    52      {
    53          String beanName = getViewControllerName(viewId);
    54          if (beanName == null)
    55          {
    56              return null;
    57          }
    58
    59          return FrameworkAdapter.getCurrentInstance().getBean(beanName);
    60      }
    61
    62      public void assertConversationState(String viewId)
    63      {
    64      }
    65
    66      public void executeInitView(String viewId)
    67      {
    68          String beanName = getViewControllerNameMapper().mapViewId(viewId);
    69          Object viewController = getViewController(viewId);
    70          if (viewController != null)
    71          {
    72              getViewControllerExecutor().invokeInitView(beanName, viewController);
    73          }
    74      }
    75
    76      public void executePreProcess(String viewId)
    77      {
    78          String beanName = getViewControllerNameMapper().mapViewId(viewId);
    79          Object viewController = getViewController(viewId);
    80          if (viewController != null)
    81          {
    82              getViewControllerExecutor().invokePreProcess(beanName, viewController);
    83          }
    84      }
    85
    86      public void executePreRenderView(String viewId)
    87      {
    88          String beanName = getViewControllerNameMapper().mapViewId(viewId);
    89          Object viewController = getViewController(viewId);
    90          if (viewController != null)
    91          {
    92              getViewControllerExecutor().invokePreRenderView(beanName, viewController);
    93          }
    94      }
    95  }