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.tobago.compat;
21  
22  import javax.faces.component.ContextCallback;
23  import javax.faces.component.NamingContainer;
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  
27  /**
28   * @deprecated since 1.6.0
29   */
30  @Deprecated
31  public class FacesInvokeOnComponent12 {
32  
33    /**
34     * @deprecated since 1.6.0
35     */
36    @Deprecated
37    public static boolean invokeOnComponent(
38        FacesContext context, UIComponent component, String clientId, ContextCallback callback) {
39      String thisClientId = component.getClientId(context);
40  
41      if (clientId.equals(thisClientId)) {
42        callback.invokeContextCallback(context, component);
43        return true;
44      } else if (component instanceof NamingContainer) {
45        // This component is a naming container. If the client id shows it's inside this naming container,
46        // then process further.
47        // Otherwise we know the client id we're looking for is not in this naming container,
48        // so for improved performance short circuit and return false.
49        if (clientId.startsWith(thisClientId)
50            && (clientId.charAt(thisClientId.length()) == NamingContainer.SEPARATOR_CHAR)) {
51          if (invokeOnComponentFacetsAndChildren(context, component, clientId, callback)) {
52            return true;
53          }
54        }
55      } else {
56        if (invokeOnComponentFacetsAndChildren(context, component, clientId, callback)) {
57          return true;
58        }
59      }
60  
61      return false;
62    }
63  
64    /**
65     * @deprecated since 1.6.0
66     */
67    @Deprecated
68    private static boolean invokeOnComponentFacetsAndChildren(
69        FacesContext context, UIComponent component, String clientId, ContextCallback callback) {
70      for (java.util.Iterator<UIComponent> it = component.getFacetsAndChildren(); it.hasNext();) {
71        UIComponent child = it.next();
72        if (child.invokeOnComponent(context, clientId, callback)) {
73          return true;
74        }
75      }
76      return false;
77    }
78  }