1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.el;
20
21 import java.io.Externalizable;
22 import java.io.IOException;
23 import java.io.ObjectInput;
24 import java.io.ObjectOutput;
25 import javax.el.ELContext;
26 import javax.el.ELException;
27 import javax.el.PropertyNotFoundException;
28 import javax.el.PropertyNotWritableException;
29 import javax.el.ValueExpression;
30 import javax.faces.FacesWrapper;
31 import javax.faces.component.UIViewRoot;
32 import javax.faces.context.FacesContext;
33 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
34 import org.apache.myfaces.view.facelets.tag.jsf.FaceletState;
35
36
37
38
39 public class FaceletStateValueExpression extends ValueExpression
40 implements Externalizable, FacesWrapper<ValueExpression>
41 {
42 private String uniqueId;
43 private String key;
44
45 public FaceletStateValueExpression()
46 {
47 }
48
49 public FaceletStateValueExpression(String uniqueId, String key)
50 {
51 this.uniqueId = uniqueId;
52 this.key = key;
53 }
54
55 @Override
56 public ValueExpression getWrapped()
57 {
58 FacesContext facesContext = FacesContext.getCurrentInstance();
59 UIViewRoot root = facesContext.getViewRoot();
60 FaceletState map = (FaceletState) root.getAttributes().get(
61 ComponentSupport.FACELET_STATE_INSTANCE);
62 if (map == null)
63 {
64 map = (FaceletState)root.getTransientStateHelper().getTransient(
65 ComponentSupport.FACELET_STATE_INSTANCE);
66 }
67 return map.getBinding(uniqueId, key);
68 }
69
70 public ValueExpression getWrapped(ELContext context)
71 {
72 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
73 if (facesContext == null)
74 {
75 facesContext = FacesContext.getCurrentInstance();
76 }
77 UIViewRoot root = facesContext.getViewRoot();
78 FaceletState map = (FaceletState) root.getAttributes().get(
79 ComponentSupport.FACELET_STATE_INSTANCE);
80 if (map == null)
81 {
82 map = (FaceletState)root.getTransientStateHelper().getTransient(
83 ComponentSupport.FACELET_STATE_INSTANCE);
84 }
85 return map.getBinding(uniqueId, key);
86 }
87
88
89 @Override
90 public Class<?> getExpectedType()
91 {
92 return getWrapped().getExpectedType();
93 }
94
95 @Override
96 public Class<?> getType(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException
97 {
98 return getWrapped(context).getType(context);
99 }
100
101 @Override
102 public boolean isReadOnly(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException
103 {
104 return getWrapped(context).isReadOnly(context);
105 }
106
107 @Override
108 public void setValue(ELContext context, Object value)
109 throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException
110 {
111 getWrapped(context).setValue(context, value);
112 }
113
114 @Override
115 public Object getValue(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException
116 {
117 return getWrapped(context).getValue(context);
118 }
119
120 @Override
121 public String getExpressionString()
122 {
123 return getWrapped().getExpressionString();
124 }
125
126 @Override
127 public boolean isLiteralText()
128 {
129 return getWrapped().isLiteralText();
130 }
131
132 @Override
133 public void writeExternal(ObjectOutput out) throws IOException
134 {
135 out.writeUTF(uniqueId);
136 out.writeUTF(key);
137 }
138
139 @Override
140 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
141 {
142 uniqueId = (String) in.readUTF();
143 key = (String) in.readUTF();
144 }
145
146 @Override
147 public int hashCode()
148 {
149 int hash = 7;
150 hash = 37 * hash + (this.uniqueId != null ? this.uniqueId.hashCode() : 0);
151 hash = 37 * hash + (this.key != null ? this.key.hashCode() : 0);
152 return hash;
153 }
154
155 @Override
156 public boolean equals(Object obj)
157 {
158 if (obj == null)
159 {
160 return false;
161 }
162 if (getClass() != obj.getClass())
163 {
164 return false;
165 }
166 final FaceletStateValueExpression other = (FaceletStateValueExpression) obj;
167 if ((this.uniqueId == null) ? (other.uniqueId != null) : !this.uniqueId.equals(other.uniqueId))
168 {
169 return false;
170 }
171 if ((this.key == null) ? (other.key != null) : !this.key.equals(other.key))
172 {
173 return false;
174 }
175 return true;
176 }
177
178 }