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