1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }