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.trinidad.component;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.context.FacesContext;
25  
26  /**
27   * Interface implemented to apply the visitor pattern to a set of components where the
28   * components are not necessarily siblings of each other.  When <code>processComponent</code> is
29   * called, the component instance is guaranteed to be in the correct context.
30   * <p>
31   * Instances of this interface are parameterized by the type of the callbackContext the implementor
32   * expects.  The typical usage is that the implementor creates and instance of the desired context
33   * and calls a helper method on a different object (for example
34   * <code>UIXComponent.processComponent</code> with the desired ComponentProcessor and context
35   * instances to actually perform the iteration.
36   * <p>
37   * Because the ComponentProcessor can't look ahead, more complex iteration tasks, such as
38   * laying out and rendering components based on the number of components to render may
39   * require multiple-passes--one to collect the layout information into the callbackContext using
40   * one ComponentProcessor implementation and a second pass using a different ComponentProcessor
41   * to actually perform the layout using the information calculated in the first pass.
42   * @see FlattenedComponent
43   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent, Object)
44   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable, Object)
45   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, UIComponent, Object)
46   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, Iterable, Object)
47   */
48  public interface ComponentProcessor<T>
49  {
50    /**
51     * Processes a component
52     * @param context The current FacesContext
53     * @param cpContext context represtinging the current component iteration state
54     * @param component Component to process on this iteration
55     * @param callbackContext ComponentProcessor-specific context
56     * @throws IOException if processing resulted in an IOException
57     */
58    public void processComponent(
59      FacesContext context,
60      ComponentProcessingContext cpContext,
61      UIComponent component,
62      T callbackContext) throws IOException;
63  }