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  package org.apache.myfaces.orchestra.viewController;
    20
    21  /**
    22   * Each executor configured with the constructor will be asked to execute the
    23   * requested method on the bean. The search will end if the executor returns "true".
    24   * <p>
    25   * As an example, this can be configured to first try an executor that checks whether
    26   * the bean implements a specific interface, then try one that uses reflection to find
    27   * magic method-names, then try one that looks for annotations.
    28   */
    29  public class CompositeViewControllerExecutor implements ViewControllerExecutor
    30  {
    31      private final ViewControllerExecutor[] viewControllerExecutors;
    32
    33      public CompositeViewControllerExecutor(ViewControllerExecutor[] viewControllerExecutors)
    34      {
    35          this.viewControllerExecutors = new ViewControllerExecutor[viewControllerExecutors.length];
    36          System.arraycopy(viewControllerExecutors, 0, this.viewControllerExecutors, 0, viewControllerExecutors.length);
    37      }
    38
    39
    40      public boolean invokeInitView(String beanName, Object bean)
    41      {
    42          for (int i = 0; i< viewControllerExecutors.length; i++)
    43          {
    44              if (viewControllerExecutors[i].invokeInitView(beanName, bean))
    45              {
    46                  return true;
    47              }
    48          }
    49
    50          return false;
    51      }
    52
    53      public boolean invokePreRenderView(String beanName, Object bean)
    54      {
    55          for (int i = 0; i< viewControllerExecutors.length; i++)
    56          {
    57              if (viewControllerExecutors[i].invokePreRenderView(beanName, bean))
    58              {
    59                  return true;
    60              }
    61          }
    62
    63          return false;
    64      }
    65
    66      public boolean invokePreProcess(String beanName, Object bean)
    67      {
    68          for (int i = 0; i< viewControllerExecutors.length; i++)
    69          {
    70              if (viewControllerExecutors[i].invokePreProcess(beanName, bean))
    71              {
    72                  return true;
    73              }
    74          }
    75
    76          return false;
    77      }
    78  }