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.MethodExpression;
29  import javax.el.MethodInfo;
30  import javax.el.MethodNotFoundException;
31  import javax.el.PropertyNotFoundException;
32  import javax.faces.FacesWrapper;
33  import javax.faces.view.facelets.TagAttribute;
34  
35  /**
36   * 
37   * 
38   * @author Jacob Hookom
39   * @version $Id$
40   */
41  public final class TagMethodExpression
42          extends MethodExpression
43          implements Externalizable, FacesWrapper<MethodExpression>
44  {
45  
46      private static final long serialVersionUID = 1L;
47  
48      private String attr;
49      private MethodExpression orig;
50      
51      public TagMethodExpression()
52      {
53          super();
54      }
55  
56      public TagMethodExpression(TagAttribute attr, MethodExpression orig)
57      {
58          this.attr = attr.toString();
59          this.orig = orig;
60      }
61  
62      public MethodInfo getMethodInfo(ELContext context)
63      {
64          try
65          {
66              return this.orig.getMethodInfo(context);
67          }
68          catch (PropertyNotFoundException pnfe)
69          {
70              throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
71          }
72          catch (MethodNotFoundException mnfe)
73          {
74              throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
75          }
76          catch (ELException e)
77          {
78              throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
79          }
80      }
81  
82      public Object invoke(ELContext context, Object[] params)
83      {
84          try
85          {
86              return this.orig.invoke(context, params);
87          }
88          catch (PropertyNotFoundException pnfe)
89          {
90              throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
91          }
92          catch (MethodNotFoundException mnfe)
93          {
94              throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
95          }
96          catch (ELException e)
97          {
98              throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
99          }
100     }
101 
102     public String getExpressionString()
103     {
104         return this.orig.getExpressionString();
105     }
106 
107     public boolean equals(Object obj)
108     {
109         return this.orig.equals(obj);
110     }
111 
112     public int hashCode()
113     {
114         return this.orig.hashCode();
115     }
116 
117     public boolean isLiteralText()
118     {
119         return this.orig.isLiteralText();
120     }
121 
122     public void writeExternal(ObjectOutput out) throws IOException
123     {
124         out.writeObject(this.orig);
125         out.writeUTF(this.attr);
126     }
127 
128     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
129     {
130         this.orig = (MethodExpression) in.readObject();
131         this.attr = in.readUTF();
132     }
133 
134     public String toString()
135     {
136         return this.attr + ": " + this.orig;
137     }
138 
139     public MethodExpression getWrapped()
140     {
141         return this.orig;
142     }
143 }