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.cdi;
20  
21  import javax.faces.FacesWrapper;
22  import javax.faces.component.PartialStateHolder;
23  import javax.faces.component.StateHolder;
24  import javax.faces.context.FacesContext;
25  
26  abstract class AbstractExternalBeanWrapper<T> implements PartialStateHolder, FacesWrapper<T>
27  {
28      private T wrapped;
29  
30      protected AbstractExternalBeanWrapper(T wrapped)
31      {
32          this.wrapped = wrapped;
33      }
34  
35      @Override
36      public void markInitialState()
37      {
38          if (this.wrapped instanceof PartialStateHolder)
39          {
40              ((PartialStateHolder) this.wrapped).markInitialState();
41          }
42      }
43  
44      @Override
45      public void clearInitialState()
46      {
47          if (this.wrapped instanceof PartialStateHolder)
48          {
49              ((PartialStateHolder) this.wrapped).clearInitialState();
50          }
51      }
52  
53      @Override
54      public boolean initialStateMarked()
55      {
56          return this.wrapped instanceof PartialStateHolder && ((PartialStateHolder) this.wrapped).initialStateMarked();
57      }
58  
59      @Override
60      public Object saveState(FacesContext context)
61      {
62          if (this.wrapped instanceof StateHolder)
63          {
64              return ((StateHolder)wrapped).saveState(context);
65          }
66  
67          return null;
68      }
69  
70      @Override
71      public void restoreState(FacesContext context, Object state)
72      {
73          if (this.wrapped instanceof StateHolder)
74          {
75              ((StateHolder)this.wrapped).restoreState(context, state);
76          }
77      }
78  
79      @Override
80      public boolean isTransient()
81      {
82          return this.wrapped instanceof StateHolder && ((StateHolder) this.wrapped).isTransient();
83      }
84  
85      @Override
86      public void setTransient(boolean newTransientValue)
87      {
88          if (this.wrapped instanceof StateHolder)
89          {
90              ((StateHolder) this.wrapped).setTransient(newTransientValue);
91          }
92      }
93  
94      @Override
95      public T getWrapped()
96      {
97          return this.wrapped;
98      }
99  }