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.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  
26  import javax.el.ELContext;
27  import javax.el.ELException;
28  import javax.el.PropertyNotFoundException;
29  import javax.el.PropertyNotWritableException;
30  import javax.el.ValueExpression;
31  import javax.faces.FacesWrapper;
32  import javax.faces.view.facelets.TagAttribute;
33  
34  /**
35   * 
36   * 
37   * @author Jacob Hookom
38   * @version $Id$
39   */
40  public class TagValueExpression extends ValueExpression implements Externalizable, FacesWrapper<ValueExpression>
41  {
42  
43      private static final long serialVersionUID = 1L;
44  
45      // orig and attr need to be available in TagValueExpressionUEL
46      ValueExpression orig; 
47      String attr; 
48  
49      public TagValueExpression()
50      {
51          super();
52      }
53  
54      public TagValueExpression(TagAttribute attr, ValueExpression orig)
55      {
56          this.attr = attr.toString();
57          this.orig = orig;
58      }
59  
60      public Class<?> getExpectedType()
61      {
62          return this.orig.getExpectedType();
63      }
64  
65      public Class<?> getType(ELContext context)
66      {
67          try
68          {
69              return this.orig.getType(context);
70          }
71          catch (PropertyNotFoundException pnfe)
72          {
73              throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
74          }
75          catch (ELException e)
76          {
77              throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
78          }
79      }
80  
81      public Object getValue(ELContext context)
82      {
83          try
84          {
85              return this.orig.getValue(context);
86          }
87          catch (PropertyNotFoundException pnfe)
88          {
89              throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
90          }
91          catch (ELException e)
92          {
93              throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
94          }
95      }
96  
97      public boolean isReadOnly(ELContext context)
98      {
99          try
100         {
101             return this.orig.isReadOnly(context);
102         }
103         catch (PropertyNotFoundException pnfe)
104         {
105             throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
106         }
107         catch (ELException e)
108         {
109             throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
110         }
111     }
112 
113     public void setValue(ELContext context, Object value)
114     {
115         try
116         {
117             this.orig.setValue(context, value);
118         }
119         catch (PropertyNotFoundException pnfe)
120         {
121             throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
122         }
123         catch (PropertyNotWritableException pnwe)
124         {
125             throw new PropertyNotWritableException(this.attr + ": " + pnwe.getMessage(), pnwe.getCause());
126         }
127         catch (ELException e)
128         {
129             throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
130         }
131     }
132     
133     public boolean equals(Object obj)
134     {
135         return this.orig.equals(obj);
136     }
137 
138     public String getExpressionString()
139     {
140         return this.orig.getExpressionString();
141     }
142 
143     public int hashCode()
144     {
145         return this.orig.hashCode();
146     }
147 
148     public boolean isLiteralText()
149     {
150         return this.orig.isLiteralText();
151     }
152 
153     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
154     {
155         this.orig = (ValueExpression) in.readObject();
156         this.attr = in.readUTF();
157     }
158 
159     public void writeExternal(ObjectOutput out) throws IOException
160     {
161         out.writeObject(this.orig);
162         out.writeUTF(this.attr);
163     }
164 
165     public String toString()
166     {
167         return this.attr + ": " + this.orig;
168     }
169 
170     public ValueExpression getWrapped()
171     {
172         return orig;
173     }
174 }