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  /**
    23   * A {@link org.apache.myfaces.orchestra.viewController.ViewControllerManager} implementation which uses
    24   * annotations on backing beans to determine the beans responsible for a given view and execute
    25   * the appropriate annotated methods.
    26   *
    27   * <p>When using Spring, every bean declaration in the spring config files is checked to see if the
    28   * referenced class has annotations, and if so that information is cached. Here, that information is
    29   * then used to locate a bean which has a ViewController annotation that references the current view.</p>
    30   *
    31   * <p>See also org.apache.myfaces.orchestra.viewController.annotations.*.</p>
    32   *
    33   * <p>
    34   * Notice: For backward compatiblity with the Orchestra-core module this ViewControllerManager
    35   * will take the Orchestra-core naming strategy
    36   * into account and uses reflection if no annotated method were found.
    37   * </p>
    38   *
    39   * @see org.apache.myfaces.orchestra.viewController.ViewControllerManager
    40   * @see org.apache.myfaces.orchestra.viewController.PlainAnnotationsViewControllerManager
    41   */
    42  public class AnnotationsViewControllerManager extends AbstractAnnotationsViewControllerManager
    43  {
    44      private ViewControllerNameMapper viewControllerNameMapper;
    45      private ViewControllerExecutor viewControllerExecutor;
    46
    47      public AnnotationsViewControllerManager()
    48      {
    49      }
    50
    51      public void initManager()
    52      {
    53          // Set things up so that finding a bean-name for a viewId looks first using an
    54          // AnnotationsViewControllerNameMapper, then a DefaultViewControllerNameMapper.
    55          viewControllerNameMapper =
    56              new CompositeViewControllerNameMapper(
    57                  new ViewControllerNameMapper[]
    58                      {
    59                          new AnnotationsViewControllerNameMapper(getAnnotationInfoManager()),
    60                          new DefaultViewControllerNameMapper()
    61                      });
    62
    63          // Set things up so that executing a method first using an
    64          // AnnotationsViewControllerExecutor, then a ReflectiveViewControllerExecutor.
    65          viewControllerExecutor =
    66              new CompositeViewControllerExecutor(
    67                  new ViewControllerExecutor[]
    68                      {
    69                          new AnnotationsViewControllerExecutor(getAnnotationInfoManager()),
    70                          new ReflectiveViewControllerExecutor()
    71                      });
    72      }
    73
    74      protected ViewControllerNameMapper getViewControllerNameMapper()
    75      {
    76          return viewControllerNameMapper;
    77      }
    78
    79      protected ViewControllerExecutor getViewControllerExecutor()
    80      {
    81          return viewControllerExecutor;
    82      }
    83  }