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.application.viewstate;
20  
21  import javax.faces.FacesWrapper;
22  import javax.faces.render.ResponseStateManager;
23  import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
24  
25  public class StateCacheUtils
26  {
27      public static boolean isMyFacesResponseStateManager(ResponseStateManager rsm)
28      {
29          if (rsm instanceof MyfacesResponseStateManager)
30          {
31              return true;
32          }
33          else
34          {
35              ResponseStateManager rsm1 = rsm;
36              while (rsm1 != null)
37              {
38                  if (rsm1 instanceof MyfacesResponseStateManager)
39                  {
40                      return true;
41                  }
42                  if (rsm1 instanceof FacesWrapper)
43                  {
44                      rsm1 = ((FacesWrapper<? extends ResponseStateManager>) rsm1).getWrapped();
45                  }
46                  else
47                  {
48                      rsm1 = null;
49                  }
50              }
51              return false;
52          }
53      }
54      
55      public static MyfacesResponseStateManager getMyFacesResponseStateManager(ResponseStateManager rsm)
56      {
57          if (rsm instanceof MyfacesResponseStateManager)
58          {
59              return (MyfacesResponseStateManager) rsm;
60          }
61          else
62          {
63              ResponseStateManager rsm1 = rsm;
64              while (rsm1 != null)
65              {
66                  if (rsm1 instanceof MyfacesResponseStateManager)
67                  {
68                      return (MyfacesResponseStateManager) rsm1;
69                  }
70                  if (rsm1 instanceof FacesWrapper)
71                  {
72                      rsm1 = ((FacesWrapper<? extends ResponseStateManager>) rsm1).getWrapped();
73                  }
74                  else
75                  {
76                      rsm1 = null;
77                  }
78              }
79              return null;
80          }
81      }
82  }